0

I have code similar to this in my facelet...

<c:foreach items=#{myBean.listOfA} var="a">

<c:foreach items=#{myBean.listOfB} var="b">

 <c:set var="aName" value="#{a.name}">
 <c:set var="component" value="#{b.associatedComponent(aName)}">//this wont resolve

 //do stuff with component

</c:foreach>


</c:foreach>

myBean is a session scoped bean. Both A and B classes are maintained in lists inside the bean but are just model objects not managed beans.

That being said the method b.associatedComponent(a) I am assuming should resolve to b.getAssociatedComponent(A a) which I have checked many times. All methods are public. What can I do to make the method accessible to EL?

No matter what I try I get a PropertyNotFoundException on associatedComponent.

P.S. I also tried moving the method to the bean like this...

<c:set var="component" value="#{myBean.associatedComponent(b, aName)}">

This also does not work and throws the same PropertyNotFoundException.

Mike Saull
  • 1,415
  • 2
  • 11
  • 11
  • AFAIK, if the method takes an argument, it's not a getter anymore, and the EL thus looks for a method `associatedComponent(A)`, and not for `getAssociatedComponent(A)`. – JB Nizet May 01 '13 at 17:05
  • @JB Nizet I also tried renaming it associatedComponent(A) and that did not work I will retry though. – Mike Saull May 01 '13 at 17:09
  • @JBNizet I confirmed that renaming the method to exactly "associatedComponent(A)" did not resolve the issue. – Mike Saull May 01 '13 at 17:28
  • What is your environment? What is the server you deploy to? Do you know that invoking methods with parameters is an option only since EL 2.2, that's closely connected with Servlet 3.0? – skuntsel May 01 '13 at 17:54
  • I am using EL 2.2 myBean.list.size() works without issue so I am pretty sure that is not the issue. – Mike Saull May 01 '13 at 18:15
  • Can you post your managed bean codes? – erencan May 02 '13 at 06:34
  • Looks like you're working with JSF instead of plain JSTL + EL. What are you trying to achieve? – Luiggi Mendoza May 02 '13 at 17:03
  • I was trying to achieve dynamically generated columns as well as rows for a table. Right now I am using c:foreach inside a Panel grid to output the right number of h:panelGroups then the panel grid formats them into the right number of columns/rows. I realize this probably isn't the best way to do it but h:dataTable didn't seem to fit the bill either. Maybe richfaces dataTable would have though... – Mike Saull May 02 '13 at 17:54

1 Answers1

0

This will not work, as the c:set tag expects a ValueExpression for the value attribute. This means that you are only able to use properties - not methods.

If you use arguments like here #{b.associatedComponent(aName)} then what you have is a method call, not a property call. This however is a valid MethodExpression and can be used in places like the action attribute of a command link. See the API documentation and spec for more details on this.

dratewka
  • 2,104
  • 14
  • 15
  • Is there something I can use to call the MethodExpression inside the forEach? Like f:event or something? I could then use a simple value expression for the retrieval. Like a set then get? – Mike Saull May 01 '13 at 18:22
  • As I understand it the problem is to iterate over two lists which are in some way associated, right? So why not use a map to simplify the situation like [here](http://stackoverflow.com/questions/6164560/how-to-use-jstl-foreach-directly-over-the-values-of-a-map). Is that feasible? – dratewka May 01 '13 at 18:31
  • internally I am using a map so do you think I could use something like #{B.associatedComponents[aName]}? I am trying this now. – Mike Saull May 01 '13 at 19:05