更新我的项目以使用Primefaces 5.2,从5.0开始,我的所有更新都显示一个旧请求的数据。如果我单击一次commandLink两次,第一次单击在客户端没有执行任何操作,服务器执行action / actionListener,并且请求带有先前的数据而没有更改,第二次单击更新时带有第一个请求的结果。总是服务器完成工作,但JSF没有。
使用PrimeFaces 5.0,一切正常。
这是我的pom.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.foo.bar</groupId>
<artifactId>foo</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>Foo</name>
<description>Project Foo</description>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>jboss-3rd-party-releases</id>
<url>https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- JBoss dependency versions -->
<version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>
<version.jboss.bom>8.1.0.Final</version.jboss.bom>
<!-- other plugin versions -->
<version.compiler.plugin>3.1</version.compiler.plugin>
<version.surefire.plugin>2.16</version.surefire.plugin>
<version.war.plugin>2.1.1</version.war.plugin>
<!-- maven-compiler-plugin -->
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>jboss-javaee-7.0-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- PRIMEFACES JSF -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.2</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces-mobile</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>2.1.0</version>
</dependency>
<!-- OMNIFACES JSF -->
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>2.0</version>
</dependency>
<!-- HIBERNATE -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
<exclusions>
<exclusion>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
</dependency>
<!-- LOG4j -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.1</version>
</dependency>
<!-- CDI -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- FILE UPLOAD -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>
<!-- EL EXPRESSION -->
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
</dependency>
<!-- LIQUIBASE -->
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-cdi</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.15</version>
</dependency>
<!-- WILDFLY 8.1.0 STUFS -->
...
</dependencies>
<build>
...
</build>
<profiles>
...
</profiles>
</project>
这是我的jsf代码的一个例子:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" template="/sistema/template.xhtml">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<ui:define name="center">
<div class="row">
<div class="col-md-12">
<div class="block-web block-color primary">
<h:panelGroup layout="block" styleClass="header">
<h:panelGroup layout="block" styleClass="actions">
<a class="minimize" href="#"><i class="fa fa-chevron-down"></i></a>
</h:panelGroup>
<h3>
<i class="fa fa-search"></i> Gerenciamento de Roles
</h3>
</h:panelGroup>
<div class="porlets-content">
<h:form id="cadastro">
<div class="align-center m-b-10 btn-toolbar">
<p:commandLink oncomplete="showModal('#formCadastro')" update=":formCad" styleClass="btn btn-labeled btn-primary">
<f:setPropertyActionListener value="" target="#{roleController.selected}" />
<span class="btn-label"><i class="fa fa-plus"></i></span>
<h:outputText value=" Adicionar" />
</p:commandLink>
<p:commandLink oncomplete="showModal('#form-del')" styleClass="btn btn-labeled btn-danger">
<span class="btn-label"><i class="fa fa-trash-o"></i></span>
<h:outputText value=" Remover" />
</p:commandLink>
<p:commandLink onclick="showModal('#atualizar')" oncomplete="removeModal('#atualizar');" styleClass="btn btn-labeled btn-default" actionListener="#{roleController.update()}">
<span class="btn-label"><i class="fa fa-refresh"></i></span>
<h:outputText value=" Atualizar" />
</p:commandLink>
</div>
<p:dataTable id="tabela" resizableColumns="true" var="role" value="#{roleController.list}" selectionMode="single" sortMode="single" selection="#{roleController.selected}"
rowKey="#{role.id}" paginator="true" rows="20" rowsPerPageTemplate="10,20,50,100" paginatorPosition="top" emptyMessage="Nenhum registro encontrado"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
currentPageReportTemplate="{currentPage} de {totalPages} ({totalRecords})" filteredValue="#{roleController.filtered}" widgetVar="tabelaUsuario"
sortBy="#{role.descricao.toUpperCase()}">
<p:ajax event="rowDblselect" oncomplete="showModal('#formCadastro')" update=":formCad :cadastro" />
<p:column headerText="CÓDIGO" width="10%" sortBy="#{role.id}">
<h:outputText value="#{role.id}" />
</p:column>
<p:column headerText="NOME" width="90%" filterMatchMode="contains" filterBy="#{role.descricao}" sortBy="#{role.descricao.toUpperCase()}" filterStyleClass="width-100p">
<h:outputText value="#{role.descricao}" />
</p:column>
</p:dataTable>
</h:form>
</div>
</div>
</div>
</div>
<!-- pop-ups -->
<ui:include src="./cadRole.xhtml" />
</ui:define>
</ui:composition>
最终,控制器:
@ManagedBean
@ViewScoped
public class RoleController extends PesquisaController<Role> {
@Inject
private Role selected;
@EJB
private RoleService bean;
public RoleController() {
super(Role.class);
}
@PostConstruct
public void init() {
reList();
}
public Role getSelected() {
return this.selected;
}
public void setSelected(Role registro) {
if (registro == null)
this.selected = new Role();
else
this.selected = new Role(registro);
}
public void update() {
if (reList())
enviarMensagemSucesso("Dados atualizados");
}
private boolean reList() {
try {
this.list = this.bean.listarTodos();
this.filtered = new ArrayList<Role>(this.list);
} catch (DAOException e) {
enviarMensagemErro(e.getMessage());
return false;
}
return true;
}
public List<Role> getList() {
if (this.list == null) {
try {
this.list = this.bean.listarTodos();
} catch (DAOException e) {
enviarMensagemErro(e.getMessage());
}
}
return this.list;
}
public void setList(List<Role> list) {
this.list = list;
}
public void persist() {
try {
if (this.selected.getId() != 0) {
this.bean.alterar(this.selected);
enviarMensagemSucesso("Registro alterado com sucesso");
} else {
this.bean.adicionar(this.selected);
enviarMensagemSucesso("Registro adicionado com sucesso");
}
sucesso();
reList();
} catch (DAOException | ValidacaoException e) {
enviarMensagemErro(e.getMessage());
}
}
public void delete() {
try {
this.bean.excluir(this.selected);
reList();
enviarMensagemSucesso("Registro removido com sucesso!");
} catch (DAOException e) {
enviarMensagemErro(e.getMessage());
}
}
}
有一个相关的问题,但我没有使用ui:repeat或c:forEach tags:JSF updates view just on second request