Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with nested:iterate tag on Struts 1.2 with Websphere 5.1.2

 
Ben Liu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm having a problem with a web application that I'm developing. I'm using nested objects with Struts, JSTL and WASD 5.1.2

My code works fine in WASD 5.0, but breaks in WASD 5.1.2. The error says that it can't find a getter method for a property.

This is an indexed property.

My ActionForm is as follows:

Public class MyActionForm extends ActionForm {
private IndexedProperty MVBreakdowns; // a class that wraps around a HashMap

public Collection getMVBreakdowns() {
// returns as an ArrayList
}

public MarketValueBreakdown getMVBreakdowns(int i) {
// return the ith MarketValueBreakdown object
}

public void setMVBreakdowns(int i, MarketValueBreakdown breakdown) {
// sets the ith MarketValueBreakdown
}

My JSP is as follows:



...


I also tried using JSTL tags:




Both have similar issues with WASD 5.1.2, but works fine with WASD 5.0

Is this a known issue with Websphere?

is there a work around that does not include using straight JSP scriptlets?

Thanks in advance!
-Ben
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a similar problem when porting from Java 1.3 to 1.4. The problem is that for some reason the reflection API doesn't seem to handle overloaded methods in quite the same way it used to. I ended up just naming my indexed getter differently than my collection getter. In your case, change the name of the indexed getter to getMVBreakdown(int i), and it should work.
 
Ben Liu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I confirmed that it is an overloaded method issue.

My JSP, however, is as follows:

<nested:iterate property="MVBrakdowns">
<nested:write property="MVBreakdowns.sectionId" />
</nested:iterate>

This needs both the Collection getMVBreakdowns() and the MarketValueBreakdown getMVBreakdowns(int i) methods to be named the same.

Is there another alternative or workaround for this?

I don't think WAS 5.1.2 is a JSP 2.0 container or else I could do something as follows:

<c:forEach items="${form.MVBreakdowns}" var="mvbreakdown" varStatus="breakdownStatus" >
<html:text property="MVBreakdowns[${breakdownStatus.index}].sectionId" />
</c:forEach>

I still want to avoid JSP scriptlets, but it seems that might be the best route.

Thanks in advance!
-Ben
 
Ben Liu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Real problem:

Indexed properties should be expressed as follows:

public class MyForm extends ActionForm {

public Object[] getIndexedProperty() {
}

public void setIndexedProperty(int i, Object property) {
}
}

// the following causes problems for JDK 1.4:
public Collection getIndexedProperty() {
}

public Object getIndexedProperty(int i) {
}

public void setIndexedProperty(int i, Object property) {
}

JSP as follows:

<nested:iterate property="indexedProperty" >
<nested:hidden property="subProperty" />
</nested:iterate>

Regards and thanks for the help,
-Ben
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic