How to make data remain after success validation? - validation

I have jsp using struts bean tag library:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
</head>
<body>
<p><a class="colorGrey" href="Welcome.do">
<bean:message key="menu.label" />
</a> >><bean:message key="menu.link.addnews" /> </p>
<p><br>
</p>
<html:form action="/NewsSave">
<table width="100%" border="0">
<tr>
<td class="colorGrey" width="164" height="35">
<bean:message key="body.news.title" /> </td>
<td width="577">
<html:text property="newsTitle" size="40" value=""/> </td>
</tr>
<tr>
<td colspan="2">
<html:errors property="newstitle" />
</td>
</tr>
<tr>
<td class="colorGrey">
<bean:message key="body.news.date" /> </td>
<td>
<html:text property="newsDate" size="10" value=""/> </td>
</tr>
<tr>
<td height="21" colspan="2" valign="top">
<html:errors property="newsdate" />
</td>
</tr>
<tr>
<td class="colorGrey" height="61" valign="top">
<bean:message key="body.news.brief" /> </td>
<td valign="top">
<html:textarea property="brief" cols="40" rows="6" value=""/>
</td>
</tr>
<tr>
<td height="23" colspan="2" valign="top"><html:errors property="brief" /></td>
</tr>
<tr>
<td class="colorGrey" height="100" valign="top">
<bean:message key="body.news.content" />
</td>
<td valign="top">
<html:textarea property="content" cols="40" rows="12" value=""/>
</td>
</tr>
<tr>
<td height="23" colspan="2" valign="top">
<html:errors property="content" />
</td>
</tr>
</table>
<html:submit value="SAVE"/>
</html:form>
<form method="POST"
action="Link.do?method=newsList"
onsubmit="return confirm('<bean:message key="body.onsubmit.cancel" />')">
<input type="submit" value="CANCEL">
</form>
And I use validator plugin, which means that after receiving incorrect info it gives message bellow text field telling what's wrong. But problem is that everything disappear after submiting. So it no info in text or text-areatags. I know that it happens because of value="". But I have another page with the same fields for adding info, which should be clear from the beginning. And if I remove value="", the info from this fields will be displayed on that page after forwarding. So
What should I do to clear info from forms after forwarding to
another page?
How to make info remain after success validation?

As you mentioned, you should remove value="" as this is setting the fields to empty. If you want to clear the values then you should do this in the Action class in which your Form bean is populated.
If you are finding that your Form beans are retaining their values between requests then check that they are request scope: the scope attribute of the action element should be "request" in struts.config

Related

p:ajax update of more than one element

I'm having trouble when trying to update two elements.
This is my code:
<h:form id="all">
<table id="gt" class="CartContents Stylize General" cellspacing="0" cellpadding="0" style="display:#{clothesBean_i.convertToList(clothesBean_i.cartclothes)}">
<tbody>
<!-- AFFICHAGE PRODUIT -->
<ui:repeat value="#{clothesBean_i.convertToList(clothesBean_i.cartclothes)}" var="c">
<tr>
<td class="CartThumb" style="">
<img src="" /> 
</td>
<td class="ProductName" colspan="1">
<h5></h5>
<br />
</td>
<td align="center" class="CartItemIndividualPrice">
$ #{c.price}
</td>
<td id="qt" align="center" class="CartItemIndividualPrice">
<h:outputLabel for="ajaxSpinner" value="" />
<p:outputPanel id="mypanel">
<p:spinner id="ajaxSpinner" value="#{clothesBean_i.qt}" min="1" max="100">
<p:ajax update="tot grandT" process="#this" />
</p:spinner>
</p:outputPanel>
</td>
<td align="center" class="CartItemIndividualPrice">
<h:outputText id="tot" value="$ #{clothesBean_i.getClothePriceQt(c)}" />
</td>
</tr>
</ui:repeat>
</tbody>
<tfoot >
<tr class="SubTotal GrandTotal">
<td colspan="4">Grand Total:</td>
<td >
<h:outputText id="grandT" value="$ #{clothesBean_i.getClothesPrice(clothesBean_i.convertToList(clothesBean_i.cartclothes))}" />
</td>
</tr>
</tfoot>
</table>
</h:form>
in this line
<p:ajax update="tot grandT" process="#this" />
when I give just one id (tot or grandT) it works fine,
but with two ids I just get a blank page (nothing is showing)!

Messages are not displaying after clicking command button in primefaces

