Reputation: 2463
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?
Upvotes: 0
Views: 10934
Reputation: 8513
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.
Upvotes: 1
Reputation: 1567
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>.
Upvotes: 0