Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Question from beginer

 
ashish kulkarni
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am learning struts and need help is doing the
following
I have one jsp display.jsp which shows name and
descritpion with a check box to select one name,
When the user selects one name and presses change i
want to display a change.jsp with all the info about
that name (name is key) and allow the user to modify
data (excpet name) and then when the user presses okay
validate amd update the database, if there is problem
display error.
I have done soome thing to add a new name, but for
change i need to get the data from database and
populate the fields to display, and then get the
updated fields
I need to know how to write a bean and map it to text
fields??
Ashish
 
J.H.B. Oosterlaar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For every form in your webapplication, you have to write a corresponding formbean of the ActionForm type. In your actionmapping you define a formbean and an action and link them together, etc. When the jsp page is loaded, that contains the <html:form... tag with the specified action, the form has a reference through the action to the corresponding formbean. The values of the properties of the formbean are then already loaded and set at the corresponding formcomponent (textfield, etc.). When the page is requested directly, the properties have default Java values (Strings are null and will result in empty textboxes, etc.).
What you need to do is the following: before you request the jsp page, you should write an Action that loads the data from the database. You create an instance of the specific formbean and set the relevant properties (the values that have to be displayed in the textfields). Then you have to add the instance of the formbean to the requestscope of the forwarded page, the actual jsp page, using the keyname that matches the name of the formbean in you actionmapping.
Jeroen Oosterlaar
[ January 11, 2003: Message edited by: J.H.B. Oosterlaar ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic