PrimeFaces PickList组件,如何将所有目标值都获取到一个InputText组件?

时间:2013-01-20 15:42:40

标签: jsf jsf-2 primefaces

我使用一个inputText和一个commandButton组件创建了xhtml页面。当我点击按钮时,overlayPanelpickList以及列表下的一个commandButton一起显示。我想获取所有目标值并将其放入inputText(此组件必须只有一个)。你能帮我怎么做吗?

以下是我现在写的xhtml代码:

<h:panelGrid id="displayPlayers" columns="3">
        <ui:repeat value="#{pickListBean.players.target}" var="player"> 
            <p:inputText id="input2" value="#{player.name}" />
        </ui:repeat> 
        <p:commandButton id="overPanBtn2" value="overPanBtn2" type="button" />
    </h:panelGrid>

    <p:overlayPanel id="chartPanel2" for="overPanBtn2" hideEffect="fade">
        <p:pickList id="pickList4" value="#{pickListBean.players}" var="player" itemLabel="#{player}" itemValue="#{player}" converter="playerConverter">
            <p:column style="width:75%;">  
                #{player.name}  
            </p:column>
            <p:column style="width:75%;">  
                #{player.number}  
            </p:column>
        </p:pickList>
        <p:commandButton id="playerSubmit4" value="Ok" update="displayPlayers" style="margin-top:5px" />
    </p:overlayPanel>

我将不胜感激。

1 个答案:

答案 0 :(得分:3)

在你的情况下应该是这样的,你只需要关注the showcase example

<强> XHTML

<p:pickList id="pickList4" value="#{pickListBean.players}" var="player" itemLabel="#{player}" itemValue="#{player}" converter="playerConverter">
    <p:ajax event="transfer" listener="#{pickListBean.onTransfer}" update="msg" />
    <p:column style="width:75%;">  
            #{player.name}  
    </p:column>
    <p:column style="width:75%;">  
            #{player.number}  
    </p:column>
</p:pickList>

BACKING BEAN

String selectedPlayerNames;

//GETTER

public void onTransfer(TransferEvent event) {
    selectedPlayerNames = "";
    for (Player p : players.getTarget()){
        selectedPlayerNames += p.getName() + " ";
        }
}

只需在传输发生时调用该事件,并将目标值保存到String中。然后将此String属性绑定到p:inputText