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

ActionForm question (struts 1)

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first page of my app is /myapp/showOption, it has a drop-down list containg some dat that is retrieved from database. so in struts-config.xml I set

<action path="/showOption" type="...MyAction", name="myForm", input="show.jsp">
<forward name="success" path="/showOption"/>
</action>

The "myForm" maps to a Form class defined in <form-bean>

when user clicks "/showOption" link, it triggers "MyAction" class' "execute" method, it gets data from database and do the setting methods on the form, show.jsp displays the values in drop down list.

On "show.jsp", there is a "update" button, user can pick one item from the options list and clcik "update", it saves this new value into another table. so the button links another action "/updateOption". Now, my question is --

I create another mapping for "/updateOption"--

<action path="/updateOption" type="...UpdateAction", name="myForm", input="show.jsp">
<forward name="success" path="/showOption"/>
</action>

I want that, after clicks "update", it stays on the "show.jsp" page. Question is --

For "update" action, can I use the SAME action form for display action ? The display form has an attribute that is a List of values. But for "update" action, I just need to input the selected value to the action. If using the same form, how do I get the selected item in the "execute" method of "update" action class ?
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes of course you can use the same form even the same action class.

To read the selected value just get it from the Dropdown list property from the ActionForm

If you have options to select multiple values in the Dropdown list, it will be returned as Array i think.

You can even use the same action instead of new one.

just create a hidden field and create a appropriate proerty in the ActionForm also.

So when you click the update button set the hidden field to some value and check that value inthe action class if the value is set then you have to update the data into the DB else the request is to retrieve the data from DB to display them in the Dropdown box.This will limit the number of Actions.

e.g. <html:select property="userType">
<html: options collection="types" property="typeid" labelProperty="typename"/>
</html:select>

then read the property userType to get the selected value in the action class.
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
appreciate it.
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
do you think this will work ?

public class MyForm extends ActionForm {
private String selectedItem;

private List items;
}


<html:select property="selectedItem" >
<html:optionsCollection name="myForm" property="items" value="id" label="name"/>
</html>

where "items" is collection of object of the following class --

public class VO {

private string id;
private string name;
}

so in the action class, I set the values for the "items" attribute of "MyForm" but leave "selectedItem" there, then when user selects an item, this attribute (selectedItem) of the form will be set and it can be carried to the next action after user clicks submit button. Does this make sense ?
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,It should work.
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic