2013-10-02 67 views
1

我使用primefaces的dataTable获取奇怪的行为。 当我向列表中添加新行并刷新数据表时,标题被复制;因此,添加第一行后,会显示标题2次,第二行4次之后,依此类推。 我试图删除过滤选项,但我仍然得到相同的行为。 有人遇到同样的问题? 我在Tomcat 7上使用Primefaces 4.0。在添加新行时重复添加Primefaces数据表头

在此先感谢任何能帮助我的人,并对我的英语不好。

这里是一个展示行为的图像: http://i.imgur.com/tb57ahJ.png


这是我的代码:一个页面的index.xhtml包括包含数据表我movementList.xhtml页:

的index.html

<!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" 
    xmlns:c="http://java.sun.com/jstl/core"> 

<h:head> 
    <link href="/#{COREWEB_MODULE_URL}/css/jsf.css" rel="stylesheet" type="text/css"></link> 
</h:head> 

<ui:include src="/jsp/faces/common/varImages.xhtml"/> 

<h:body style="background-color:grey;"> 

<p:growl id="messages"/> 

<p:dock position="top" halign="center" > 
    <p:menuitem value="Home" icon="#{imgHome64}" url="index.xhtml"/> 
    <p:menuitem value="Movimenti" icon="#{imgNoteBook64}" url="/movement/list.xhtml"/> 
    <p:menuitem value="Mutuo" icon="#{imgEuro64}" url="/bankLoan/list.xhtml"/> 
    <p:menuitem value="Grafici" icon="#{imgChart64}" url="/graph/list.xhtml"/> 
    <p:menuitem value="Dizionario" icon="#{imgBook64}" url="/dictionary/list.xhtml"/> 
</p:dock> 

<p:stack icon="/images/stack/stack.png"> 
    <p:menuitem value="Home" icon="#{imgHome64}" url="index.xhtml"/> 
    <p:menuitem value="Movimenti" icon="#{imgNoteBook64}" url="/movement/list.xhtml"/> 
    <p:menuitem value="Mutuo" icon="#{imgEuro64}" url="/bankLoan/list.xhtml"/> 
    <p:menuitem value="Grafici" icon="#{imgChart64}" url="/graph/list.xhtml"/> 
    <p:menuitem value="Dizionario" icon="#{imgBook64}" url="/dictionary/list.xhtml"/> 
</p:stack> 

<div style="display:block;width:1300px;height:50px;"> 
    <div style="float:left;width:1120px;" id="menuTopDiv"> 

    </div> 
    <div style="float:left;width:180px;height:50px;" id="themeSwitcherDiv"> 
     <h:panelGrid columns="2" cellpadding="10"> 
      <p:themeSwitcher value="#{guestPreferences.theme}" style="width:165px" effect="fade" id="statefulSwitcher"> 
       <f:selectItem itemLabel="Choose Theme" itemValue="" /> 
       <f:selectItems value="#{themeSwitcherBean.themes}" /> 
       <p:ajax listener="#{themeSwitcherBean.saveTheme}" /> 
      </p:themeSwitcher> 
     </h:panelGrid> 
    </div> 
</div> 

<div style="display:block;width:1300px;height:220px;"> 
    <div id="menuTopLeftDiv" style="float:left;width:300px;height:220px;"> 
     <ui:include src="/jsp/faces/menu/menuLeft.xhtml"/> 
    </div> 
    <div id="latestIncomeDiv" style="float:left;width:490px;height:220px;margin-left:0.3em;"> 
     <ui:include src="/jsp/faces/latestIncomeWidget.xhtml"/> 
    </div> 
    <div id="latestOutcomeDiv" style="float:left;width:496px;height:220px;margin-left:0.3em;"> 
     <ui:include src="/jsp/faces/latestOutcomeWidget.xhtml"/> 
    </div> 
</div> 

<div style="float:left;display:block;width:1300px;"> 
    <ui:include src="/jsp/faces/movement/movementList.xhtml"/> 
</div> 

</h:body> 
</html> 

movementList.xhtml

<ui:composition 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:c="http://java.sun.com/jstl/core" 
    xmlns:p="http://primefaces.org/ui"> 

<h:form id="movementForm"> 
    <h:outputScript library="primefaces" name="jquery/jquery.js"/> 

<p:growl id="messages" showDetail="true"/> 