I used an input text, upload file and command button properties.My File upload mode is basic.In command button i made ajax=false.I used required=true in both the fields.While clicking save with empty fields, corresponding method is executing and message is displaying in console, but error message is not displaying in UI.
<p:dialog widgetVar="addDialogWidgetVar" id="addDialogWidgetVarId" dynamic="true" >
<table style="width: 100%;">
<tr>
<td>
<p:messages for="errorMsgId" id="errorMsgId" autoUpdate="true" showDetail="false" showSummary="true" closable="true"/>
</td>
</tr>
</table>
<h:form id="formId" enctype="multipart/form-data">
<table>
<tr>
<td>
<label style="margin-top: 5%"><h:outputText value="Name:"/><h:outputText value="*" style="color:red"/></label>
</td>
<td width="10%"/>
<td>
<p:inputText value="#{manageBean.attachment.fileName}" id="fileNameId" maxlength="60" style="width:70"
required="#{not empty param[save.clientId]}" requiredMessage="Please enter Attachment name"></p:inputText>
</td>
</tr>
<tr height="10"></tr>
<tr>
<td>
<label style="margin-top: 5%"><h:outputText value="Upload Attachment:"/><h:outputText value="*" style="color:red"/></label>
</td>
<td width="10%"/>
<td>
<p:fileUpload label="Select a file" mode="simple" value="#{manageBean.attachment.file}"
allowTypes="/(\.|\/)(pdf|doc|docx|xls|xlsx|gif|jpg|jpeg|png|PNG|GIF|JPG|JPEG)$/"
invalidFileMessage="Allow only (pdf|doc|docx|xls|xlsx|gif|jpg|jpeg|png|PNG|GIF|JPG|JPEG) file."
multiple="false" required="#{not empty param[save.clientId]}" requiredMessage="Please select a file" >
</p:fileUpload>
</td>
</tr>
</table>
<br />
<table style="margin-left: 30%;">
<tr align="center">
<td>
<p:commandButton value="Close" actionListener="#{manageBean.cancelAttachment}" oncomplete="addDialogWidgetVar.hide()" />
</td>
<td>
<p:commandButton id="submitbtnid" value="Save" ajax="false" binding="#{save}"
actionListener="#{manageBean.saveAttachment}" update=":errorMsgId"/>
</td>
</tr>
</table>
</h:form>
</p:dialog>
Try do submit without ajax for test, and also put p:growl in the page, try get messages without update messages component and find bug.

How to display <form:errors> outside <form:form> in Spring?

I'm new to Spring and I've been having some trouble trying to show a form errors.
I have the following form:
<form:form action="loginform.html" commandName="loginForm" onsubmit="goWait();">
<table><tr>
<td>User Name: </td>
<td><form:input path="userName" /></td>
</tr>
<tr>
<td>Password: </td>
<td><form:password path="password"/> </td>
<tr>
<td colspan="2">
<input type="submit" value="Login" style="butt-login">
</td>
</tr>
</table>
</form:form>
The form, as can be seen, is backed by a LoginForm Bean that validates it.
I want to show all the errors from the validation, outside this form. Something like this:
<div>
<ul>
<li><form:errors path="userName"/></li>
<li><form:errors path="password"/></li>
</ul>
</div>
This div should be outside the , so I can't use the tag.
How can I do this?
You could just capture the html produced by form:errors and display it somewhere after the form:
<form:form ...>
<c:set var="err">
<form:errors path="*" element="div" id="err" cssClass="hidden" />
</c:set>
</form:form>
....
<c:out value="${err}" />
If you want to show the errors before the form, you can do that with a bit of jQuery
Yes, you can user form:errors tag outside form:form tag
<form:errors path="yourBindedObject.*" />
<form:form action="loginform.html" commandName="loginForm" onsubmit="goWait();">
<table><tr>
<td>User Name: </td>
<td><form:input path="userName" /></td>
</tr>
<tr>
<td>Password: </td>
<td><form:password path="password"/> </td>
<tr>
<td colspan="2">
<input type="submit" value="Login" style="butt-login">
</td>
</tr>
</table>
</form:form>
If you want to show all errors associated with any fields just pass a star to the path attribute.
<form:errors path="*" />
But if you want to show global error messages just pass an empty string:
<form:errors path="" />
More information related: http://www.mkyong.com/spring-mvc/spring-mvc-form-errors-tag-example/

Images in an email is not displaying in IE

