JSF页面中的动态操作 [英] Dynamic Action in JSF page

查看:92
本文介绍了JSF页面中的动态操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSF页面.我的CommandButton动作方法值取决于bean变量值. 例子: Bean headerBean具有可变的actionValue,其值为"someBean.doAction1()"

I have a JSF page. My CommandButton action method value is dependent on the bean variable value. Example: Bean headerBean has varaible actionValue with value "someBean.doAction1()"

当我使用时,它说headerBean.actionValue不是正确的方法.

When I use , It says headerBean.actionValue is not a method which is right.

如何获取操作值"someBean.doAction1"而不是headerBean.actionValue.

How can I get the action value as "someBean.doAction1" instead of headerBean.actionValue.

谢谢

推荐答案

您可以为此使用大括号符号.

You can use the brace notation for that.

<h:commandButton value="submit" action="#{someBean[headerBean.actionValue]}" />

#{headerBean.actionValue}返回例如doAction1的字符串时,这将有效地调用#{someBean.doAction1}.

When the #{headerBean.actionValue} returns a String of for example doAction1, then this will effectively invoke #{someBean.doAction1}.

如果要调用的bean名称当前实际上在actionvalue中(headerBean.actionValue返回someBean.doAction1),则需要将其拆分为一个返回bean名称的字段和一个返回方法名称的字段,然后使用

If the bean name to be called is currently actually in the actionvalue (headerBean.actionValue returning someBean.doAction1), you need to split it into a field that returns the bean name and one that returns the method name and then use

<h:commandButton value="submit" action="#{requestScope[headerBean.beanName][headerBean.actionValue]}" />

如果headerBean.beanName返回'someBean'并且headerBean.actionValue返回doAction1,则上面的代码将调用#{somebean.doAction1}.

If headerBean.beanName returns 'someBean' and headerBean.actionValue returns doAction1 the above will call #{somebean.doAction1}.

这篇关于JSF页面中的动态操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