<p:accordionPanel id="movementAccordion"> 
    <p:tab title="Elenco Movimenti"> 

     <p:dataTable id="dataTable" var="movement" value="#{movementJsf.movementList}" widgetVar="movementTable" 
      emptyMessage="No movements found with given criteria" 
      paginator="true" rows="10" editable="true" stickyHeader="true" 
      paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
      rowsPerPageTemplate="5,10,15"> 

      <p:column style="padding:0.2em;width:2.5em;text-align:center;" filterBy="#{movement.direction.name}" 
       headerText="Dir" filterMatchMode="contains"> 
       <h:graphicImage url="#{movement.directionId == 3 ? imgArrowUpGreen16 : imgArrowDownRed16}"/> 
      </p:column> 

      <p:column style="padding:0.2em;" filterBy="#{movement.direction.name}" 
       headerText="Direzione" filterMatchMode="contains"> 
       <h:outputText value="#{movement.direction.name}"/> 
      </p:column> 

      <p:column style="padding:0.2em;" filterBy="#{movement.type.name}" 
       headerText="Movimento" filterMatchMode="contains"> 
       <h:outputText value="#{movement.type.name}"/> 
      </p:column> 

      <p:column style="padding:0.2em;width:6em;text-align:right;" headerText="Data"> 
       <h:outputText value="#{movement.operationDate}"> 
        <f:convertDateTime type="date" pattern="dd-MM-yyyy"/> 
       </h:outputText> 
      </p:column> 

      <p:column style="padding:0.2em;width:6em;text-align:right;" headerText="Ammontare"> 
       <h:outputText value="#{movement.amount}"> 
        <f:convertNumber type="currency" currencySymbol="€" locale="de-DE"/> 
       </h:outputText> 
      </p:column> 

      <p:column headerText="Azioni" style="padding:0.2em;width:6em;text-align:right;"> 
       <h:graphicImage url="#{imgPageEdit}" title="Modifica" alt="Modifica" id="movement_edit_#{movement.id}"/> 
       <h:graphicImage url="#{imgPageDelete}" title="Cancella" alt="Cancella" id="movement_remove_#{movement.id}"/> 
      </p:column> 

     </p:dataTable> 
    </p:tab> 
</p:accordionPanel> 

<p:commandButton id="modalDialogButton" value="Aggiungi movimento" onclick="PF('movementFormDialog').show();" type="button"/> 

<p:dialog id="modalDialog" header="Modal Dialog" widgetVar="movementFormDialog" modal="true" height="400" resizable="false" 
    showEffect="fade" hideEffect="fade"> 
    <p:ajax event="close" update="messages" immediate="true" global="false" 
     listener="#{movementJsf.addMovement}"/> 

    <h:panelGrid id="display" columns="2" cellpadding="4"> 
     <f:facet name="header"> 
      Aggiungi movimento 
     </f:facet> 

     <h:outputLabel for="type" value="Tipologia: *"/> 
     <p:autoComplete value="#{movementJsf.typeId}" id="movementType" completeMethod="#{facesService.movementTypeAutocomplete}" 
      var="type" itemLabel="#{type.name}" itemValue="#{type.id}" forceSelection="true"/> 

     <h:outputLabel for="amount" value="Ammontare *"/> 
     <h:inputText size="20" value="#{movementJsf.amount}"/> 

     <h:outputLabel for="operationDate" value="Data operazione: *"/> 
     <p:calendar value="#{movementJsf.operationDate}" id="operationDateCalendar" locale="it" showButtonPanel="true" navigator="true" effect="slideDown"/> 

     <h:outputLabel for="estimated" value="Stimato: *"/> 
     <p:selectOneMenu value="#{movementJsf.estimatedId}" effect="fade"> 
      <f:selectItem itemLabel="Seleziona" itemValue=""/> 
      <f:selectItems value="#{facesService.movementEstimatedList}" var="dictionary" itemLabel="#{dictionary.name}" itemValue="#{dictionary.id}"/> 
     </p:selectOneMenu> 

     <f:facet name="footer"> 
      <p:commandButton type="button" value="Save" icon="ui-icon-check" style="margin:0"/> 
     </f:facet> 
    </h:panelGrid> 

     <p:commandButton id="addFormButton" value="Aggiungi" action="#{movementJsf.addMovement}" 
      oncomplete="PF('movementFormDialog').hide();" update="movementForm:movementAccordion:dataTable"/> 
     <p:commandButton id="undoFormButton" value="Annulla" onclick="PF('movementFormDialog').hide();" type="button"/> 
</p:dialog> 

</h:form> 

</ui:composition> 

MovementJsf.java

package it.fronte.account.jsf; 

