0

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>

我将不胜感激。

4

1 回答 1

3

在您的情况下,它应该是这样的,您只需要遵循展示示例

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>

支持豆

String selectedPlayerNames;

//GETTER

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

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

于 2013-01-21T21:34:43.123 回答