0

I have one primefaces autocomplete with dropdown and one reset button.

After selecting one value from the dropdown list if I am press the reset button, autocomplete dropdown becomes blank(i.e it is getting reseted). But the problem is after resetting the autocomplete I am not able to get the values in the autocomplete drop down list.

Here goes my code

index.xhtml

<p:autocomplete id="name" binding="#{myBean.name}" value="#{myBean.personName}" completeMethod="#{myBean.retrieveNames}" dropdown="true"/>

<p:commandButton value="Reset" action="#{myBean.reset}"  immediate="true" update="@form">

MyBean.java

private String personName;
private UIInput name;


public void resetUIValue(UIInput uiObj) {  
    uiObj.setSubmittedValue(null);
    uiObj.setLocalValueSet(false);
    uiObj.setValid(true);
    uiObj.setValue("");
}
public void reset() {
        this.clearFormValues();
        this.resetUIValue(this.name);

}
public void clearFormValues()
{
   this.name="";
}
public List<String> retrieveNames(String query)
{
    List<String> result=new ArrayList<String>();
    for(int i=0;i<10;i++)
    {
        result.add(query+i);
    }
    return result;
}
Kush Sahu
  • 399
  • 1
  • 13
  • 33
  • look maybe this answer will help more http://stackoverflow.com/a/8391552/1692632 – Darka Sep 17 '13 at 18:32
  • @Darka Thanks for your response. But it didnt provide me solution to my problem. I have also tried by not resetting my autocomplete. But after reset when I update the panel which include this autocomplete, I do not receive autocomplete dropdown. Here with reset functionality my concern is more for retrieving my dropdown list in autocomplete which is some how lost after updation of the panel. – Kush Sahu Sep 17 '13 at 19:55

1 Answers1

1

I pasted your code and got 3 errors:

1) this.name=""; is not String i changed to personName

2)p:commandButton should end with />

3)at least, when I tried access page, I got error, that it can't find p:autocomplete, so I changed it to p:autocomplete p:autoComplete

After that when I press reset autoComplete still works.

Here is full code:

 <h:form id="test" prependId="false">

 <p:autoComplete id="name" binding="#{beanT.name}" value="#{beanT.personName}" completeMethod="#{beanT.retrieveNames}" dropdown="true"/>
 <p:commandButton value="Reset" action="#{beanT.reset}"  immediate="true" update="@form" />

 </h:form>


 @ManagedBean(name="beanT")
 @ViewScoped
 public class TestBean {
    private String personName;
    private UIInput name;


    public UIInput getName() {
        return name;
    }
    public void setName(UIInput name) {
        this.name = name;
    }
    public void resetUIValue(UIInput uiObj) {  
        uiObj.setSubmittedValue(null);
        uiObj.setLocalValueSet(false);
        uiObj.setValid(true);
        uiObj.setValue("");
    }
    public void reset() {
            this.clearFormValues();
            this.resetUIValue(this.name);

    }
    public void clearFormValues()
    {
       this.setPersonName("");
    }
    public List<String> retrieveNames(String query)
    {
        List<String> result=new ArrayList<String>();
        for(int i=0;i<10;i++)
        {
            result.add(query+i);
        }
        return result;
    }
    public String getPersonName() {
        return personName;
    }
    public void setPersonName(String personName) {
        this.personName = personName;
    } 
 }
Darka
  • 2,762
  • 1
  • 14
  • 31
  • hi that all was typing mistakes these are present only in this que. Not in actual code. Sorry for those mistakes. But actual code is still not working – Kush Sahu Sep 26 '13 at 09:58