I've created a composite that contains the PrimeFaces selectManyMenu
. I'm attempting to pass the bound selection value into the composite, but it fails.
Composite code:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:kf="http://java.sun.com/jsf/composite/kf"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<composite:interface>
<composite:attribute name="selectedUsers" required="true"/>
<composite:attribute name="users" required="true" type="java.util.List"/>
<composite:attribute name="recommendActionHandler" required="true" method-signature="void listener()"/>
<composite:attribute name="recommendButtonStyle"/>
<composite:clientBehavior name="click" event="change" targets="recommendUsers" default="true"/>
</composite:interface>
<composite:implementation>
<div id="#{cc.clientId}">
<h:form id="recommendForm" prependId="false">
<p:growl id="recommendGrowl" showDetail="true"/>
<p:commandButton id="recommendBtn" value="Recommend" type="button" update=":recommendForm,recommendUsers" style="#{cc.attrs.recommendButtonStyle}"/>
<p:overlayPanel id="recommendPanel" for="recommendBtn" widgetVar="recommendPanel"
dynamic="true"
hideEffect="fade"
showCloseIcon="true">
<p:selectManyMenu id="recommendUsers" value="#{cc.attrs.selectedUsers}" showCheckbox="true"
style="width:150px;height:200px">
<f:selectItems value="#{cc.attrs.users}" var="user" itemLabel="#{user.login}" itemValue="#{user.login}"/>
</p:selectManyMenu>
<p:commandButton id="submitRecommendations"
value="Send"
update="recommendUsers recommendGrowl"
actionListener="#{cc.attrs.recommendActionHandler}"
process="recommendUsers @this"
/>
</p:overlayPanel>
</h:form>
</div>
</composite:implementation>
</html>
View code:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:kf="http://java.sun.com/jsf/composite/kf"
>
<ui:composition template="/WEB-INF/facelet_templates/default.xhtml">
<ui:define name="content">
<kf:recommend id="recommendIt"
selectedUsers="#{recommendViewBean.selectedUsers}"
users="#{recommendViewBean.users}"
recommendActionHandler="#{recommendController.saveRecommendations()}"
/>
</ui:define>
</ui:composition>
</html>
View bean code:
public class RecommendViewBean {
private List<UserType> users = new ArrayList<UserType>();
private List<String> selectedUsers = new ArrayList<String>();
//setters and getters...
}
In the code above, the value selectedUsers
is the value in question. I pass the view/backing bean's List value that holds the selections for the selectManyMenu
's value
attribute. This works great when outside of a composite or if I pass the view bean like this...
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:kf="http://java.sun.com/jsf/composite/kf"
>
<ui:composition template="/WEB-INF/facelet_templates/default.xhtml">
<ui:define name="content">
<kf:recommend id="recommendIt"
selectedUsers="#{recommendViewBean}"
users="#{recommendViewBean.users}"
recommendActionHandler="#{recommendController.saveRecommendations()}"
/>
</ui:define>
</ui:composition>
</html>
...
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:kf="http://java.sun.com/jsf/composite/kf"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<composite:interface>
<composite:attribute name="selectedUsers" required="true"/>
<composite:attribute name="users" required="true" type="java.util.List"/>
<composite:attribute name="recommendActionHandler" required="true" method-signature="void listener()"/>
<composite:attribute name="recommendButtonStyle"/>
<composite:clientBehavior name="click" event="change" targets="recommendUsers" default="true"/>
</composite:interface>
<composite:implementation>
<div id="#{cc.clientId}">
<h:form id="recommendForm" prependId="false">
<p:growl id="recommendGrowl" showDetail="true"/>
<p:commandButton id="recommendBtn" value="Recommend" type="button" update=":recommendForm,recommendUsers" style="#{cc.attrs.recommendButtonStyle}"/>
<p:overlayPanel id="recommendPanel" for="recommendBtn" widgetVar="recommendPanel"
dynamic="true"
hideEffect="fade"
showCloseIcon="true">
<p:selectManyMenu id="recommendUsers" value="#{cc.attrs.selectedUsers.selectedUsers}" showCheckbox="true"
style="width:150px;height:200px">
<f:selectItems value="#{cc.attrs.users}" var="user" itemLabel="#{user.login}" itemValue="#{user.login}"/>
</p:selectManyMenu>
<p:commandButton id="submitRecommendations"
value="Send"
update="recommendUsers recommendGrowl"
actionListener="#{cc.attrs.recommendActionHandler}"
process="recommendUsers @this"
/>
</p:overlayPanel>
</h:form>
</div>
</composite:implementation>
</html>
So, my question is, how would I pass the appropriate bound value for selectManyMenu
's value
attribute into the composite?
Thanks so much. Let me know if I need to explain more.