I have created an HTML email for a client, who then asked me to post it to their server for viewing on the web. It is a basic table layout with images and some links.
Everything appears to work in all major email clients, as well as Chrome, Safari, and Firefox. However, All versions of IE simply do not display the images. You can see the site here.
http://poweredbyprofessionals.com/email/2012-10-MRF/
I verified that the images are RGB and not CMYK, as well as ran it through a validator. Nothing seems to fix the issue. Any ideas?
Solution
Replace width="auto" and height="auto" by the real width and height.
Demo
http://jsfiddle.net/yrVsL/1/
Code modified
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<table style="border-collapse: collapse;" align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="center">
<font color="#005697" style="font-family:Arial, Helvetica, sans-serif; font-size:18px; line-height:36px;">
<strong> Join Us!! <br/></strong>
</font>
<font color="#008754" style="font-family:Arial, Helvetica, sans-serif; font-size:14px; line-height:20px;">
<strong>Wings of Hope for Melanoma</strong><br />
a fundraising gala to benefit the <br />
Melanoma Research Foundation<br /><br />
</font>
<font color="#000" style="font-family:Arial, Helvetica, sans-serif; font-size:14px; line-height:20px;">
<strong> Thursday, October 11, 2012<br/>
6:00 PM to 10:00 PM<br />
Gotham Hall <br />
1356 Broadway, New York<br /><br />
</strong>
<strong>Click here for more information, to purchase tickets or make a donation!</strong>
</font>
</td>
</tr>
<tr>
<td>
<a href="http://www.poweredbyprofessionals.com/melanoma/Purchase.html" target="_blank">
<img style="display: block;" src="http://poweredbyprofessionals.com/email/2012-10-MRF/images/Slice-1.jpg" alt="Slice-1" width="550" height="257" />
</a>
</td>
</tr>
<tr>
<td>
<img style="display: block;" src="http://poweredbyprofessionals.com/email/2012-10-MRF/images/Slice-2.jpg" alt="Slice-2" width="550" height="446" />
</td>
</tr>
<tr>
<td>
<table style="border-collapse: collapse;" align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<img style="display: block;" src="http://poweredbyprofessionals.com/email/2012-10-MRF/images/Slice-4.jpg" alt="Slice-4" width="275" height="99" />
</td>
<td>
<a href="http://www.poweredbyprofessionals.com/melanoma/Purchase.html" target="_blank">
<img style="display: block;" src="http://poweredbyprofessionals.com/email/2012-10-MRF/images/Slice-3.jpg" alt="Slice-3" width="275" height="99" />
</a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<img style="display: block;" src="http://poweredbyprofessionals.com/email/2012-10-MRF/images/Slice-5.jpg" alt="Slice-5" width="550" height="319" />
</td>
</tr>
<tr>
<td>
<img style="display: block;" src="http://poweredbyprofessionals.com/email/2012-10-MRF/images/Slice-6.jpg" alt="Slice-2" width="550" height="99" />
</td>
</tr>
<tr>
<td>
<a href="http://www.poweredbyprofessionals.com/melanoma/Purchase.html" target="_blank">
<img style="display: block;" src="http://poweredbyprofessionals.com/email/2012-10-MRF/images/Slice-7.jpg" alt="Slice-1" width="550" height="99" />
</a>
</td>
</tr>
<tr>
<td>
<table style="border-collapse: collapse;" align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<a href="http://www.poweredbyprofessionals.com" target="_blank">
<img style="display: block;" src="http://poweredbyprofessionals.com/email/2012-10-MRF/images/Slice-8.jpg" alt="Slice-3" width="180" height="87" />
</a> </td>
<td>
<a href="http://www.melanoma.org" target="_blank">
<img style="display: block;" src="http://poweredbyprofessionals.com/email/2012-10-MRF/images/Slice-9.jpg" alt="Slice-3" width="180" height="87" />
</a>
</td>
<td>
<a href="http://www.stanadler.com" target="_blank">
<img style="display: block;" src="http://poweredbyprofessionals.com/email/2012-10-MRF/images/Slice-10.jpg" alt="Slice-3" width="180" height="87" />
</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

PrimeFaces Ajax

