user1494328
user1494328

Reputation: 681

PrimeFaces PickList component, how to get all target values to one InputText component?

I created xhtml page with one inputText and one commandButton component. When I clicked on button is displaying overlayPanel with pickList and one commandButton under list. I want to get all target values and put it into inputText (this component must be only one). Can you help me how to do it?

Below is xhtml code that I wrote for now:

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

I will be grateful for help.

Upvotes: 0

Views: 7409

Answers (1)

Aritz
Aritz

Reputation: 31649

In your case it should be something like that, you only have to follow 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() + " ";
        }
}

Just call the event when transfer happens, and save the targeted values into the String. Then bind this String property to a p:inputText.

Upvotes: 3

Related Questions