Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

call struts action on change of combobox value

Status
Not open for further replies.

Amrun

Programmer
Jul 20, 2005
2
DE
Hi,

I've written a struts-application that shows a list of announcements taken from the database (oracle). In this list (table) I want to add the functionality of changing visibility of the announcement (via a combobox with Yes or No). This changes should be transferred to the database. Here is my sample-code piece:

<logic:iterate id="ann" name="announcements">
<tr>
<td class="list"><bean:write name="ann" format="yyyy-MM-dd" property="val(ADATE)" /></td>
<td class="list"><bean:write name="ann" property="val(TITLE)" /></td>
<td class="list"><html:select name="ann" property="visible" value="val(VISIBLE)" size="1">
<html:eek:ption value="true">Yes</html:eek:ption>
<html:eek:ption value="false">No</html:eek:ption>
</html:select></td>
<td class="list"><html:link action="/administration/announcements/annEditPreparation" paramId="id" paramName="ann" paramProperty="val(ID)"> Edit </html:link></td>
</tr>
</logic:iterate>

I've read about the onchange option of <html:select> tag but I guess this only works with java-script?

I also have another problem - the comboboxvalue that is displayed doesn't equal with the value in the database. Does anyone know why this occures?

Thx for help,
Amrûn
 
Future tip: use the code [] tags please. Thanks.

Code:
<html:select name="ann" property="visible" value="val(VISIBLE)" size="1"><html:option value="true">Yes</html:option><html:option value="false">No</html:option></html:select></td>

If this is the combo box you are refering to, I'm not sure what values you have in the database, but Yes and No are displayed but value="" is what is actually transfered. So if the person selects yes and submits, then "true" is the value sent.

As far as the onchange bit. If you put that in one of the struts tags it auto-generates a javascript for you and attaches itself to that box/item. It's a short cut from having to actually learn Javascript but it's not some new cool feature if that's what you're thinking it is.

From the tag lib web page:

onchange JavaScript event handler executed when this element loses input focus and its value has changed. [RT Expr]

Located Here:

If you change the -html to -bean or -logic you can see all the other struts taglib definitions.

HTH

Andrew
 
First: Thx for the tip with the code tags. I didn't know how to post code in the correct way.

I think I wasn't able to explain my problem in a proper way. So I will try it again.
I have some data stored in my database. Actually it concerns announcement with the items date, id, title, text, visible. I want to show a list (table) with the stored announcements in my webapplication. To make it easier for the user I want to implement the function that the visible-item can be changed in this list (table) via a combobox.

The database-query to get all Announcements is called in the base action for the announcements. There I get an Collection which I forward via the request - parameter ( request.setAttribute("announcements", ann); ).

In the index.jsp page (for displaying the announcements I iterate through this collection.

Code:
<logic:iterate id="ann" name="announcements">
<tr>
  <td class="list"><bean:write name="ann" format="yyyy-MM-dd" property="val(ADATE)" /></td>
  <td class="list"><bean:write name="ann" property="val(TITLE)" /></td>
  <td class="list"><html:select name="ann" property="visible" value="val(VISIBLE)" size="1" onchange="document.forms[0].submit();">
                     <html:option value="true">Yes</html:option> 
                     <html:option value="false">No</html:option>
                   </html:select></td> 
  <td class="list"><html:link action="/administration/announcements/annEditPreparation" paramId="id" paramName="ann" paramProperty="val(ID)"> Edit </html:link></td>
  <input type="hidden" name="id" value="<bean:write name="ann" property="val(ID)" />" /> 
</tr>
</logic:iterate>

In my opinion the actual value for the combobox should be displayed, but this doesn't work.
I've tried to use the document.forms[].submit() and this works fine, but how can I set the parameters? Because I must get the id from the data-row I have to edit.

I hope this explanation was a clearer?!
Thx for help
Amrun
 
Hi,

Write up javascript function and pass the ID, and call that function on onChange of the select box.

Cheers
Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top