I am trying to make login with jsf.
I want to hide login panel when user registered.
I did this with jsf ajax.
When I try to do this with primefaces. I am failed.
I triy in jsf ajax like this.
<h:form id="register">
<table style="width: 49%; margin-right: auto; margin-left: auto;">
<tr>
<td colspan="3">
All fields are required.</td>
</tr>
<tr>
<td class="style2" style="height: 51px">Username</td>
<td style="width: 17px; height: 51px;">:</td>
<td class="style3" style="height: 51px"><h:inputText
id="regusername" style="width:155px;height:24px;"
value="#{userRegister.regUser.username}">
</h:inputText></td>
</tr>
<tr>
<td class="style2" style="height: 51px">Name</td>
<td style="width: 17px; height: 51px;">:</td>
<td class="style3" style="height: 51px"><h:inputText
id="regname" style="width:155px;height:24px;"
value="#{userRegister.regUser.name}">
</h:inputText></td>
</tr>
<tr>
<td class="style2" style="height: 51px">Mail</td>
<td style="width: 17px; height: 51px;">:</td>
<td class="style3" style="height: 51px"><h:inputText
id="regmail" style="width:155px;height:24px;"
value="#{userRegister.regUser.mail}">
</h:inputText></td>
</tr>
<tr>
<td class="style2" style="height: 51px">Password</td>
<td style="width: 17px; height: 51px;">:</td>
<td class="style3" style="height: 51px">
<h:inputSecret
id="regpassword" style="width:155px;height:24px;"
value="#{userRegister.regUser.password}">
</h:inputSecret></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td class="style3"><h:commandButton
style="width:76px;height:26px" value="Clear" type="reset">
</h:commandButton> <h:commandButton style="width:75px;height:26px"
value="Register" action="#{userRegister.register()}"
method="post">
<f:ajax execute="regname regusername regpassword regmail"
render="registermessage" />
</h:commandButton></td>
</tr>
<tr>
<td colspan="3"><h:outputText id="registermessage"
value="#{userRegister.message}"></h:outputText></td>
</tr>
</table>
</h:form>
</h:panelGroup>
<h:panelGroup rendered="#{userLogin.isLoggedin()== true}"
layout="block">
You are already loggedin !!
</h:panelGroup>
When ı try this in primefaces like this:
<p:panel id ="registerPanel" header="User Registration" align="center"
style="text-align:center;">
<table style="width: auto; margin: auto;">
<tr>
<td style="text-align: right;"><h:outputLabel for="regname"
value="Name Surname : * " /></td>
<td style="text-align: left"><p:inputText id="regname"
value="#{userRegister.regUser.name}" size="40" required="true"
label="Name and Surname">
<f:validateLength minimum="2" />
</p:inputText> <p:watermark for="regname" value="Name Surname" /></td>
</tr>
<tr>
<td style="text-align: right" colspan="2"><p:message
for="regname" /></td>
</tr>
<tr>
<td style="text-align: right;"><h:outputLabel
for="regusername" value="Username : * " /></td>
<td style="text-align: left"><p:inputText id="regusername"
value="#{userRegister.regUser.username}" size="40"
required="true" label="Username">
<f:validateLength minimum="3" />
</p:inputText> <p:watermark for="regusername" value="Username" /></td>
</tr>
<tr>
<td style="text-align: riht" colspan="2"><p:message
for="regusername" /></td>
</tr>
<tr>
<td style="text-align: right;"><h:outputLabel for="regmail"
value="E-Mail : * " /></td>
<td style="text-align: left"><p:inputText id="regmail"
value="#{userRegister.regUser.mail}" size="40" required="true"
label="Mail">
<f:validateLength minimum="2" />
</p:inputText> <p:watermark for="regmail" value="mail#example.com" /></td>
</tr>
<tr>
<td style="text-align: right" colspan="2"><p:message
for="regmail" /></td>
</tr>
<tr>
<td style="text-align: right;"><h:outputLabel for="paswword"
value="Password : * " /></td>
<td style="text-align: left"><p:password id="regpassword"
value="#{userRegister.regUser.password}" size="40"
required="true" label="Password">
<f:validateLength minimum="5" />
</p:password> <p:watermark for="regpassword" value="Password" /></td>
</tr>
<tr>
<td style="text-align: left" colspan="2"><p:message
for="regpassword" /></td>
</tr>
<tr>
<td style="text-align: right" colspan="2">
</td>
</tr>
<tr>
<td style="text-align: right" colspan="2">
<p:commandButton value="Clear" image="ui-icon ui-icon-arrowrefresh-1-w"
type="reset"/>
<p:commandButton value="Register" image="ui-icon ui-icon-disk"
action="#{userRegister.register()}" method="post">
<f:ajax
render="registerpaneli" />
</p:commandButton>
</td>
</tr>
</table>
-->
</h:panelGroup>
I registraion panel cant hiden.
What is the problem ?
Remove the
<p:commandButton ....>
<f:ajax render="what-ever">
</p:commandButton>
By
<p:commandButton update="what-ever" ../>
Furthermore, you can read Primefaces' Document and its demo.
Because in Primefaces, most components are compatible with Ajax, especially <p:commandButton/> because it has Ajax turned on by default.
In PrimeFaces, <p:commandButton> already has built-in ajax functionality. You don't need to use <f:ajax>. In fact, <f:ajax> cannot be used with PrimeFaces. If you really need to use it, you must use <p:ajax> instead.
To fix your issue, I think you should change you button like this:
<p:commandButton value="Register" actionListener="#{userRegister.register}" update="registerPanel" />

Resources