Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Action and ActionForm

Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
couple of questions from beginner:

1. In Action class' "execute(mapping, form, req, res)" method, we can do

SubmitForm f = (SubmitForm)form;
String name = f.getName();

to retrieve "name" value. Can I simply use "String name = req.getParameter("name");" ? What's the difference ? If no difference, why bother creating a "SubmitForm" as mandatory ?

2. I learned <html:select> and <html ptionCollection>. They work well in my example but by default no item is selected. But I want to always set the first item in the listbox as selected item. I don't know what simple tag I can use to make it ?
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can take the value of the field using request.getParameter().But in struts when we use struts tag libaries and ActionForms, the values will be set to the corresponding fields in the action forms.So in the respective Action class we use the form argument of the execute method to get the requried form class and the the value
Suppose i have a jsp called login.jsp and i have one ActionForm class associated with as LoginForm
So in my action class' executem method what i will do to get the username is
LoginForm loginForm = (LoginForm)form;
String username = loginForm.getUsername();

Hope you understood. Please refer jakarta struts site for more information
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic