Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Action in JSF page

Tags:

jsf

icefaces

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()"

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

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

Thanks,

like image 752
mahesh Avatar asked Jun 02 '11 20:06

mahesh


1 Answers

You can use the brace notation for that.

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

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

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]}" />

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

like image 77
BalusC Avatar answered Oct 07 '22 13:10

BalusC