Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionForm not passing values to JSP

 
Mario Romero
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Mario Romero
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey this is what i did....

Hope this helps
 
Hari Dhanakoti
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mario Romero
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic