2

I can't get method calls with parameters to work in JSF 2.0 (MyFaces) and Tomcat 6.

This is how I try it:

<f:selectItems var="item" value="#{bla.someList} itemValue="#{item.value1}" itemLabel="#{item.value2}"> <f:param name="param1" value="0" /> </f:selectItems>

I can't define the method like this, right? And why not?

getSomeList(int a)

So this is what I tried:

getSomeList() {
Integer a = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("param1")); 
return doSomething(a);
}

And this is what I get:

java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:417)

I would be very grateful if someone helped me out. Thanks!

UPDATE: Ah, it worked with #{bla.getSomeList(0)}!

2 Answers 2

5

I can't define the method like this, right?

getSomeList(int a)

No.

And why not?

Because you're using old Tomcat 6 which doesn't support EL 2.2 where this feature was introduced.

And this is what I get:

java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:417)

Because there it is null. The <f:param> works in links/buttons only, not on plain components.

In order to get method calls in EL to work, you need to upgrade to a Servlet 3.0 / EL 2.2 capable container like Tomcat 7, or to replace Tomcat 6's default EL 2.1 implementation by one which supports parameterized method calls. For detail see this answer. Once done that, you can use

<f:selectItems value="#{bla.getSomeList(0)}" ... />

An alternative is to replace List by Map, which can be a custom implementation which does (lazy) loading on get() method.

public Map<String, List<Something>> getSomeMap() {
    return someCustomLazyLoadingMap;
}

with

<f:selectItems value="#{bla.someMap.keyName}" ... />
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! But it worked with #{bla.getSomeList(0)} instead of #{bla.someList(0)}
0

Try using

<f:selectItems var="item" value="#{bla.someList(0)} itemValue="#{item.value1}" itemLabel="#{item.value2}"/>

This works for some implementations of JSF.

2 Comments

This is not JSF specific. This is EL specific.
Yes you are right. But I knew it was possible in some cases :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.