Jsf primefaces选项卡视图上的tabChange事件不';t在ManagedBean中设置值
我在使用PrimeFaces5.0和JSF2.2.5时遇到了一个问题。使用Jsf primefaces选项卡视图上的tabChange事件不';t在ManagedBean中设置值,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,我在使用PrimeFaces5.0和JSF2.2.5时遇到了一个问题。使用 p:tabView两个选项卡共享同一个ManagedBean和同一个对象事件tabChange未按预期工作。当用户更改选项卡时,我希望执行与单击按钮相同的验证,但事件不会刷新bean值,而是发布值。我能够用这个简单的例子重现这个问题。 xhtml代码: <h:body> <div class="well"> <h:form id="testeForm">
p:tabView
两个选项卡共享同一个ManagedBean和同一个对象事件tabChange
未按预期工作。当用户更改选项卡时,我希望执行与单击按钮相同的验证,但事件不会刷新bean值,而是发布值。我能够用这个简单的例子重现这个问题。
xhtml代码:
<h:body>
<div class="well">
<h:form id="testeForm">
<p:tabView id="tView">
<p:ajax event="tabChange"
process="@this"
update="@form"
listener="#{testeBean.onTabChange}" />
<p:tab id="tab1" title="tab1">
<p:inputText id="teste1"
value="#{testeBean.evento.nome}" />
<p:commandButton id="savetab1"
process="tab1"
update="@form"
actionListener="#{testeBean.saveTab1}"
value="salvarTab1">
</p:commandButton>
</p:tab>
<p:tab id="tab2" title="tab2">
<p:inputText id="teste2"
value="#{testeBean.evento.descricao}" />
<p:commandButton id="savetab2"
process="tab2"
update="@form"
actionListener="#{testeBean.saveTab2}"
value="salvarTab2">
</p:commandButton>
</p:tab>
</p:tabView>
</h:form>
</div>
</h:body>
}
正在过帐的值:
我尝试了process=“@this”process=“@form”process=“@all”immediate=“true”
,但没有成功。我是不是遗漏了什么?
提前谢谢
重要更新:
在花了一些时间调试primefaces代码之后,在类org.primefaces.component.api.UITabPanel
中,我意识到primefaces只在其process()方法中处理子组件,如果它不是ajax请求的源:
if(isRequestSource(context)) {
return;
}
因此,我删除了这段代码并重新编译primefaces,现在它运行良好。我会把这个问题公诸于众,以防有比我更有经验的人找到更好的解决办法。试试这个
xhtml
在6.0之后
<p:ajax event="*" listener="*" skipChildren="false">
skipChildren=“false”
帮助,并在侦听器调用函数之前设置托管bean的值。再次感谢您的回答。我明白你的意思,但是想象一个场景,你有多个选项卡,如果用户当前在tab3中,然后用户单击tab1,那么我必须验证tab3上的对象字段,如果可以,请转到tab1。这就是为什么我需要tabChange事件,我需要知道源选项卡和下一个选项卡。还有其他提示吗?
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<f:facet name="first">
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8" />
<meta name="viewport"
content="user-scalable=no,
width=device-width,
initial-scale=1.0,
maximum-scale=1.0"/>
</f:facet>
<title>page2</title>
</h:head>
<h:body>
<h:form id="testeForm">
<p:remoteCommand name="rc"
process="@this,tView:teste1,tView:teste2"
update="tView:teste1,tView:teste2"
actionListener="#{testeBean.execute}" />
<p:tabView id="tView" onTabChange="rc()">
<p:tab id="tab1" title="tab1">
<p:inputText id="teste1"
value="#{testeBean.evento.nome}" />
<p:commandButton id="savetab1"
process="tab1"
update="@form"
actionListener="#{testeBean.saveTab1}"
value="salvarTab1">
</p:commandButton>
</p:tab>
<p:tab id="tab2" title="tab2">
<p:inputText id="teste2"
value="#{testeBean.evento.descricao}" />
<p:commandButton id="savetab2"
process="tab2"
update="@form"
actionListener="#{testeBean.saveTab2}"
value="salvarTab2">
</p:commandButton>
</p:tab>
</p:tabView>
</h:form>
</h:body>
</html>
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
/**
*
* @author Wittakarn
*/
@ViewScoped
@ManagedBean(name = "testeBean")
public class TesteBean implements Serializable{
private Evento evento;
public TesteBean(){
evento = new Evento();
}
@PostConstruct
public void init() {
}
public void saveTab1() {
System.out.println(evento.getNome());
System.out.println(evento.getDescricao());
}
public void saveTab2() {
System.out.println(evento.getNome());
System.out.println(evento.getDescricao());
}
public void execute() {
System.out.println(evento.getNome());
System.out.println(evento.getDescricao());
}
public Evento getEvento() {
return evento;
}
public void setEvento(Evento evento) {
this.evento = evento;
}
}
<p:ajax event="*" listener="*" skipChildren="false">