aspose file tools
The moose likes Struts and the fly likes How to change the input attribute in the ActionForm ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "How to change the input attribute in the ActionForm ?" Watch "How to change the input attribute in the ActionForm ?" New topic
Author

How to change the input attribute in the ActionForm ?

Jack Lau
Ranch Hand

Joined: Aug 30, 2002
Posts: 166
Hello all,
Does anyone know how to change the input attribute in the ActionForm, not in the struts-config.xml ?
// Inside struts-config.xml
<action
path="/jsp/test"
type="com.jack.TestAction"
name="TestForm"
input="/jsp/test/testStruts.jsp"
</action>
// Inside ActionForm
public ActionErrors validateChangePassword(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (true) {
errors.add("test", new ActionError("id_not_match");
// want to chnage the input attribute
}
return errors;
}
I would like to change the input attribute (input="/jsp/test/testStruts.jsp")in struts-config.xml dynamically so that I can forward to a specified page when there is an error.
Thanks in advance!
Jack
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
In the input attribute of the action tag instead of the jsp name, use an action mapping name and hence when u call mapping.getInputForward(), the action class is called where you can write code to send to any desired page e.g.:
<!-- Update a Users Professional Profile Information -->
<action path="/updateprofprofile"
input="/returnUpdateControl.do"
type="com.registration.action.ProfileAction"
parameter="method"
name="RegisterForm"
scope="session"
validate="true">
<forward name="failure" path="/index.jsp"/>
<forward name="thanks" path="/index-profile.jsp"/>
<forward name="refreshform" path="/returnUpdateControl.do"/>
</action>
<!-- Forward mapping control for profile updation -->
<action path="/returnUpdateControl"
type="com.registration.action.UpdateControlAction"
name="RegisterForm"
scope="session">
<forward name="usmdp" path="/usmdprofile.jsp"/>
<forward name="nursep" path="/nursesprofile.jsp"/>
<forward name="pharmacistp" path="/pharmacistprofile.jsp"/>
<forward name="ohcpp" path="/healthcareprovider-profile.jsp"/>
<forward name="healthadminp" path="/healthadmin-profile.jsp"/>
<forward name="physicianasstp" path="/paprofile.jsp"/>
<forward name="medstudentp" path="/medstudents-profile.jsp"/>
<forward name="intlmdp" path="/intl-md-profile.jsp"/>
<forward name="basic-profile" path="/getprofile.do?method=getBasicProfileFromId"/>
<forward name="error" path="/error.jsp"/>
</action>
// Inside ActionForm
public ActionErrors validateChangePassword(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (true) {
errors.add("test", new ActionError("id_not_match");
// want to chnage the input attribute
}
return errors;
}

//Inside UpdateControlAction class which is a simple action class
ActionErrors errors = form.validate(mapping, request);
if(errors != null && errors.size() > 0){
//go to the input page mapping
}else{
//send to some other place
}

HTH
Sahil
[ October 27, 2003: Message edited by: sandy gupta ]

Adios
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to change the input attribute in the ActionForm ?
 
Similar Threads
Struts - got a blank page
application.resources don't show me the messages
DynaValidatorForm question:
form-bean with DynaValidatorForm
validation error messages