This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Problem with 2 ActionForms for one JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with 2 ActionForms for one JSP" Watch "Problem with 2 ActionForms for one JSP" New topic
Author

Problem with 2 ActionForms for one JSP

Gail Mikels
Ranch Hand

Joined: May 07, 2001
Posts: 634
Hi - I'm fairly new to Struts. I thought I understood the configuration setup, but I guess not.

I have a form that, when submitted, sets the form's action value (based on a user-selected value from the form.) This part seems to work (I can output the form.action value thru Javascript & see the correct value).

Before I started the project, the form forwarded to only one ActionForm. I am giving the form more functionality, and would like to put the new functionality into a different ActionForm class, since the logic is not similar.

I have entered a new forward tag in the global-forwards section, as well as a new action tag in action-mappings section of the struts-config file. I literally copy & pasted the old ones, & copy & pasted the new name in all places that held the old name. This new name is the same (copy & pasted) as the form's action value I mentioned above.

The only way I can get my new ActionForm class to be called is if I revert back to the original configuration and simply replace the old class name with my new one. Other than that, I get nothing - no error, no stack trace, and no page.

I've reverted back to just hard-coding my new action in the jsp:


Here's the except from the struts-config file:


Not much to go on, but maybe someone can see the error I've made?

Many Thanks!


Gail Mikels
Ergin Er
Ranch Hand

Joined: Sep 06, 2005
Posts: 60
Do you understand the concept of Struts (the MVC-approach)?
I'm not a Struts wiz either but as far as I know (from the little experience I have) your Form should represent the fields of your jsp page. So if you want to add functionality to your jsp by adding new fields then just extend your form with the field attributes.
If you really want a jsp with same sort of fields doing different things, then just implement a new action-form-jsp.
Your form should only contain the jsp attributes it represents and the logic should be present (or called from) within your action.
Gail Mikels
Ranch Hand

Joined: May 07, 2001
Posts: 634
Not adding new fields. Adding functionality based on user choices from existing fields.

Turns out I've done it correctly - just missed a step in a little-used permissions table in the database.

...another case in favor of DOCUMENTING CODE that others may alter!!!

:roll:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem with 2 ActionForms for one JSP
 
Similar Threads
The page will go to main.jsp even user don't input username?
html:options collection tag help URGENT
struts form being cleared in IE 6
Struts Without Form Bean
ActionForm not populated/is null after mapping