selectManyMenu复合内部的选择值

时间:2013-09-04 14:59:56

标签: jsf primefaces attributes composite-component selectmanymenu

我创建了一个包含PrimeFaces selectManyMenu的复合材料。我试图将绑定的选择值传递给复合,但它失败了。

复合代码:

<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>

查看代码:

<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>

查看bean代码:

public class RecommendViewBean {


    private List<UserType> users = new ArrayList<UserType>();
    private List<String> selectedUsers = new ArrayList<String>();

    //setters and getters...
}

在上面的代码中,值selectedUsers是有问题的值。我传递了view / backing bean的List值,该值包含selectManyMenu的{​​{1}}属性的选择。这在复合体之外或者像我这样传递视图bean时效果很好......

value

...

<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> 的{​​{1}}属性的相应绑定值传递给复合?

非常感谢。如果我需要解释更多,请告诉我。

0 个答案:

没有答案