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/12 04:02:37 UTC

struts 2,
 
in struts 2, try to do following:
 
  a.    use <s:select to display the selectable list (get value from db)
  b.    pickup the selection, 
  c.    query the db
  d.    use <s:select to display the selectable list still, and display the query result
 
2 Bean file
 
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; }
}
 
public class BedAnalysis {
  private String bed_id;
  private String status;
  public String getBed_id() {return bed_id;}
  public String getStatus() {return status;}
  public void setBed_id(String bed_id) { this.bed_id=bed_id; }
  public void setStatus(String status) { this.status=status; }
  }
 
Action 
 
public class Analysis_input implements Action {
    private ArrayList<Bed> beds;
    private ArrayList<BedAnalysis> bedanalysis;
    private String bed_id;
   
    public String execute() throws Exception {
                  ....  /* db initial, get session etc */
                  beds=service.Beds();              /* service is call db */
                  String first_time=null;
                  first_time=ActionContext.getContext().getSession().get("FIRST_TIME");
                  if (first_time==null)
                      session.put("FIRST_TIME","1");
                  else {
                       bedanalysis=service.Analysis2(getBed_id());
                       }

                  return SUCCESS;
    }
 
    public void setBeds(ArrayList<Bed> beds){ this.beds = beds; }
    public void setBed_id(String bed_id){ this.bed_id = bed_id; }     
    public void setBedanalysis(ArrayList<BedAnalysis> bedanalysis){ this.bedanalysis = bedanalysis; }
    public ArrayList<Bed> getBeds() { return beds; }
    public String getBed_id(){ return bed_id; }
     public ArrayList<BedAnalysis> getBedanalysis() { return bedanalysis; }
   
struts.xml
    <action name="Analysis_input" class="matco.Analysis_input">
            <result name="error">/Analysis_input.jsp</result>
            <result name="input">/Analysis_input.jsp</result>
            <result name="success">/Analysis_input.jsp</result>
        </action>
 
jsp file
    <s:form id="analysis" action="Analysis_input">
         <s:select label="beds" name="beds" headerKey="1" headerValue="Please Select Bed#" list="beds" listKey="bed_id" listValue="bed_id"  value="%{#beds{bed_id}}"/>
        <s:submit value="Query"/>
    </s:form>
     <s:iterator value="bedanlysis" status="st" >
               <s:property value="bed_id"/>&nsp&nbsp<s:property value="status"/>          </s:iterator>
 
when i call Analysis_input.action, it works, the select box pop the value from db
   but after i select value of bed_id and submit, page render back, and show me the following
        



Invalid field value for field "beds".

beds:
 Please Select Bed# 
 
i did select the value of bed_id, why this happen?
 
the weird thing even are:  the select list box' all value are gone.
 
pls help me
 
john