2

我正在尝试为登录的用户类型显示不同的消息,但获取解析异常

<ui:define name="header">
        <ui:param name="userParam" value="#{bean.user.firstName} - #{bean.user.lastName}" />    
        <p:panel id="headerPanel"
            header="#{bean.adminUser ? 'Welcome Power User' userParam : bean.normalUser ? 'Welcome User' userParam :'Welcome to sytem'}"/>
    </ui:define>

这是例外

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

2 回答 2

2

从您的代码:

#{bean.adminUser ? 'Welcome Power User' userParam : bean.normalUser ? 'Welcome User' userParam :'Welcome to sytem'}

您不能以这种方式在 EL 中连接字符串。

如果您使用的是 EL 2.2,则可以使用字符串的concat()方法。

#{bean.adminUser ? 'Welcome Power User '.concat(userParam) : bean.normalUser ? 'Welcome User '.concat(userParam) : 'Welcome to sytem'}

或者,如果您仍在使用 EL 2.1,则应事先由另一个<ui:param>(或<c:set>)准备完整的字符串:

<ui:param name="welcomePowerUser" value="Welcome Power User #{userParam}" />
<ui:param name="welcomeUser" value="Welcome User #{userParam}" />
...
#{bean.adminUser ? welcomePowerUser : bean.normalUser ? welcomeUser : 'Welcome to sytem'}
于 2012-11-08T02:36:48.473 回答
1

使用两个表达式:

#{bean.adminUser ? 'Welcome Power User' : 'Welcome User'}#{userParam}
于 2012-11-08T00:57:32.757 回答