2

I have the same problem as user1598186 has stated in his question here : p:commandButton doesn't call bean's method in an <ui:include> page

However, no solution has been given (he has removed <ui:include> tags altogether and used variables instead)

Are there any ways of using <ui:include> and still have my backing bean's method executed, when I'm calling it inside the commandButton.

Any help will be much appreciated.

Community
  • 1
  • 1
sciFi
  • 161
  • 1
  • 2
  • 9

1 Answers1

3

EL 2.2 method parameters (so, #{bean.method()} instead of #{bean.method}) can be used to pass a method signature that can be used in the actionListener attribute of a commandButton. The following is an example of passing a ManagedBean property as well as passing a method signature:

Main Page

<ui:include src="/jointeam.xhtml">
  <ui:param name="propertyValue" value="#{managedBean.property1} />
  <ui:param name="method" value="#{managedBean.performAction()}" />
</ui:include>

jointeam.xhtml

...

<h:inputText value="#{propertyValue}" />

...

<p:commandButton value="Submit" actionListener="#{method}" />

You can see how powerful this is in terms of code reuse and for many instances is less verbose and easier to use than composite components.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
maple_shaft
  • 10,435
  • 6
  • 46
  • 74
  • Will the `` work even if the redirection is being done by a method in the bean? eg: ` ` Please help.. – sciFi Feb 21 '13 at 05:50
  • @sciFi I believe the src attribute takes a string property, so as long as navigation returns a valid FILE PATH then it should work. Remember that this component includes an xhtml file, not requesting an xhtml page – maple_shaft Feb 21 '13 at 11:06
  • i do return the name of a page (using if condition) in my bean, so it is a String that is returned as `my_page.xhtml` But the parameter passed using `` is not being read inside my_page (which is inside ``. Am I doing something wrong? Please help.. – sciFi Feb 21 '13 at 11:25
  • @sciFi Hmmm... perhaps you can post your code in a seperate question? It is hard to diagnose issues in the comments section. – maple_shaft Feb 21 '13 at 11:51
  • I have posted it as a separate question [link is here](http://stackoverflow.com/questions/15002272/dynamic-ui-include-and-commandbutton). if my question is still not clear, please do tell me.. Any help will be really appreciated. Thanks. – sciFi Feb 21 '13 at 12:30
  • This won't work at all. The method expression is interpreted as a value expression. See the answer on OP's follow-up question. – BalusC Feb 21 '13 at 12:56
  • @BalusC I understand that your answer works well too, but I am telling you, for right or wrong, the Primefaces actionListener attribute on commandButton being passed a method from ui:param in this way works. I am looking at my working code right now on Primefaces 3.2 and this code works for me, just on Primefaces CommandButton actionListener but it works. Try it for yourself and see. – maple_shaft Feb 21 '13 at 13:07
  • It'll probably be the EL 2.2 `()` on the method name. Does it work for you without them? And on different servers? – BalusC Feb 21 '13 at 13:09
  • @BalusC I just tested and it does not work without the EL 2.2 () feature. – maple_shaft Feb 21 '13 at 13:14
  • @BalusC Thank you for clarifying this, I learned something new today! :) – maple_shaft Feb 21 '13 at 13:19