File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Struts Question from beginer

ashish kulkarni
Ranch Hand

Joined: Aug 15, 2002
Posts: 131
I am learning struts and need help is doing the
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

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 ]
I agree. Here's the link:
subject: Struts Question from beginer
It's not a secret anymore!