Search code examples
jsfprimefacesjsf-2

JSF 2 - calling a listener with object parameter from composite component


I have the following question: I defined my own custom component this way:

<composite:interface componentType="myComponent">
   <composite:attribute name="listener" method-signature="void action(java.lang.Object)"/>
   ...
   more attributues
</composite:interface>

Now, in my view, i try to pass a listener with a specific cellphone object that was passed to the view via ui:param tag:

<ui:include src="page.xhtml" >
     <ui:param name="currentCellphone" value="#{cellphone}" />
</ui:include>

and then, in the page.xhtml view, i try to do:

<my:myComponent ... listener = "#{backbeanController.backbeanMethod(currentCellphone)}">

Now, if the backbeanmethod is expecting to get a cellphone object as a parameter, when it's gets to the function, the parameter is null. But!, if it's excepted to get string for example, and i send it a string instead of myCellphone object, is works just fine.

I can't pass the myCellphone parameter properly to the backbean. any ideas? Thank you very much.


Solution

  • You can't pass complex object as a parameter, you can just pass a string, say "Id" of the object. Then you have to reconstruct the object but you can use session map like in this example :

    Map<String, Object> sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
    sessionMap.put("controller", controller);
    

    and call it

    Map<String, Object> sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
    MyController controller = (MyController) sessionMap.get("controller");
    

    You can read the complete example in Primefaces forum alse see Other link

    Hope that helped you.