You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by john lee <sh...@yahoo.com> on 2009/04/10 07:59:42 UTC

 
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     


      

Re: Posted by Dave Newton <ne...@yahoo.com>.
Wes Wannemacher wrote:
> 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. 

Putting in an index only matters if order is important (and you don't 
trust the browser to submit in order); if a page has multiple variables 
of the same name their values will be put into an array or collection 
action property.

For a checkbox w/ a true/false value probably need either an index or to 
use a map-based property.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Posted by Wes Wannemacher <we...@wantii.com>.
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


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org