Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mixing code for different screens

Status
Not open for further replies.

Lloric

Programmer
Mar 23, 2006
1
US
I need to get a better idea of the process flow for Struts. All of the examples I see talk about a logon screen application. First a .jsp is presented, then the screen data is moved into a ActionForm, then control is handed to an Action which calls the next screen.

My problem is, I don't want to mix code for loading the second screen in with the validation of the logon for the first screen.

Also, I am being told that the process is really, Action --> ActionForm --> .jsp. And the loading of data for the .jsp should take place in the Action. (Which is the opposite of all the logon examples.)

So then I thought, ok, I will just link the logon form Action to another action that will load the second form. I have since heard thats not a good idea.

So a la "the chicken or the egg", which comes first? The action or the display of the .jsp?
 
Tha action comes first then display of the jsp.

> My problem is, I don't want to mix code for loading the second screen in with the validation of the logon for the first screen.

I'm not sure you are. What code are you talking about for loading the second screen? Struts does both the actual validation and forwarding to the second screen for you. All you have to do is set up an ActionForm (or DynaActionForm) and supply some mappings in struts-config.xml.

Simply supplying a ActionForward af = mapping.findForward(SOMEFORWARDNAME); in the action will allow Struts to forward to the correct place?

If you're talking about setting up data ready for your second jsp to display then do the following :

1. a.jsp calls action
2. struts does its validation by looking at the mapping in the struts-config.xml
3. if validation fails forward back to a.jsp and display an actionerror (simply supply a fail mapping in struts-config)
4. if validation passes the rest of your action will get called
5. Go and get the data you need (delegating to another class to do this)
6. Set the data you've got into some scope, probably request via request.setAttribute
7. Forward to success (the success mapping in struts-config that maps to b.jsp)
8. Your second jsp gets called and displays the data in the request via suitable tags

Not sure if this helps or I've missed the point.
 
Hi,

I believe that you have two choices when deciding where to do validation.

1. You can do your validation within the ActionForm subclass by placing your validation code within the "validate" method and when the ActionForm bean is populated by ActionServlet the method will be called at that time.

or.

2. You can use Struts "Validator Plug-In" which isolates the validation routines in xml files.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top