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

Struts Question from beginer

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic