• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Struts 1.2 ActionForm pre-filling question

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 329
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Yeah. What he said. Totally. Wait. What? Sorry, I was looking at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic