Link to home
Start Free TrialLog in
Avatar of sangeetha
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.
Avatar of sompol_kiatkamolchai
sompol_kiatkamolchai
Flag of Thailand image

why don't you validate data by using struts framework? As you explain me that you validate it by Form-Action, I suggest you to find how to validate data in struts.

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.

ASKER CERTIFIED SOLUTION
Avatar of sompol_kiatkamolchai
sompol_kiatkamolchai
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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("invalidZipCode"));
            }
            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,phoneInvalid

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.

:)
Avatar of sangeetha
sangeetha

ASKER

Ok.. I'll give a try. Thanks.