Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Struts understanding

Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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="/">
<forward name="success" path="/SelectionScreen.jsp"/>
<forward name="failure" path="/failure.jsp"/>
<forward name="invalidSession" path="/login.jsp"/>

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 ]
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic