jsf - p:selectOneListbox ajax item selection changes scroll position -
there <p:selectonelistbox>
20 items. first 5 items can viewed in list , remaining can scrolled , selected. list ajaxified. when item numbers greater 5 selected (after scrolling it) scrollbar not remain @ place; moves top position. makes selected item (for example item 9) invisible. program uses ajax listener. app uses primefaces 5.0.
but, when ajax listener removed selected (item 9) visible , scroller not move top (remove p:ajax tag's listener attribute in below jsf page).
i know how make scrollbar not move when item selected while using ajax listener.
the jsf page:
<p:selectonelistbox id="list" scrollheight="100" value="#{bean.todo}"> <f:selectitems value="#{bean.data}" var="t" itemlabel="#{t.name}" itemvalue="#{t.name}"/> <p:ajax process="@this" update="@this msg" listener="#{bean.valuechanged}" /> </p:selectonelistbox> <br /><h:outputtext id="msg" value="#{bean.message}" />
the bean's code:
import javax.faces.bean.*; import java.io.serializable; import java.util.*; import javax.faces.event.ajaxbehaviorevent; import javax.faces.component.uioutput; @managedbean(name="bean") @sessionscoped public class todosbean implements serializable { private list<todo> data; private string todo; // selected item value private string msg; public todosbean() { loaddata(); if (data.size() == 0) { return; } todo t = data.get(0); string name = t.getname(); settodo(name); // select first item in list setmessage(name); } private void loaddata() { data = new arraylist<>(); data.add(new todo("1first", "1")); data.add(new todo("2second", "2")); data.add(new todo("3third", "3")); data.add(new todo("4fourth", "4")); data.add(new todo("5fifth", "5")); data.add(new todo("6sixth", "6")); data.add(new todo("7seventh", "7")); data.add(new todo("8eighth", "8")); } public list<todo> getdata() { return data; } public void setmessage(string msg) { this.msg = msg; } public string getmessage() { return msg; } public string gettodo() { return todo; } public void settodo(string t) { todo = t; } public void valuechanged(ajaxbehaviorevent e) { string name = (string) ((uioutput) e.getsource()).getvalue(); setmessage(name + " selected."); } }
public class todo { private string name; private string desc; public todo() {} public todo(string name, string desc) { this.name = name; this.desc = desc; } public string getname() { return name; } public void setname(string name) { this.name = name; } public string getdesc() { return desc; } public void setdesc(string desc) { this.desc = desc; } @override public string tostring() { return this.name; } }
remove update="@this
solve it. updating control move default state. might in newer version of pf default state improved , still @ correct position
Comments
Post a Comment