1

I use Apache MyFaces 2.0.2 on WebSphere Application Server 8.

How do I get the key of a DualTreeBidiMap in a in JSF 2.0?

The DualTreeBidiMap provides a getKey(Object Value) or get(Object Key) method.

I have the Value in another ManagedBean, so I want to print out the Key for this Value with EL.

I've tryed something like this:

<h:outputText value="#{bean1.dualTreeBidiMap.key(bean2.value)}"  />

But this does not work.

veote
  • 1,400
  • 9
  • 33
  • 62

1 Answers1

0

Since your value attribute is a method expression and not a value expression, the correct syntax should be:

<h:outputText value="#{bean1.dualTreeBidiMap.getKey(bean2.value)}"  />

The get prefix needs only to be omitted for value expressions (for fields with a parameterless getter).

Note that method invocation with parameters is only possible since EL 2.2. I am not using WAS 8, but a quick Google search revealed that it should support EL 2.2.

Matt Handy
  • 29,855
  • 2
  • 89
  • 112
  • Sad to say but this solution does not work for me. I've tryed : This also does not work. – veote Jun 07 '12 at 11:31
  • Do you have an exxample for this? – veote Jun 07 '12 at 11:56
  • I tried it with a simple method that takes a String as parameter and returns a modified String. Adapted to your source code it could be something like `#{bean1.dualTreeBidiMap.getKey('hello')}"` - assuming your value is a string. – Matt Handy Jun 07 '12 at 12:02
  • From [this link](http://publib.boulder.ibm.com/infocenter/ieduasst/v1r1m0/index.jsp?topic=/com.ibm.iea.was_v8/was/8.0/ProgramingModel/WASV8_Servlet_JSP_EL/player.html) EL 2.2 should be part of WAS 8 – Matt Handy Jun 07 '12 at 12:27
  • How do I check if EL 2.2 is available? Is there a method, maybe in FacesContext? – veote Jun 07 '12 at 12:37
  • Check this answer for more hints: [http://stackoverflow.com/a/7237216/620338](http://stackoverflow.com/a/7237216/620338) – Matt Handy Jun 07 '12 at 12:45
  • Ok, my Dynamic Web Modulei is 3.0 (Servlet 3.0), but where is the problem ? :( – veote Jun 07 '12 at 12:48
  • Hm.., just the routine questions: are the getters called? Does your method work if you call it from a bean and not from the view? – Matt Handy Jun 08 '12 at 05:59
  • So, I had a little mistake. When I call my method from bean it works fine. When I call it from view I get a java.lang.NoSuchMethodException: org.apache.commons.collections.bidimap.DualTreeBidiMap.getKey(java.lang.String) – veote Jun 08 '12 at 06:37
  • A solution might be to use a wrapper function in your bean that makes the call to the DualTreeBidiMap. – Matt Handy Jun 08 '12 at 06:42
  • I've tryed that too but without success :/ – veote Jun 08 '12 at 07:14