File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes jsp hidden field not populated in  ActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "jsp hidden field not populated in  ActionForm" Watch "jsp hidden field not populated in  ActionForm" New topic
Author

jsp hidden field not populated in ActionForm

matt love
Ranch Hand

Joined: Jan 25, 2010
Posts: 65
I've read many coderanch conversations and still need to ask:

Why doesn't the hidden field get populated to the ActionForm? It's like RequestUtils.populate ignores the field.

Then, how can I modify the same hidden field depending on which link the user selects? Should javascript and DOM work?




ActionForm




Action


web.xml


config




Thanks.

Matt

Jaimesh M Ponkia
Greenhorn

Joined: Nov 24, 2010
Posts: 21
HTML Link does not carry the form data. You can either go for different submit buttons or pass the values as parameter to the action link and fetch it accordingly in action class. Use the rewrite tags to hide parameters it from the end users.
matt love
Ranch Hand

Joined: Jan 25, 2010
Posts: 65
Thanks Jaimesh,

I had come up with a work-around, similar to your first solution with two Submits.

In the config I created two mappings, each going to the same Action, one mapping each from the two links with different actions, ie, <html:link action="/chooseDataStoreTypeDataBase"> for one and <html:link action="/chooseDataStoreTypeArray"> for the other. The config entries:



The trick was creating an Interface that each of the mapping's form extended. Each form had a different literal, eg, one form had private static final String dataStoreType = "array"; and the other private static final String dataStoreType = "dataBase";. Thus, in the Action I could test the Interface and polymorphically determine which Link sent the request.

I've since modified my solution by utilizing request.getRequestURI() in the Action.

Maybe not the most elegant solution, but it seems reasonable.

I included alot of the above code in case someone can use it later.

Thanks again.

Matt


Jaimesh M Ponkia
Greenhorn

Joined: Nov 24, 2010
Posts: 21
If you were using the hidden variable only to determine which link was clicked then you can go for using LookUpDispatchAction and set the action according to your link. This way you will not have to make 2 entries in struts-config and not worry about requestURI.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp hidden field not populated in ActionForm
 
Similar Threads
Validation in struts
Problem with logic:present
Problem with logic:present tag
Servlet Action not found
Verification failed on Username existence check using AJAX