简体   繁体   中英

No getter method for property - JSP Exception

In my Struts-config.xml file,

<action path="/getTareWeight" 
  type="com.astrazeneca.usbod.scale.actions.GetTareByBarcodeAction"  
  name ="getTareByBarcodeForm" 
  scope="request" 
  validate="true" 
  input="/jsp/getTareByBarcode.jsp">

    <forward name="success" path="/jsp/tareWeightResult.jsp" />
  </action>

In GetTareByBarcodeForm which extends the ActionForm the following getter and setter methods are there,

public String getBarcodeString() {
    return (this.barcodeString);
}

public void setBarcodeString(String barcodeString) {
    this.barcodeString = barcodeString;
}

public String getResult() {
    return (this.result);
}

public void setResult(String result) {
    this.result = result;
}

In the GetTareByBarcodeAction.java file,

public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response)
        throws IOException, ServletException{
      String target = new String("success");
      double tareWeight=0;
      String tw = new String("");
      GetTareByBarcodeForm gForm = (GetTareByBarcodeForm)form;
      String errorString;
      StringTokenizer t = new StringTokenizer(gForm.getBarcodeString(),
      " \t\n\r\f:,;.");
      List barcodeList = new ArrayList();
      List tareWeightList = new ArrayList();
      while (t.hasMoreTokens()) {             
        barcodeList.add(t.nextToken().trim());           
      }
      int size = barcodeList.size();
      VesselProcessor vproc = VesselProcessor.getInstance();
      for(int i=0;i<size;i++)
      {
        tareWeight = vproc.checkTares((String) barcodeList.get(i));
        tw=Double.toString(tareWeight);
        tareWeightList.add(barcodeList.get(i));
        tareWeightList.add(tw);
        String temp = barcodeList.get(i).toString();
        gForm.setBarcodeString(temp);
        gForm.setResult(tw);
      }

    request.setAttribute("TAREWEIGHT", tareWeightList);
    return (mapping.findForward(target));       
}

In the tareWeightResult.jsp file, i am printing the values in the attribute TAREWEIGHT in a table format.

<logic:present name="TAREWEIGHT">
        <logic:iterate id="result" name="TAREWEIGHT">
            <tr>
                <td>
                    <bean:write name="result" property="barcodeString"/>
                </td>
                <td>
                    <bean:write name="result" property="result"/>
                </td>
            </tr>           
        </logic:iterate>
    </logic:present>

When I tried to run this functionality after deploying it in weblogic server, I have the below error in log.

javax.servlet.jsp.JspException: No getter method for property barcodeString of bean result
at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:968)
at org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:286)
at jsp_servlet._jsp.__tareweightresult._jsp__tag2(__tareweightresult.java:237)
at jsp_servlet._jsp.__tareweightresult._jspService(__tareweightresult.java:174)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)

Can anybody let me know where I have gone wrong in this scenario?

As far as I can see from your code, there are no GetTareByBarcodeForm instances in the tareWeightList : the latter contains String s, so when bean:write tries to extract the property, it cannot: String doesn't have such a getter.

Perhaps you should revisit your logic extracting the values, and wrap the results in proper instances.

So your code should look more like the following:

    for (int i = 0; i < size; i++) {
        tareWeight = vproc.checkTares((String) barcodeList.get(i));
        tw = Double.toString(tareWeight);
        String temp = barcodeList.get(i).toString();

        GetTareByBarcodeForm f = new GetTareByBarcodeForm();
        f.setBarcodeString(temp);
        f.setResult(tw);
        tareWeightList.add(f);
    }

so that the result list, the one you pass as TAREWEIGHT , would contain proper objects.

Still, that's not too good: now, GetTareByBarcodeForm plays two roles, the actual form and the search result entry. So I would highly recommend introducing a new class, TareTableEntry , and only include table details in it:

    for (int i = 0; i < size; i++) {
        tareWeight = vproc.checkTares((String) barcodeList.get(i));

        TareTableEntry entry = new TareTableEntry();
        entry.setBarcodeString(barcodeList.get(i));
        entry.setResult(tareWeight);
        tareWeightList.add(entry);
    }

That's more code, but it pays off in a long run.

The id with "result" is represented by TAREWEIGHT. Does this object has the barCodeString property ? It looks to me that there is some problem with the bean name in

<bean:write>.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM