我有一个JSF页面。我的CommandButton动作方法值取决于bean变量值。示例:Bean headerBean具有可变的actionValue,其值为“ someBean.doAction1()”
当我使用时,它说headerBean.actionValue不是正确的方法。
如何获得作为“ someBean.doAction1”而不是headerBean.actionValue的操作值。
谢谢,
您可以为此使用大括号符号。
<h:commandButton value="submit" action="#{someBean[headerBean.actionValue]}" />
Run Code Online (Sandbox Code Playgroud)
#{headerBean.actionValue}例如doAction1,当返回String时,它将有效地调用#{someBean.doAction1}。
如果要调用的bean名称当前实际上在actionvalue(headerBean.actionValuereturning someBean.doAction1)中,则需要将其拆分为一个返回bean名称的字段和一个返回方法名称的字段,然后使用
<h:commandButton value="submit" action="#{requestScope[headerBean.beanName][headerBean.actionValue]}" />
Run Code Online (Sandbox Code Playgroud)
如果headerBean.beanName返回'someBean'并headerBean.actionValue返回doAction1,则将调用#{somebean.doAction1}。
| 归档时间: |
|
| 查看次数: |
1137 次 |
| 最近记录: |