3

I Want to get selected checkbox value from checkbox Key property on Action Class as List.

My code look like this

<s:form action="SearchEmail">
    <s:iterator value="ls">
        <s:checkbox name="chk"  key="number" />
    </s:iterator>

    <s:submit value="Go"/>
</s:form>

<s:iterator value="ls" status="stat">
    <s:checkbox name="chk[%{#stat.index}]"  key="number" /> 
    <%-- <s:property value="number"/> --%>
</s:iterator>   

The output is:

Value of CheckBox:{0=true, 1=false, 2=true}

But I need value in String format I don't need Index I need Value of Key property of Checkbox. I want to get the value of Selected Property.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Amrit Singh
  • 59
  • 1
  • 5
  • by specifying an index: http://stackoverflow.com/questions/15338286/editing-arraylist-of-objects-with-struts-2-form-tag/15343980#15343980 – Andrea Ligios Jun 16 '15 at 16:29
  • @RomanC: my 2 cents, but don't delete every old answer not being accepted / upvoted. Apart from the fact that I've got many upvotes a couple of years later having written an answer, it seems not the best choice for SO users (not the careless OP, but the other users). For example you've now linked that question, but the answer is not readable for users with rep < 10.000... – Andrea Ligios Jun 17 '15 at 07:58
  • @AndreaLigios The answers that have not upvotes for a long time will be deleted. – Roman C Jun 17 '15 at 08:08
  • @RomanC No, those are the questions, if I remember well – Andrea Ligios Jun 17 '15 at 08:08
  • 1
    @RomanC: Andrea is right. It's only "abandoned questions" which are deleted. See http://meta.stackexchange.com/q/173513/163863 for criteria. – Matt Jun 17 '15 at 08:10
  • it will be deleted by owner, users (if they are real) should upvote, I don't like to write answers that are neither upvoted, nor accepted. – Roman C Jun 17 '15 at 08:14
  • I have understand the reason that i might have edited Question and would not have uploaded that as an Answer. But could you please let me know what's wrong apart from that? I 'm new to stack-overflow so don't know how to use so i posted incorrectly.I think you should help me to get familiar rather than blocking my access to post Question. I still don't know how to post my code in correct format. – Amrit Singh Jun 17 '15 at 09:05
  • @AmritSingh, welcome to SO. Please [take a tour](http://stackoverflow.com/tour), then read [how to ask](http://stackoverflow.com/help/how-to-ask) and refer to [the related section of the Help Center](http://stackoverflow.com/help/asking) for doubts about asking. To format code, simply put 4 spaces before your code, or use the code button ( `{}` ). Remember to format it properly, and describe what you want with a correct grammar and relevant data only. Eye-candy questions are answered first and better, while effortless and unclear questions are generally downvoted and/or brutally closed. – Andrea Ligios Jun 18 '15 at 09:00

2 Answers2

1

 <s:property value="number"/>

 <s:checkbox  fieldValue="%{number}" name="chk" key="number">  </s:checkbox>  <!-- key="number" -->

</s:iterator>   

wow it's working with above code.Something Magic. Thank every one to letting me resolve it on my own.

Amrit Singh
  • 59
  • 1
  • 5
0

here 'var' attribute makes the sense

<s:iterator value="ls" var="val">

<s:checkbox name="%{val}" id="%{val}"  label="%{val}"></s:checkbox>

</s:iterator> 
gani
  • 99
  • 1
  • 10