p:selectManyMenu ajax Select Event

UI Components for JSF
Post Reply
umairamin
Posts: 6
Joined: 05 Jan 2017, 14:25

29 Jan 2017, 19:14

I have been trying to capture click/select event when user selects values from ManyMenu. i have done it with oneMenu.
is there any listener which gets invoked when user selects value/values from select manymeny.

Code: Select all

	<p:selectManyMenu id="basic"
			value="#{selectOneMenuView.selectedOptions}">
			<f:selectItems value="#{selectOneMenuView.divisionsAL}" var="v"
				itemValue="#{v.getDivision()}" itemLabel="#{v.getDivision()}" />
			<p:ajax event="select" update="basic"
				listener="#{selectOneMenuView.onNodeSelect}" />
		</p:selectManyMenu>

Code: Select all

	public void onNodeSelect(NodeSelectEvent event) {
		System.out.println("inside select Event");
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected", event.getTreeNode().toString());
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
i tried this but onNodeSelect didnot invoked.

i also tried

Code: Select all

<p:selectManyMenu value="#{bean.selectedSectors>
    <f:selectItems value="#{bean.availableSectors}"/>    
    <p:ajax listener="#{bean.selectedSectorsChanged}" />
</p:selectManyMenu>
where

Code: Select all

public void selectedSectorsChanged() {
    System.out.println("Selected sectors are: " + selectedSectors); // Look, JSF has already set it.
    // ...
}
and couple of other examples as well.
but couldn't get desired results.

orwtech@gmail.com
Posts: 3
Joined: 29 Nov 2013, 12:07

01 Mar 2017, 17:52

From the documentation you have onclick and onchange and on ondblclick

Try this:

Code: Select all

<p:ajax event="click" update="basic" listener="#{selectOneMenuView.onNodeSelect}" />
Maybe your listener signature is wrong?

Replace

Code: Select all

NodeSelectEvent
with

Code: Select all

AjaxBehaviorEvent
or

Code: Select all

ActionEvent

bsanders1979
Posts: 69
Joined: 02 Jun 2013, 18:37

22 May 2020, 19:52

Sorry I couldn't answer this sooner, but I just ran into the same problem and wanted to share what I did and it's surprisingly easy.

Code: Select all

<p:selectManyMenu
    value="#{viewModel.selectedValues}"
    converter="#{valueConverter}"
    showCheckbox="true"
>
    <p:ajax
        process="@this"
        listener="#{viewModel.selectedValuesChanged}"
    />
    
    <f:selectItems
        value="#{viewModel.values}"
        var="value"
        itemValue="#{value}"
        itemLabel="#{value.name}"
    />
</p:selectManyMenu>

@Setter
private List<Value> oldSelectedValues, selectedValues;

public List<Value> getSelectedValues() {
    if (selectedValues == null)
        selectedValues = oldSelectedValues = new ArrayList<>();
    
    return selectedValues;
}

public void selectedValuesChanged() {
    List<Value>
        added = getSelectedValues().stream().filter(not(oldSelectedValues::contains)).collect(toList()),
        removed = oldSelectedValues.stream().filter(not(getSelectedValues()::contains)).collect(toList());

    //Use added/removed to implement desired logic
    
    oldSelectedValues = getSelectedValues();
}

public class Predicates {
    public static <T> Predicate<T> not(Predicate<T> predicate) {
        return predicate.negate();
    }
}

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests