jsf 2 - Primefaces 3.3/3.4 tabview: ajax update on tabChange -
using following code, content of 2 tabs cleared on tabchange event instead of being updated:
<h:form id="form"> <p:tabview id="tabview"> <p:ajax event="tabchange" listener="#{testbean.onchange}" update="@form"/> <p:tab title="tab 1"> <h:outputtext value="lorem ipsum dolor sit amet." id="ht1"/> </p:tab> <p:tab title="tab 2"> <h:outputtext value="donec et mi et arcu commodo hendrerit." id="ht2"/> </p:tab> </p:tabview> </h:form>
the onchange method empty method test code.
i'm missing here can't find what. doing wrong?
edit
i'm using viewscoped bean.
i've tried update="@form"
, update=":form"
, update=":form:tabview"
, same problem occurs.
if use update="ht1, ht2"
, fine but in onchange method, select programmatically tab want active (there treatment in real code validates data: if validation fails, i'd stay on tab 1, if it's ok, go tab 2). achieve that, guess must update whole tabview component , not tabs' content. maybe i'm wrong?
full code
i made few changes, here's updated code still doesn't work.
managed bean:
import java.io.serializable; import javax.faces.bean.managedbean; import javax.faces.bean.viewscoped; import org.primefaces.event.tabchangeevent; @managedbean @viewscoped public class testbean implements serializable { private int idx; private string s1 = "test 1"; private string s2 = "test 2"; public testbean() { system.out.println("testbean.init"); } public void onchange(tabchangeevent e){ s1 = "test test"; s2 = "test test"; } public int getidx() { return idx; } public void setidx(int idx) { this.idx = idx; } public string gets1() { return s1; } public void sets1(string s1) { this.s1 = s1; } public string gets2() { return s2; } public void sets2(string s2) { this.s2 = s2; } }
facelet:
<?xml version='1.0' encoding='utf-8' ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"> <h:head> <title>facelet title</title> </h:head> <h:body> <h:form id="form"> <p:tabview id="tabview" activeindex="#{testbean.idx}"> <p:ajax event="tabchange" listener="#{testbean.onchange}" update="@form"/> <p:tab title="tab 1"> <h:outputtext value="#{testbean.s1}" id="ht1"/> </p:tab> <p:tab title="tab 2"> <h:outputtext value="#{testbean.s2}" id="ht2"/> </p:tab> </p:tabview> <h:messages/> </h:form> </h:body> </html>
update
i changed primefaces jar 3.4 3.2 , magic, behaviour doesn't happen anymore. tried 3.3 , boom, error. i'm going ask on primefaces forum if known bug.
you should use activeindex
<p:tabview id="tabview" activeindex="#{testbean.tabindex}" >
and in onchange method, after validation set correct tabindex.
Comments
Post a Comment