import it.fronte.account.command.search.MovementSearchCommand; 
import it.fronte.account.model.Movement; 
import it.fronte.account.service.AccountService; 
import it.fronte.dictionary.model.Dictionary; 
import it.fronte.dictionary.service.DictionaryService; 

import java.math.BigDecimal; 
import java.util.ArrayList; 
import java.util.Date; 
import java.util.List; 

import javax.faces.application.FacesMessage; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.RequestScoped; 
import javax.faces.context.FacesContext; 

import org.springframework.web.jsf.FacesContextUtils; 

@RequestScoped 
@ManagedBean(name = "movementJsf") 
public class MovementJsf { 

    protected AccountService accountService = (AccountService) FacesContextUtils.getWebApplicationContext(
      FacesContext.getCurrentInstance()).getBean("accountService"); 
    protected DictionaryService dictionaryService = (DictionaryService) FacesContextUtils.getWebApplicationContext(
      FacesContext.getCurrentInstance()).getBean("dictionaryService"); 

    // Properties 

    public BigDecimal amount; 
    public Integer estimatedId; 
    public Date operationDate = new Date(); 
    public Integer typeId; 

    public List<Movement> movementList = new ArrayList<Movement>(); 

    public List<Movement> getMovementList() { 
     MovementSearchCommand searchCommand = new MovementSearchCommand(); 
     searchCommand.setAccountId(1); 
     searchCommand.setSort("operationDate"); 
     searchCommand.setSortDirection("desc"); 
     searchCommand.setPage(1); 
     searchCommand.setPageSize(99999999); 
     this.movementList = accountService.searchMovement(searchCommand); 
     return movementList; 
    } 

    // Getters & Setters 

    public Integer getTypeId() { 
     return typeId; 
    } 

    public void setTypeId(Integer typeId) { 
     this.typeId = typeId; 
    } 

    public BigDecimal getAmount() { 
     return amount; 
    } 

    public void setAmount(BigDecimal amount) { 
     this.amount = amount; 
    } 

    public Integer getEstimatedId() { 
     return estimatedId; 
    } 

    public void setEstimatedId(Integer estimatedId) { 
     this.estimatedId = estimatedId; 
    } 

    public Date getOperationDate() { 
     return operationDate; 
    } 

    public void setOperationDate(Date operationDate) { 
     this.operationDate = operationDate; 
    } 

    // Constructors 

    public MovementJsf() { 

    } 

    public MovementJsf(Integer typeId, BigDecimal amount, Date operationDate, Integer estimatedId) { 
     this.typeId = typeId; 
     this.amount = amount; 
     this.operationDate = operationDate; 
     this.estimatedId = estimatedId; 
    } 

    // CRUD methods 

    public String addMovement() { 
     Movement movement = new Movement(); 
     movement.setAccountId(1); 
     movement.setCreationDate(new Date()); 
     movement.setLastModifiedDate(new Date()); 
     movement.setTypeId(this.typeId); 
     Dictionary type = dictionaryService.getDictionary(this.typeId); 
     movement.setDirectionId(getDirection(type)); 
     movement.setAmount(this.amount); 
     movement.setEstimatedId(this.estimatedId); 
     movement.setOperationDate(this.operationDate); 
     accountService.saveOrUpdate(movement); 

     movementList.add(0, movement); 

     FacesMessage msg = new FacesMessage("Movimento aggiunto", "Movimento aggiunto"); 
     FacesContext.getCurrentInstance().addMessage(null, msg); 

     return null; 
    } 

    private Integer getDirection(Dictionary dictionary) { 
     if (dictionary.getParentDictionaryId() != null) 
      return getDirection(dictionary.getParentDictionary()); 
     else 
      return dictionary.getId(); 
    } 

} 
+0

我试图从降级4 PrimeFaces到PrimeFaces 3.5,现在我所有的jar文件效果很好。 也许它是版本4.0中的一个bug – GreyStar

+0

然后报告给PrimeFaces家伙,以便他们可以修复它。 – BalusC

+0

该问题与p:dataTable中“stickyHeader”属性的使用有关,它在Primefaces 4中不受支持;所以消除它的行为就消失了。 – GreyStar

回答

-1

解决删除滚动= “true” 或改为滚动= “假”

+1

为什么?什么版本?最新版本?请更具体地说 – Kukeltje

+0

我在primefaces 5.2中看到这个bug。不知道是否修正了最新版本:5.2.13。不知道为什么。还有人可以做更多的测试 – asdrubal