tks for your great advise, i run the code, but receive the following error /Analysis_input.jsp(17,12) Attribute var invalid for tag iterator according to TLD i check the syntax, then i put extra } inside the tag as the following then i put extra '}' inside <s:checkbox name="%{'bed[' + (st.count -1) + ']'}'" value="#curBed.bed_id"></s:checkbox> and run again, but receive the same error, please advise. tks again john
--- On Fri, 4/10/09, Wes Wannemacher <w...@wantii.com> wrote: From: Wes Wannemacher <w...@wantii.com> Subject: Re: <s:checkboxlist or <s:checkbox To: "john lee" <sh_thorn_b...@yahoo.com> Cc: "Struts Users Mailing List" <user@struts.apache.org> Date: Friday, April 10, 2009, 1:26 AM On Friday 10 April 2009 02:14:22 john lee wrote: > tks for your quick response. > > the reason i initialize there is because try to get fresh list from > database. Preparable will run per invocation, just like execute runs once per invocation. The difference is that execute is likely to run after the view has been rendered. Check this page - http://struts.apache.org/2.x/docs/prepare-interceptor.html > second, as your suggest, i need to change the name, but how? > Really, implementing Preparable and moving the initialization logic to a prepare method is your best option. But, what you have to do to make your checkboxes unique is add some OGNL like this - <s:iterator value="beds" status="st" var="curBed"> <s:checkbox name="%{'bed[' + (st.count -1) + ']'" value="#curBed.bed_id"></s:checkbox> </s:iterator> Now, that code is completely untested and the status object's count member is 1-based, not zero-based as you'll need since you're iterating an ArrayList, that's why there is some math in there. I can't remember if you can do it that way or if you'll just end up with string concatenations... but you get the idea. You could also get done and find the object uninitialized since your logic for loading up the arraylist is done in the execute method. -Wes > tks in advance again > > john > > --- On Fri, 4/10/09, Wes Wannemacher <w...@wantii.com> wrote: > > > From: Wes Wannemacher <w...@wantii.com> > Subject: Re: <s:checkboxlist or <s:checkbox > To: "Struts Users Mailing List" <user@struts.apache.org> > Date: Friday, April 10, 2009, 1:09 AM > > > I'm jumping in a bit late, but I'll add a few observations. I don't think > that execute is the place where you want to initialize your service and > populate the "beds" list... You're better off implementing Preparable and > initializing the list there. > > Second, when you are using the iterator and creating single checkboxes, you > need to make the names unique. You are simply creating a new checkbox with > the name "beds" over and over again. > > -Wes > > On Friday 10 April 2009 01:59:42 john lee wrote: > > I defined an entity java. > > > > public class Bed { > > private String bed_id; > > public String getBed_id() {return bed_id;} > > public void setBed_id(String bed_id) { this.bed_id=bed_id; } > > } > > > > in action file, i did the following, > > public class Analysis_input extends ActionSupport { > > private ArrayList<Bed> beds; > > public String execute() throws Exception { > > ......../ * initialized service...and it is database > > connection */ beds=service.Beds(); > > > > ActionContext.getContext().getSession().put("Beds",beds); return > > SUCCESS; > > } > > public void setBeds(ArrayList<Bed> beds){ this.beds = beds; > > } public ArrayList<Bed> getBeds() { return beds; } > > } > > > > in jsp file, i did > > <s:checkboxlist name="beds" list="beds" /> > > > > but received the error > > > > FreeMarker template error! > > Error on line 28, column 13 in template/simple/checkboxlist.ftl > > stack.findValue(parameters.listKey) is undefined. > > It cannot be assigned to itemKey > > The problematic instruction: > > ==> assignment: itemKey=stack.findValue(parameters.listKey) [on line 28, > > column 13 in template/simple/checkboxlist.ftl] in user-directive > > s.iterator [on line 25, column 5 in template/simple/checkboxlist.ftl] in > > include "/${parameters.templateDir}/simple/checkboxlist.ftl" [on line 25, > > column 1 in template/xhtml/checkboxlist.ftl] > > if i change the jsp file to the following > > > > <s:iterator value="beds" status="st"> > > <s:checkbox name="beds" value="bed_id"></s:checkbox><br> > > </s:iterator> > > > > but receive the new error > > > > <!--StartFragment-->Error on line 28, column 13 in > > template/simple/checkboxlist.ftl stack.findValue(parameters.listKey) is > > undefined. > > It cannot be assigned to itemKey > > The problematic instruction: > > ---------- > > ==> assignment: itemKey=stack.findValue(parameters.listKey) [on line 28, > > column 13 in template/simple/checkboxlist.ftl] in user-directive > > s.iterator [on line 25, column 5 in template/simple/checkboxlist.ftl] in > > include "/${parameters.templateDir}/simple/checkboxlist.ftl" [on line 25, > > column 1 in template/xhtml/checkboxlistany expert can give me the advise? > > i am new to struts 2tks in advancejohn -- Wes Wannemacher Author - Struts 2 In Practice Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more http://www.manning.com/wannemacher