Checking the string length in Expression

I am using JSF and want to have a component that should only be displayed when the String value in the associated managed bean is greater than zero. I'm doing it:

rendered="#{tabbedToolbarBean.editor.selectedQuery.length() gt 0}" 

In addition, the getter signature for selectedQuery is public String getSelectedQuery(){} . I am getting the following error with the latest weblogic server.

Error: The function length has an invalid prefix or uses a default namespace that is not defined. Correct the prefix or in the jsp document, place the function inside the tag that defines the tag library Namespace

What am I missing? I do not get much help after searching the Internet.

+6
source share
2 answers

This means that your environment does not support the new EL 2.2 feature when invoking methods without parenthesized access.

It is best to use JSTL fn:length() .

 <html ... xmlns:fn="http://java.sun.com/jsp/jstl/functions"> ... rendered="#{fn:length(tabbedToolbarBean.editor.selectedQuery) gt 0}" 

Alternatively, just use the empty keyword in EL. The difference is that it also checks for nullness.

 rendered="#{not empty tabbedToolbarBean.editor.selectedQuery}" 

See also:

+9
source

Try the fn: length () JSTL function:

 rendered="#{fn:length(tabbedToolbarBean.editor.selectedQuery) gt 0}" 
+3
source

All Articles