Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ActionForm not passing values to JSP

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey this is what i did....

Hope this helps
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 c:out 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 c:out too.
[ August 24, 2007: Message edited by: Mario Romero ]
 
This is my favorite tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic