This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes Options Tag not Recognizing Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Options Tag not Recognizing Collection" Watch "Options Tag not Recognizing Collection" New topic
Author

Options Tag not Recognizing Collection

Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
Background:

I have a standard JSP page where I pass in a basic transfer object (charistic) that contains a property (charelements) that is an ArrayList of Charelement objects. Each Charelement object contains an element String and and ID which is of type integer.
So in my jsp page I can iterate through the collection with the standard forEach tag without any issue.

c:forEach var="element" items="${charistic.charelements}"

Issue:

However, when I try and build an options tag in the following manner, I get an error (I left out the < and > brackets).

html:select property="${charistic.charisticbeanname}" value="${charistic.invvalue}"

htmlptions collection="${charistic.charelements}" property="elementID" labelProperty="element"

/html:select


Here is the error:

Cannot find bean under name [com.product.to.CharelementTO@c2060e

I'm not sure why the forEach tag will recognize my collection definition and yet the options tag does not?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Issues with Struts tags should be raised in the Struts forum. I have moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
Let me re-phrase my question a little:

Let's say I am passing to my JSP page one transfer object A which contains a property (called bs) that consists of an ArrayList of transfer objects B. Each of the B transfer objects contain a property (called cs) that consists of an ArrayList of transfer objects C.

So in my JSP page I start iterating through the B transfer objects with the following forEach statement:

forEach items="${A.bs}" var="bs"

Now I'm iterating through the ArrayList of B objects by referencing them by the bs parameter. Within this iteration, I want to iterate through the ArrayList of C objects that are tied to each of the B objects. In the past, I've used a second forEach iteration to iterate through the ArrayList of C objects like this:

forEach items="${bs.cs}" var="cs"

And now I'm able to access/iterate through the ArrayList of C objects that are imbedded within the ArrayList of B objects that is ultimately imbedded in the one A object. I use this second forEach to create a options list HTML element.

What I don't understand is why I can't replace the second forEach with the following code:

select property="${bs.somebeanproperty}"
html ptions collection="${bs.bs}" property="elementID" labelProperty="element"

..where the elementID and element properties have the appropriate setter/getter methods in the C object.

This is the error that I get when I try to use the above code:

Cannot find bean under name [com.product.to.CharelementTO@1747e0f, com.product.to.CharelementTO@100200c]

Where CharelementTO is equivalent to the C object noted above.

So why would the forEach be able to recognize the C ArrayList and not the html ptions (when I use it with the collections property) not recognize it.

Any ideas?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Options Tag not Recognizing Collection