wood burning stoves 2.0*
The moose likes Struts and the fly likes <s:select in <s:iterate tag displaying with comma seperated value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "<s:select in <s:iterate tag displaying with comma seperated value" Watch "<s:select in <s:iterate tag displaying with comma seperated value" New topic
Author

<s:select in <s:iterate tag displaying with comma seperated value

Khyathi nyala
Greenhorn

Joined: Sep 30, 2009
Posts: 5
Hi,

I am having <s:select which contains 5 values inside the <s:iterator tag. Also, I have <s:button tag inside this iterator and button onClick event, calling the javascript function and inside this funciton setting up action and submitting. The code snippet as follows


So my page looks like the following:

<table>
queue name1 dropdown list savebutton
</table>

<table>
queuename2 dropdown list savebutton
</table>



I am accessing this setStatus of <s:select name attribute inside my action class. For example, when I click on first save button, the javascript funciton has been called and coming to the action class. Inside the action class when i try to print the "setStatus", i should get only queue name1 drop down value, But instead iam getting all the quename1, queuename2 drop down value with comma seperated. Can any one please help me how to get only the selected dropdown value of that pariticular submit.

Thanks.


Khyathi nyala
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Khyathi please Use Code Tags when you post a source code. You can edit your message using button and then add code tags to it.

Your JSP code doesn't have a closing iterator tag so I'm assuming that it ends after the table tag. Also you didn't show the form tag so I'm assuming its before the iterator tag. In that case you are generating multiple drop down boxes with the same name, so when you submit the form, there'll be multiple values sent to the server with the name setStatus. To solve your problem, you'll have to use a String array as the setStatus property in your action. Alternatively you can move your form element inside the iterator tag, so that each select tag will be in a separate form thus when you submit, only one setStatus value will be sent to the server. In that case you'll have to change your javascript code a little. Your javascript code doesn't look too good to me anyways, why are you setting the form's action in javascript??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Khyathi nyala
Greenhorn

Joined: Sep 30, 2009
Posts: 5
Hi Ankit,

Thanks for the very quick reply. I do not have any form tag inside my jsp page. So should i use just <form: or <s:form. Can you please give me example for the <s:form to how exactrly use it. ?

For the javascript, i was doing in this way becaue i have the update method inside my action class and i am declaring some this like this to call the method inside the struts.xml



So when i say .submit, it directly calls this update method.

Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You're trying to submit a form and you don't have any forms? I don't see how that will work.

Have you looked at the <s:form> tag documentation? It discusses how to use it. Oftentimes the documentation is one of the best first places to look for documentation.

http://struts.apache.org/2.1.8/docs/form.html
 
 
subject: <s:select in <s:iterate tag displaying with comma seperated value