1. Displaying errors on the JSP page is not differnt from the normal action
form validation. You could add <html:errors /> whereever you need to display
the error. In addition you could add a <html:javascript
formName="YourFormName" /> in your JSP along with adding onsubmit="return
validateYourFormName(this)" in the html:form would give you an additional
client side JavaScript validation automatically plugged in.
2. You could have the reset method in the formbean as normal. I din't see
any reason why you couldn't.
3. Well.. in struts all the error and success actions are forwards and a JSP
forward does the forward without coming back to the client browser. Hence
url will remain the same... Does that really matter... you would look at the
page rather than what is there in the URL!
HTH
Nitesh
----- Original Message -----
From: "Thai Dang Vu" <[EMAIL PROTECTED]>
To: <user@struts.apache.org>
Sent: Saturday, June 18, 2005 2:08 AM
Subject: Howto display errors when using Struts Validator
Hello,
I don't know how to display errors in the jsp input page when using Struts
Validator. This is my case:
- validation.xml
...
<formset>
<form name="getNameForm">
<field property="name" depends="required">
<arg0 key="Name" resource="false"/>
</field>
<field property="phone" depends="required, mask">
<msg key="Phone number" name="mask" resource="false"/>
<arg0 key="A phone number" resource="false"/>
<var>
<var-name>mask</var-name>
<var-value>^(\d{3}-\d{3}-\d{4})|(\(\d{3}\)
?\d{3}-\d{4})$</var-value>
</var>
</field>
</form>
</formset>
...
- struts-config.xml
...
<form-beans>
<form-bean name="getNameForm" type="GetNameForm"/>
</form-beans>
<action-mappings>
<action input="/inputname.jsp" name="getNameForm" path="/greeting"
scope="request" type="GreetingAction" validate="true">
<forward name="greeting" path="/greeting.jsp"/>
</action>
</action-mappings>
<message-resources parameter="MyMessageResources"/>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>
...
- validator-rules.xml isn't changed.
- GetNameForm.java
public class GetNameForm extends ValidatorForm {
private String name;
private String phone;
... getter, setter methods
My questions are:
1. How can I dislay the errors in the input jsp file when the name and phone
values don't meet the requirement?
2. Can I have the reset method in the Form Bean? If I can't, how can I reset
those values?
3. When I run it with the invalid values for name or phone, Struts forwards
me to the jsp input page but the address in the address bar is greeting.do.
How can I make it inputname.jsp?
Sincerely,
Thai
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]