You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Kennedy <jk...@davincitechnology.com> on 2004/03/29 18:46:55 UTC
Multiple page wizard with validation
I'm using struts 1.1 with the standard Validation stuff (see below)
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>
I have a multi-page form (random access tabbed interface) and I would like
to do the correct validation on the correct form (tab). There are 3 related
jsp pages. Formtab1.jsp, formtab2.jsp and formtab2.jsp. Only fields on
formtab1.jsp should be validated and so on...
I understand that I would need to specify the correct page for each field in
my validation.xml file. I also need to do a setPage(x) with my Action on
the DynaValidatorForm object. This really is not my question. I want to
understand how the DynaValidatorForm gets initialized. I initialize it the
first time through my Action using:
BeanUtils.copyProperties(form, mybean);
This action is also used for the tab navigation, but I don't want to
initialize the form each time I run through the action.
How can I sense that the form has already been initialized so I don't
overwrite new user entries on the form?
I don't think I should have to create a separate struts action for the first
time and another for each time after that.
Here's a snippet of code:
DynaValidatorForm _form = (DynaValidatorForm)form;
String prop_id = req.getParameter("id");
Context jndi_context = new InitialContext();
Object obj_ref =
jndi_context.lookup("java:comp/env/ejb/props");
RentalPropertyHome home = (RentalPropertyHome)
PortableRemoteObject.narrow(obj_ref,
RentalPropertyHome.class);
// could have a finder exception here if user hacks URL
RentalProperty rental_prop = home.findByPrimaryKey(prop_id);
RentalPropertyValue prop_vo =
rental_prop.getRentalPropertyValue();
BeanUtils.copyProperties(_form, prop_vo);
// decide which tab to make visible
if ( page_tab.equals("1") )
{
_form.setPage(1);
return mapping.findForward("editformtab1");
}
else if ( page_tab.equals("2") )
{
return mapping.findForward("editformtab2");
}
else if ( page_tab.equals("3") )
{
return mapping.findForward("editformtab3");
}
else if ( page_tab.equals("4") )
{
return mapping.findForward("editformtab4");
}
else
{
return mapping.findForward("editformtab1");
}
thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org