EL syntax error on

2019-03-04 10:13发布

问题:

I am trying to create a condition for a link where if the length is not = 0 then show the description but I am getting a syntax error the code is:

<c:if test="#{fn:length(#{pqfn:format('ACTUAL_LINK')}) != 0}">
    <h:outputLink id="link1" value="#{pqfn:format('LINK_DESCRIPTION')}"/>
</c:if>

The error I am receiving is:

Caused by: org.apache.el.parser.ParseException: Encountered " <ILLEGAL_CHARACTER> "{ "" at line 1, column 14.
Was expecting one of:
    "." ...
    ")" ...
    "[" ...
    "," ...
    ">" ...
    "gt" ...
    "<" ...
    "lt" ...
    ">=" ...
    "ge" ...
    "<=" ...
    "le" ...
    "==" ...
    "eq" ...
    "!=" ...
    "ne" ...
    "&&" ...
    "and" ...
    "||" ...
    "or" ...
    "*" ...
    "+" ...
    "-" ...
    "/" ...
    "div" ...
    "%" ...
    "mod" ...

回答1:

You can not nest EL expressions as in #{... #{... ...} ...}. This is not making any sense. You should see an EL expression #{... ...} as one big scope where various EL scoped variables and EL functions can interact with each other.

The proper syntax is:

<c:if test="#{fn:length(pqfn:format('ACTUAL_LINK')) != 0}">

The particular exception you got is thrown because the EL parser unexpectedly encountered an { while one of the listed character sequences was expected at that point.



回答2:

You seem to be nesting one EL expression inside another ... that won't work:

#{fn:length(#{pqfn:format('ACTUAL_LINK')}) != 0}
            ^
      can't do this


标签: jsf el