aspose file tools*
The moose likes Struts and the fly likes Struts understanding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts understanding" Watch "Struts understanding" New topic
Author

Struts understanding

A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
I have come to the realization that there are some parts of struts that I don't have a good grasp on so it's time to take a step back and get a solid understanding on the things that are confusing me.

<action path="/Selection" type="com.mysample.myproject.SelectionAction" name="SelectionForm" scope="request" validate="true" input="/Selection.do">
<forward name="success" path="/SelectionScreen.jsp"/>
<forward name="failure" path="/failure.jsp"/>
<forward name="invalidSession" path="/login.jsp"/>
</action>

I understand that the type is simply tying this action to a particular form.
I understand the scope is the length of time that this action will have effect.
I understand the forward parts depending on the result from the Action class.
The part that has me confused it the input. I want to be able to validate a form and ensure that there is only positive or zero numbers in the field. My question is where should the input be pointing to if there is an issue?
I'm confused on how that should work.
The page loads with the current values and then the user is given the option to change them before submitting the page. I want validation to ensure they meet the requirements before the page is submitted.
Can anyone offer some insight on this ?

Do I understand correctly in that when the current setup runs it simply re-sends the information to the page, repeating the errors in a continuous loop ?

thanks in advance for your time.
[ May 16, 2007: Message edited by: A knibbs ]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I am not sure that I have ever had the input attribute point back to the same action. I often have a "display" action with validate = false and a "save" action with validate = true. The input on the save action would point back to the display action.

The thing to keep in mind with validation is that it is all done on one request cycle. The user fills out the form and submits the page. All the form values get stuck on the request. Struts populates a form object and then perform validation. If validation fails then the flow goes to your input attribute. This could be a jsp, in which case the values are still on the request so the form is populated. This could also be an action, in which case the request values are used to populate the action's form and I am pretty sure that validation will be performed if it is configured for the action.

- Brent
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
So basically what I have done was create an endless loop that occurs as soon as there is an error, the error is encounted sent to the input page and the cycle repeats until the max stack size is met.

So if I understand you correctly you have a display action (that is used for any saving/validating) that will continue on normally if correct and otherwise go back to the same page with the errors ? If this is the case do you simply pass along any variables that are required when populating the form ?

The part that is confusing me is that I have one that works in a similar manner, the only difference being that the one the works has all the values being initialized to 0 where as the one that doesn't work is being filled in with existing values.

thanks again for all your help on this Brent.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts understanding