PDA

View Full Version : AbstractWizardFormController referenceData() on step two


Reikje
Jun 15th, 2007, 05:54 AM
Hi, I am using a AbstractWizardFormController to handle a form spanning over two pages. My bean class is called MailItemCriteria. In the first step, the user may select and existing mail item or type some content into a textfield. When the second step loads for the first time, I would like to populate a List property in the command bean but only if the user has selected a mail item in the first step.

It would be possible in the referenceData method. However how do I distinguish if step two is displayed for the first time or as a result of a postback that caused a validation error? isFormSubmission() will always evaluate to true because the user is either coming from step 1 (using POST) or has submitted invalid form values.

Thanks in advance,
Reik

sami25
Jun 15th, 2007, 08:18 AM
t would be possible in the referenceData method. However how do I distinguish if step two is displayed for the first time or as a result of a postback that caused a validation error? isFormSubmission() will always evaluate to true because the user is either coming from step 1 (using POST) or has submitted invalid form values.

I doubt whether I understood the question fully, but part of the question I can answer, if you want to know if the page was loaded because of error or it is afresh over ride the following.

protected Map referenceData(HttpServletRequest request, Object command, Errors errors, int page)throws Exception {
if(errors.hasErrors() && page == 2){
// indicates errors contained in page 2
}
// donot set the allowDirtyForward attribute in the wizard controller.


I hope it helps

Reikje
Jun 15th, 2007, 08:53 AM
Thanks for the hint, this seems like a nice workaround. I will try it out.

Could be that the question was not as understandable. I want to populate fields in the command bean based on the user choice in step 1 (and only for the first time step 2 is loaded). Your solution should do the trick.



// donot set the allowDirtyForward attribute in the wizard controller.

What impact has the dirtyForward and why is it important here?

sami25
Jun 15th, 2007, 10:47 AM
What impact has the dirtyForward and why is it important here?

if you have a validator associated with the wizard then the allowDirtyForward will allow the user to go to the 2nd page without validating the data in the page1.

Could be that the question was not as understandable. I want to populate fields in the command bean based on the user choice in step 1 (and only for the first time step 2 is loaded). Your solution should do the trick.

why do you want to populate some fields based on the command object?, if these fields are editable by the user then its normal/good to model these fields in the command object. else you do that in the service layer or the middle tier.

Reikje
Jun 15th, 2007, 11:39 AM
why do you want to populate some fields based on the command object?, if these fields are editable by the user then its normal/good to model these fields in the command object. else you do that in the service layer or the middle tier.

By fields I mean properties in the command object (which are mapped to html input fields). To give you the reason, here is my workflow:

Step 1)
- select existing object from DB or type in some text to check

Step 2)
- if object was selected: load the object from DB and use their text attribute
- if text was typed in: use the typed in text
- extract strings within the text (velocity placeholders)
- populate a map with placeholder names and values in the command bean
- display a html input field for each placeholder name and have the user type in a value

Finish)
- try to parse the text using placeholder values

In Step 2 where I populate the map of the command bean, I only have the (replacement) values, if the user has selected an existing object in Step 1.