Rajath
Rajath

Reputation: 2188

<p:pickList> not clearing after RemoveAll button

I am encountering a strange problem with <p:pickList>. When I open a dialog having this pickList and clear all items from target list using the RemoveAll button and submit using <p:commandButton> the old items in the target list still appear. I have given the attribute required=true for the pickList. The strange behaviour is when I submit it, a tooltip appears saying that the field is mandatory.

So if the items are clearing and required attribute is working fine, why are the old items reappearing? What is the solution for this?

<p:pickList id="selectedId" value="#{someDialog.selectedItem}"
            var="item" itemValue="#{item}" required="true"
            converter="pickListConverter" requiredMessage="#{msg.required_message}" 
            styleClass="#{component.valid ? '': 'ui-state-error'}">
        </p:pickList>

EDIT: Backing Bean - I am posting only the relevant method. SomeDialog.java

 private DualListModel<Item> selectedItem = new DualListModel<Item>();
 //Its getters and setters

public final void afterSave(final ParamObject pObject) {
        pObject.getRelevantData().clear();
        pObject.getRelevantData().addAll(selectedItem.getTarget());
    }

ParamObject .java

private List<Item> relevantData = new ArrayList<Item>();
//Setters and Getters

Upvotes: 0

Views: 1090

Answers (1)

Darka
Darka

Reputation: 2768

As @Xtreme Biker mentioned its in your backing bean.

When first time you submit list, you set it in backing bean. Second time you open dialog, it is already there. Even if you press RemoveAll, it removes only in your browser, it doesn't work with backing bean. And your submit will not work, because you have required=true.

So you can choose one of this options:

  1. remove required=true and after every submit you will need press RemoveAll and submit again empty list (its not an option).
  2. after doing all required tasks in backing bean, clear someDialog.selectedItem value, update and close dialog.
  3. every time you open dialog clear someDialog.selectedItem value in backing bean.

I hope it will help as I am new in here too.

Upvotes: 2

Related Questions