While I agree that there is nothing wrong with calling validate()
yourself; if you are using 1.2 you might want to look into the
MappingDispatchAction -- it was designed to allow for one Action that
supports multiple action configurations -- even with different forms, etc.
Bryce Fischer wrote:
I'm having a problem with a ValidatorForm and validation. The first time
I try to access the action below, I get a validation error. The form
never gets the opportunity to be filled in by the Action class (action
called is /fringe.do?method=edit). Is there any way to tell Struts to
not do validation unless we are saving? For example, calling
/fringe.do?method=save? I have solved it by overrideing the validate()
method, checking the parameters and seeing if "method = 'save'".
I was wondering if this was the only way to accomplish this? I'd like to
be able to keep that kind of logic out of my form, and put it in the
validation.xml file, or another configuration file...
Form:
public class FringeForm extends ValidatorForm implements
java.io.Serializable {
private String field1;
public ActionErrors validate(ActionMapping mapping, HttpServletRequest
request) {
ActionErrors actionErrors = new ActionErrors();
String method = request.getParameter("method");
if ("save".equals(method)) {
actionErrors = super.validate(mapping, request);
}
return actionErrors;
}
// getters and setters omitted for brevity
}
Validation:
<form-validation>
<!--
Define global validation config in validation-global.xml
-->
<formset>
<form name="fringeForm">
<field property="field1" depends="required">
<arg0 key="fringeForm.field1"/>
</field>
</form>
</formset>
</form-validation>
And the action mapping looks like this (actual class extends
DispatchAction):
<action
path="/fringe"
type="org.springframework.web.struts.DelegatingActionProxy"
name="fringeForm"
scope="request"
parameter="method"
input="/WEB-INF/pages/fringeForm.jsp"
>
<forward name="edit" path="/WEB-INF/pages/fringeForm.jsp"/>
<forward name="success" path="/index.jsp"/>
</action>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]