This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Struts and the fly likes ActionForm not passing values to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ActionForm not passing values to JSP" Watch "ActionForm not passing values to JSP" New topic
Author

ActionForm not passing values to JSP

Mario Romero
Greenhorn

Joined: Aug 06, 2007
Posts: 18
Wenas, I have an Action that set the fields of an ActionForm directly, like this:



The ActionForm method looks like this:



After that I checked that the form fields where correctly set.
I expected that in the JSP forwarded, the fields would auto populate with the ActionForm values since names are the same:



...but no, fields are empty. What could be the problem?

Thanks


.NET & JSP developer for <a href="http://www.grupocartuja.com" target="_blank" rel="nofollow"> Grupo Cartuja</a><br /> <br />Currently moving the webpage from ASP to Struts (mostly the Intranet)
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In your code:


Is the form1 variable the result of casting the ActionForm instance sent as parameter to the execute method? If not, that's the problem. example:


Merrill
Consultant, Sima Solutions
Mario Romero
Greenhorn

Joined: Aug 06, 2007
Posts: 18
The problem is that I have an ActionForm for each JSP (in this case at least) to make it more "modularized" instead of relaying in a big ActionForm.

I found this wiki http://wiki.apache.org/struts/StrutsMultipleActionForms which talks about the problem and some solutions. I will just make a bigger ActionForm then and bookmark that page for later use when I find myself more confortable with struts.

Btw what I did was just creating a new ActionForm

And think that the next page will magically take that form since it was the same class it wanted. Forgetting all the OOP basics is my speciality.

Thanks again Merrill.
[ August 24, 2007: Message edited by: Mario Romero ]
Christian Nash
Ranch Hand

Joined: Jan 17, 2006
Posts: 107
Hey this is what i did....

Hope this helps


- Christian
Hari Dhanakoti
Greenhorn

Joined: Jan 04, 2007
Posts: 6
Can we set the form values in request attribute from servlet and display the values of the form bean in JSP?

If setting as attribute can we have any other methods to print the value of the form bean in JSP

Thanks in Advance


Regards<br />Hari
Mario Romero
Greenhorn

Joined: Aug 06, 2007
Posts: 18
mmm thanks Christian, that should made the trick for now.


Hari, to your first question, yes. You can do MyForm.setField(whatever) in the Action, and the form will "transport" the values to the next JSP page which you can show with cut for example.

2� question, an attribute doesn�t pass through the Form, it goes directly in the request to the JSP. There you can show it with cut too.
[ August 24, 2007: Message edited by: Mario Romero ]
 
GeeCON Prague 2014
 
subject: ActionForm not passing values to JSP