Passing a backing bean instance as parameter to composite component
-
21-12-2019 - |
Question
Is it possible to pass a backing bean instance as parameter to a composite component using JSF 2.2 and invoke methods from the bean instance?
Is there any examples? Thanks for helping.
La solution
I got it! And here is my solution:
Composite component:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface>
<cc:attribute name="backingBean" required="true" shortDescription="A backing bean to invoke polimorphic methods."/>
</cc:interface>
<cc:implementation>
<h:commandButton value="Foo" action="#{cc.attrs.backingBean.myPolimorphicMethod}"/>
</cc:implementation>
</html>
Using the composite component:
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:cc="http://xmlns.jcp.org/jsf/composite/components"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/templates/template.xhtml">
<ui:define name="content">
<h:form>
<cc:myCustomComponent backingBean="#{myBacking}"></cc:myCustomComponent>
</h:form>
</ui:define>
</ui:composition>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow