Firstly, if you have separate "mappings" in your struts-config.xml (which
use the same DispatchAction) why can't you set validate to "true" for some
and "false" for others?

Having said that, if you have just one mapping, you could set the
validate="false" in the struts-config.xml and call the form validation, as
required, in your Action's methods...say you wanted validation in an "edit"
method...

public ActionForward edit(
               ActionMapping mapping,
               ActionForm form,
               HttpServletRequest request,
               HttpServletResponse response)
                       throws Exception {

    ActionMessages errors = form.validate(mapping, request);
    if (errors != null && errors.size() >0) {
        return mapping.getInputForward();
    }

    // do the rest of my stuff here

}

I guess the other alternative would be to put some logic in the ActionForm's
validate method - but that would be kind of duplicating the decision logic
in the DispatchAction

Niall


----- Original Message ----- 
From: "Nadia Kunkov" <[EMAIL PROTECTED]>
To: "Struts help (E-mail)" <[EMAIL PROTECTED]>
Sent: Monday, October 04, 2004 5:10 PM
Subject: Validate some forms and not the others. How?


Hi,
I'm building an application using DispatchAction.  I have several screens
that use the same ActionForm and I set validate to "true" for this action
form.
The first page of my app is just a jsp with a single button ( I have to
start somewhere :) .  When I click the button on this first page which is
not the form and has no input fields, I guess Struts tries to validate it.
What I see in the log is that I do get into the validate method, the
validation fails and the action itself is not performed.  How can I tell
struts to not validate this first page but validate other screens where
there are input fields.  Since I use dispatch action I can't specify
validate "false" for some actions and "true" for the others, it's just one
validate...
That brings me to the next question.  Should I use DispatchAction?
Thanks for your help.
NK



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to