2

in our project we have a lot of modal panels to ensure that the user knows what he is about to do. all these panels look alike with just two buttons (ok and cancel).

The only difference is the action that the OK-Button is performing.

Now my idea is to build a generic modal panel that I just call and pass the action which is working fine until I need to pass parameters to the action-method.

I am using this as OK-Button:

<a:commandButton
  id="okGenericPanel"
  action="#{actionBean[action]}"
  value="#{messages['wizard.button.ok.label']}"
  oncomplete="#{oncomplete}">
</a:commandButton>

which is working fine. Calling this looks like the following:

<a:commandLink id="testLink"
   value="#{messages['home.test']}" ajaxSingle="true">
   <rich:componentControl for="genericPanel" 
      attachTo="testLink" operation="show" event="onclick" />
</a:commandLink>
<ui:include src="/components/genericModalPanel.xhtml">
   <ui:param name="actionBean" value="#{adminHomeAction}"/>
   <ui:param name="action" value="sayHello"/>
   <ui:param name="oncomplete" value="alert('im done');" />
</ui:include>

I already tried to give the parameter direclty into the ui:param like this:

<ui:param name="action" value="sayHello('hello')"/>

or in the actual call:

action="#{actionBean[action]('hello')}"

but neither works.

Is there another way to do this? Or is it only possible to call methods without any parameters this way?

thanks a lot for any help, Martin

Martin-Mueller
  • 141
  • 1
  • 10

2 Answers2

0

Provide the parameter as an actionparameter, not as as a method parameter:

First pass it to the modal panel:

<rich:componentControl event="onclick" for="genericPanel" operation="show" attachTo="testLink">
    <f:param value="hello" name="helloParam"/>
</rich:componentControl>

Then pass it to the backing bean when clicking the button:

<a:commandButton id="okGenericPanel" action="#{actionBean[action]}"  value="#{messages['wizard.button.ok.label']}" oncomplete="#{oncomplete}">
    <a:actionparam assignTo="#{someActionBeanField}" value="{helloParam}" converter="..."/>
</a:commandButton>

There is no # sign in the actionparam value attribute above. You also need a converter if the parameter is not String.

There is a better example at richfaces demo site: http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=editDataTable&cid=1025315

dcernahoschi
  • 14,968
  • 5
  • 37
  • 59
0

The "actual call" example should work in EL 2.2, however previous versions of Tomcat 7 (and implicitly also JBoss 6) and Glassfish 3 have had a bug wherein this doesn't work. But this is fixed in the current versions. It works in at least Tomcat 7.0.22 and Glassfish 3.1.2.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555