GeeCON Prague 2014*
The moose likes Struts and the fly likes Struts Question from beginer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Question from beginer" Watch "Struts Question from beginer" New topic
Author

Struts Question from beginer

ashish kulkarni
Ranch Hand

Joined: Aug 15, 2002
Posts: 130
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


A$HI$H
J.H.B. Oosterlaar
Ranch Hand

Joined: Sep 12, 2002
Posts: 41
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 ]
 
GeeCON Prague 2014
 
subject: Struts Question from beginer