1) Define your "add" form at the top of struts-config.xml (name=userProfileForm, type=YourFormType)
2) Define two action mappings, the first being a "setup" or "view" action, the second being a "process" or "save" action. Each has a different path, but they will both have the same form (specified by the "name" attribute). Set validation to true in the "view" action mapping, false in the "save" action mapping.
3) (More than one way to do this) Make sure your Action class acts appropriately depending on whether the user has triggered it using the "setup" path or the "save" path. The way I do this is to use the "parameter" attribute to an action mapping. I set the parameter to be "view" for the first mapping, "save" for the second. Then your Action class can invoke mapping.getParameter in the execute method. If the parameter is "view", you really don't need to do anything, just forward on to "success" (the blank form). If the parameter is "save", process the user's form input. This becomes a little more complicated when you begin using "update" forms in contrast to "add" forms, but tackle that when you get to it.
As an alternative to #2 that makes #3 easier, just make the "setup" action mapping very simple, with no form at all:
<action path="/viewUserProfileForm" type="YourFormType" forward="/AddUserProfile.jsp">
Now you have no form bean associated with the "setup" action, because you probably don't need it anyway (unless you need to prepopulate the form in some way), so your Action class is only going to be invoked when /addUserProfile is the action mapping).
Hope that helps.
Erik
PC Leung wrote:
Can I set validation on or off in ValidatorForm dynamically? In the first place, set it off. Later on, set it on.
On Thu, 26 Aug 2004 11:05:30 -0400, Erik Weber <[EMAIL PROTECTED]> wrote:
Well, that looks fine -- /addUserProfile is the path the user will access to submit the form, but what path does your user access to view the blank form in the first place?
Erik
PC Leung wrote:
How can I define it in struts-config.xml as you suggest.
my current fragment of struts-config.xml is the following.
<action path="/addUserProfile" type="com.erp.quotation.AddUserProfileAction" name="addUserProfileForm" scope="request" validate="true" parameter="method" input="/AddUserProfile.jsp"> <forward name="success" path="/AddUserProfile.jsp"/> <forward name="failure" path="/AddUserProfile.jsp"/> <forward name="cancel" path="/UserMaint.jsp"/> </action>
On Thu, 26 Aug 2004 10:55:13 -0400, Erik Weber <[EMAIL PROTECTED]> wrote:
Is validation turned on in the action mapping for your setup action? If you are using the same form bean for both setup and save actions, the action mappings should have validation turned off for the former and on for the latter.
Erik
PC Leung wrote:
The web page displays at the first time with the following error.
java.lang.NullPointerException java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1108) java.text.DateFormat.parse(DateFormat.java:333) com.erp.quotation.AddUserProfileForm.getSqlJoinDate(AddUserProfileForm.java:68) com.erp.quotation.AddUserProfileForm.validate(AddUserProfileForm.java:80) org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:942)
When it first displays, I want it to show with a token. Then I make a setup DispatchAction like the following.
public final class AddUserProfileAction extends DispatchAction { public ActionForward setup (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { saveToken(request); return mapping.findForward("success"); }
How it get a validation error message? Actually submit button has not been clicked.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]