sangeetha
asked on
Struts - Form Validation, Form-Bean and Form-Action
Hi,
Please look here:
http://jaggybala.clawz.com/CalendarTool/ShowList.html
At present i have 3 JSP's, 2 Form-Bean and 2 Form-Action as follows:
JSP Form-Bean Form-Action
------------ ----------------- -------------------
FilterList.jsp FilterForm.java FilterAction.java
RegisterList.jsp RegiterForm.java RegisterAction.java
ShowList.jsp --- ---
ShowList.jsp includes FilterList.jsp and RegisterList.jsp and shows List of Members below as shown.
I am doing Validation in FilterAction.java (for FilterList.jsp fields), RegisterAction.java (for RegisterList.jsp fields) and forward( & re-direct) both Form-Action's to ShowList.jsp so that if there are any validation errors, it should display in the ShowList page.
But, i have some problems and difficulties in doing so.
I think instead of above designing, there should be an easy/efficient way of doing this. Is it possible to write One JSP that has 2 FORMS along with proper Validations and Actions ?
If so, please suggest me. Thanks.
Please look here:
http://jaggybala.clawz.com/CalendarTool/ShowList.html
At present i have 3 JSP's, 2 Form-Bean and 2 Form-Action as follows:
JSP Form-Bean Form-Action
------------ ----------------- -------------------
FilterList.jsp FilterForm.java FilterAction.java
RegisterList.jsp RegiterForm.java RegisterAction.java
ShowList.jsp --- ---
ShowList.jsp includes FilterList.jsp and RegisterList.jsp and shows List of Members below as shown.
I am doing Validation in FilterAction.java (for FilterList.jsp fields), RegisterAction.java (for RegisterList.jsp fields) and forward( & re-direct) both Form-Action's to ShowList.jsp so that if there are any validation errors, it should display in the ShowList page.
But, i have some problems and difficulties in doing so.
I think instead of above designing, there should be an easy/efficient way of doing this. Is it possible to write One JSP that has 2 FORMS along with proper Validations and Actions ?
If so, please suggest me. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks.
i do validate in Form-Action because i want to show the errors in ShowList.jsp
>> in the Form-Bean there will be validate() method which will call automatically by struts when you submit data from jsp if there are some error you can specifie target action or jsp to redirect to.
could you plesae explain me this.thanks.
i do validate in Form-Action because i want to show the errors in ShowList.jsp
>> in the Form-Bean there will be validate() method which will call automatically by struts when you submit data from jsp if there are some error you can specifie target action or jsp to redirect to.
could you plesae explain me this.thanks.
we just implement this method in Form-Bean
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
{
ActionErrors errs = new ActionErrors();
if (condition) {
errs.add("zipcode", new ActionError("invalidZipCod e"));
}
if (condition) {
errs.add("phone", new ActionError("phoneInvalid" ));
}
return errs;
}
and tell struts will validate data when they create this form bean if there is no error so they pass to action-from
but If there are some errors they will redirect request to the error page that I configured.
In error page I can use some taglib to access this error and display it.
I can not remember for exactly detail now. But If I am free, I will be back here to explain you more.
:)
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
{
ActionErrors errs = new ActionErrors();
if (condition) {
errs.add("zipcode", new ActionError("invalidZipCod
}
if (condition) {
errs.add("phone", new ActionError("phoneInvalid"
}
return errs;
}
and tell struts will validate data when they create this form bean if there is no error so they pass to action-from
but If there are some errors they will redirect request to the error page that I configured.
In error page I can use some taglib to access this error and display it.
I can not remember for exactly detail now. But If I am free, I will be back here to explain you more.
:)
invalidZipCode,phoneInvali d
this I use in ActionError("....")
is a key for lookup message from message repository. So It would be useful if we deploy application in another locale, we just create a new message repository for that country.
:)
this I use in ActionError("....")
is a key for lookup message from message repository. So It would be useful if we deploy application in another locale, we just create a new message repository for that country.
:)
ASKER
Ok.. I'll give a try. Thanks.
becuase I don't have enogh time to give you some useful code, but I have some clue for you to get start.
in the Form-Bean there will be validate() method which will call automatically by struts when you submit data from jsp if there are some error you can specifie target action or jsp to redirect to.