for sake of simplicity, define scenario as: class person defines object id (int) , name (string) attribute. created list<person> persons, loaded jsp page respective action class method (getpersons()), populate <s:radio> tag. far, good, jsp populates <s:radio> accordingly. can select , submit option action class (defined in jsp's <form> element). problem can submit name of selected person in <s:radio>, when want submit person's id. how can it?
practical example: have 2 persons on <s:radio> list, john (with id=1), , peter (with id=2). want display names on <s:radio> element, if choose peter, want submit 2 action class, instead of name.
code below:
jsp
<form action="submitdata" class="ink-form all-100 small-100 tiny-100" method="post"> <s:radio label="persons" name="personid" list="persons.{name}" /> </form> action class (submitdata action)
public class submitdata extends actionsupport { private string personid; public string execute() { system.out.println("person id: "+personid); return success; } public void setpersonid(string personid) { this.personid = personid; } }
in ognl persons.{name} called projection , don't need in <s:radio> tag. use listkey , listvalue attributes define property of objects inside list shown , submitted.
<s:radio label="persons" name="personid" list="persons" listkey="id" listvalue="name" /> one more thing. person id int , trying submit personid string. of course work consider changing personid int. in way, later when want retrieve person object database don't need convert string int.
Comments
Post a Comment