Jsf 使用动态添加的新行更新primefaces数据表
当我单击按钮NewJsf 使用动态添加的新行更新primefaces数据表,jsf,primefaces,datatable,Jsf,Primefaces,Datatable,当我单击按钮New时,仅在第一次单击时,一个新行就会添加到我的数据表中,页面就会刷新。除第一个集团外,有几个集团没有刷新数据表。因此,为了查看新添加的行,我使用F5键刷新页面。当然,我的update=“datatablesaiepiece”不起作用,或者只在第一次单击时起作用 这是我的主页home.xhtml: <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD X
时,仅在第一次单击时,一个新行就会添加到我的数据表中,页面就会刷新。除第一个集团外,有几个集团没有刷新数据表。因此,为了查看新添加的行,我使用F5键刷新页面。当然,我的update=“datatablesaiepiece”
不起作用,或者只在第一次单击时起作用
这是我的主页home.xhtml:
<?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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<script type="text/javascript">
function addRowOnComplete() {
jQuery('#supercoolnewrow').trigger('click');
}
</script>
<ui:composition template="/resources/template/all.xhtml">
<ui:define name="titre">Saisie</ui:define>
<ui:define name="content">
<p:tabView id="ViewPlan">
<p:tab id="tab2" title="Saisie 1">
<h:outputScript library="js" name="frenchLocale.js" />
<h:form id="formPiece">
<p:panel id="panelSaisie" header="Saisir" style="color: brown;font-size: 15px">
<h:panelGrid columns="3" >
<p:outputLabel for="description" value="Description:" ></p:outputLabel>
<p:inputText id="description" value="#{ecritureCtrl.description}" required="true" label="Description" maxlength="100" size="75">
<f:validateLength maximum="100" />
</p:inputText>
<p:message for="description" />
<p:outputLabel for="date" value="Date:" ></p:outputLabel>
<p:calendar locale="fr" id="date" required="true" label="Date" value="#{ecritureCtrl.date}" />
<p:message for="date" />
<p:outputLabel for="code" value="Code Avant" ></p:outputLabel>
<p:inputText id="code" value="#{ecritureCtrl.code}" required="true" >
</p:inputText>
<p:message for="code" />
</h:panelGrid>
<br/>
<p:dataTable var="line" value="#{ecritureCtrl.lignes}" id="dataTableSaisiePiece" >
<p:column headerText="First Name" style="width:150px">
<p:inputText value="#{line.intituleCompte}" style="width:100%"/>
</p:column>
<p:column headerText="Last Name" style="width:150px">
<p:inputText value="#{line.code}" style="width:100%"/>
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton actionListener="#{ecritureCtrl.newLine}" value="New" update="dataTableSaisiePiece" oncomplete="addRowOnComplete()" ajax="true"/>
</h:form>
</p:tab>
<p:tab id="tab3" title="Saisie 2">
</p:tab>
</p:tabView>
</ui:define>
</ui:composition>
</html>
函数addRowOnComplete(){
jQuery(“#supercolnewrow”).trigger('click');
}
赛西
我的ManagedBean:
@ManagedBean (name = "ecritureCtrl")
@SessionScoped
public class EcritureCtrl {
private List<Avant> lignes = new ArrayList<Avant>();
Avant unUser;
private String description;
private Date date;
private String code;
public EcritureCtrl() {
lignes.add(new Avant());
}
public void newLine(ActionEvent actionEvent){
lignes.add(new Avant());
}
}
@ManagedBean(name=“ecrituretrl”)
@会议范围
公共类电子出版物{
private List lignes=new ArrayList();
先锋大学;
私有字符串描述;
私人日期;
私有字符串码;
公共秘书处(){
lignes.add(new Avant());
}
公共无效换行符(ActionEvent ActionEvent){
lignes.add(new Avant());
}
}
你能帮帮我吗?
提前谢谢。这似乎对我有用
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
@ManagedBean
@SessionScoped
public class EcritureCtrl implements Serializable {
private static final long serialVersionUID = 1L;
private String code;
private Date date;
private String description;
private List<Avant> lignes = new ArrayList<Avant>();
private Avant unUser;
public String getCode() {
return this.code;
}
public Date getDate() {
return this.date;
}
public String getDescription() {
return this.description;
}
public List<Avant> getLignes() {
return this.lignes;
}
public Avant getUnUser() {
return this.unUser;
}
@PostConstruct
private void init(){
this.lignes.add(new Avant());
}
public void newLine(ActionEvent actionEvent) {
this.lignes.add(new Avant());
}
public void setCode(String code) {
this.code = code;
}
public void setDate(Date date) {
this.date = date;
}
public void setDescription(String description) {
this.description = description;
}
public void setLignes(List<Avant> lignes) {
this.lignes = lignes;
}
public void setUnUser(Avant unUser) {
this.unUser = unUser;
}
}
import java.io.Serializable;
导入java.util.ArrayList;
导入java.util.Date;
导入java.util.List;
导入javax.annotation.PostConstruct;
导入javax.faces.bean.ManagedBean;
导入javax.faces.bean.SessionScoped;
导入javax.faces.event.ActionEvent;
@ManagedBean
@会议范围
公共类ecrituretrl实现可序列化{
私有静态最终长serialVersionUID=1L;
私有字符串码;
私人日期;
私有字符串描述;
private List lignes=new ArrayList();
私人先锋大学;
公共字符串getCode(){
返回此.code;
}
公共日期getDate(){
返回此日期;
}
公共字符串getDescription(){
返回此.description;
}
公共列表getLignes(){
返回此。对齐;
}
公共先锋大学(){
返回这个.unUser;
}
@施工后
私有void init(){
this.lignes.add(new Avant());
}
公共无效换行符(ActionEvent ActionEvent){
this.lignes.add(new Avant());
}
公共无效设置码(字符串码){
this.code=代码;
}
公共作废设置日期(日期){
this.date=日期;
}
公共void集合描述(字符串描述){
this.description=描述;
}
公共无效设置对齐(列表对齐){
this.lignes=lignes;
}
公共无效设置用户(先锋用户){
this.unUser=unUser;
}
}
及
很抱歉
函数addRowOnComplete(){
警惕();
}
avant equals和hashcode方法如何?avant有转换器吗?@Leo我没有equals和hashcode方法。两种转换器我都不用。我应该考虑使用VIEW,而不是tooPerfect Leo。这正是我想要的。我删除了不有用的Javascript函数addrowncomplete()
。我不理解你的评论:>考虑使用VIEW,而你也能解释吗?有时候,会话范围可能太宽了。使用会话作用域的页面将在整个用户会话期间保留,如果该用户浏览您的应用程序,它将在会话中保留越来越多的数据。如果由于内存限制,您打算同时为多个用户提供服务,这可能是一个问题。这就是为什么,对于只需要将交互上下文限制在同一页面上的页面,您可以使用视图范围,该范围将一直存在到您离开该页面为止。感谢您提供此重要信息。事实上,我是jsf开发的新手,我承认我需要一本好书来掌握这项技术的基础知识
<!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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Sorry</title>
</h:head>
<h:body>
<script type="text/javascript">
function addRowOnComplete() {
alert();
}
</script>
<h:form id="formPiece">
<p:messages id="messages" showDetail="true" autoUpdate="true"
closable="true" />
<p:tabView id="ViewPlan">
<p:tab id="tab2" title="Saisie 1">
<p:panel id="panelSaisie" header="Saisir"
style="color: brown;font-size: 15px">
<h:panelGrid columns="3">
<p:outputLabel for="description" value="Description:"></p:outputLabel>
<p:inputText id="description" value="#{ecritureCtrl.description}"
required="true" label="Description" maxlength="100" size="75">
<f:validateLength maximum="100" />
</p:inputText>
<p:message for="description" />
<p:outputLabel for="date" value="Date:"></p:outputLabel>
<p:calendar locale="fr" id="date" required="true" label="Date"
value="#{ecritureCtrl.date}" />
<p:message for="date" />
<p:outputLabel for="code" value="Code Avant"></p:outputLabel>
<p:inputText id="code" value="#{ecritureCtrl.code}"
required="true">
</p:inputText>
<p:message for="code" />
</h:panelGrid>
<br />
<p:dataTable var="line" value="#{ecritureCtrl.lignes}"
id="dataTableSaisiePiece">
<p:column headerText="First Name" style="width:150px">
<p:inputText value="#{line.intituleCompte}" style="width:100%" />
</p:column>
<p:column headerText="Last Name" style="width:150px">
<p:inputText value="#{line.code}" style="width:100%" />
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton actionListener="#{ecritureCtrl.newLine}"
value="New" update="dataTableSaisiePiece" oncomplete="addRowOnComplete()"
ajax="true" />
</p:tab>
<p:tab id="tab3" title="Saisie 2">
</p:tab>
</p:tabView>
</h:form>
</h:body>
</html>