aspose file tools*
The moose likes Struts and the fly likes Struts 1.2 ActionForm pre-filling question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 1.2 ActionForm pre-filling question" Watch "Struts 1.2 ActionForm pre-filling question" New topic
Author

Struts 1.2 ActionForm pre-filling question

Edgardo Mejias
Greenhorn

Joined: Jun 15, 2012
Posts: 1
I am new to Struts and need some help understanding how to best pre-fill an ActionForm. At a high level, I created a jsp page, ActionForm and Action for some user information. The form, field validations, etc... all work well as expected. I would like to implement an edit function that would pre-load the user information onto the form and allow the user to update. I have the update portion of the code working (saving updates to database), but have not figured out how to get the form to pre-load the user info. I have developed a User object stored in the session with getter, setter, save, initialize, etc... methods.

Questions:
1) Should the pre-loading occur in the ActionForm or the Action?
- If in the ActionForm, how can I access the session to retrieve the User object?
- If in the Action, where and how can it be done? In the execute method of the Action, I can use the request object to get to the session, but the execute method only seems to execute after the form passes the validation process, not when the jsp/ActionForm is first initialized.
2) I tried importing the User Object onto the jsp page, but when I use the html:text tag in conjunction with the bean:write tag, it gives me an error referring to no bean found in scope. If I need to declare the the User object as the page bean object, how do I go about doing so?

I can upload the Action/ActionForm/jsp code and the struts config if needed, but I was hoping to get a high level understanding of how to best approach this scenario. Please let me know if you need the code and configuration files to help answer my question?

Thank you

Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Hi Edgardo,

Welcome to JavaRanch!!!


Edgardo Mejias wrote:..., but have not figured out how to get the form to pre-load the user info.
What does it exactly mean - on page load or on submission of the page?
Edgardo Mejias wrote:I have developed User object stored in the session with getter, setter, save, initialize, etc... methods
This is not required until and unless you want to save the data for the complete session
Edgardo Mejias wrote:Should the pre-loading occur in the ActionForm or the Action?
I prefer ActionForm, you can still have a behavior in form [say formPrePopulate] which accepts "request"[through action class] as parameter from where we can access session. I prefer this to make sure my form deals only with fields/data and action class deals only with the action it needs to perform for the request.
Edgardo Mejias wrote:but when I use the html:text tag in conjunction with the bean:write tag
Please do not mess up the JSP's, why would we need a framework if we can not make use of it to the fullest? It would make our job more tedious later.



Have Fun with Java
little,little.. little by little makes a lot..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 1.2 ActionForm pre-filling question