0

我创建了一个包含 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是有问题的值。selectManyMenu我传递了包含'value属性选择的视图/支持 bean 的 List 值。这在复合之外或者我像这样传递视图 bean 时效果很好......

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

所以,我的问题是,我如何将selectManyMenu'value属性的适当绑定值传递给组合?

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

4

0 回答 0