2017-03-09 49 views
0

我用primefaces製作了一個web項目。我將一個txt文件上傳到數據表中,然後創建一些特定的過程,然後想要對assign列進行一些更改,但是當我輸入某些內容時,outputtext不會更改。但是,輸入文本更改。我的意思是如果該行點擊,顯示新值,但它不顯示舊值。這裏是我的代碼不會更改jsf上的outputtext值

@[email protected] public class MessageTableController implements Serializable { 

private static final long serialVersionUID = 20111020L; 

private List<preList> kullaniciList; 
private UploadedFile file; 
private File f; 
private BufferedReader br; 
private String line; 
private String[] str; 


public List<preList> getKullaniciList() { 
    return kullaniciList; 
} 

public void setKullaniciList(List<preList> kullaniciList) { 
    this.kullaniciList = kullaniciList; 
} 

public UploadedFile getFile() { 
    return file; 
} 

public void setFile(UploadedFile file) { 
    this.file = file; 
} 

public void upload() throws IOException { 
    if (file != null) { 
     FacesMessage message = new FacesMessage("Succesful", file.getFileName() + " is uploaded."); 
     FacesContext.getCurrentInstance().addMessage(null, message); 
     readUploadedFile(); 
    } 
} 

public void readUploadedFile() throws IOException { 
    f = new File(file.getFileName()); 
    br = new BufferedReader(new FileReader(f)); 
    kullaniciList = new ArrayList<preList>(); 
    while ((line = br.readLine()) != null) { 
     if (line.contains("PI")) { 
      str = line.split("="); 
      kullaniciList.add(new preList(str[0], str[1])); 
     } 
    } 
    br.close(); 
} 


public class preList { 

    private String value; 

    private String assign; 

    public preList(String value, String assign) { 
     this.value = value; 
     this.assign = assign; 
     System.out.println(value); 
    } 

    public String getValue() { 
     return value; 
    } 

    public void setValue(String value) { 
     System.out.println(value); 
     this.value = value; 
    } 

    public String getAssign() { 
     return assign; 
    } 

    public void setAssign(String assign) { 
     System.out.println(value); 
     this.assign = assign; 
    } 
}} 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets" 
    xmlns:h="http://xmlns.jcp.org/jsf/html" 
    xmlns:f="http://xmlns.jcp.org/jsf/core" 
    xmlns:p="http://primefaces.org/ui"> 

<h:head> 

</h:head> 
<h:body> 
    <h:form enctype="multipart/form-data"> 
     <p:growl id="messages" showDetail="false" /> 

     <p:fileUpload value="#{messageTableController.file}" mode="simple" 
      skinSimple="true" /> 

     <p:commandButton value="Submit" ajax="false" 
      actionListener="#{messageTableController.upload}" disabled="false" /> 
    </h:form> 
    <p:dataTable id="cellEditingTable" var="message" 
     value="#{messageTableController.kullaniciList}" paginator="true" 
     paginatorPosition="bottom" editable="true" editMode="cell"> 


     <f:facet name="header"> 
      PRE_INSTALL 
     </f:facet> 

     <p:column> 
      <f:facet name="header"> 
       <h:outputText value="Value" /> 
      </f:facet> 
      <p:cellEditor> 
       <f:facet name="output"> 
        <h:outputText value="#{message.value}"/> 
       </f:facet> 
       <f:facet name="input"> 
        <p:inputText value="#{message.value}" 
         style="width:96%" update="cellEditingTable"/> 
       </f:facet> 
      </p:cellEditor> 
     </p:column> 
     <p:column> 
      <f:facet name="header"> 
       <h:outputText value="Assign" /> 
      </f:facet> 
      <p:cellEditor> 
       <f:facet name="output"> 
        <h:outputText value="#{message.assign}" /> 
       </f:facet> 
       <f:facet name="input"> 
        <p:inputText value="#{message.assign}" style="width:96%" /> 
       </f:facet> 
      </p:cellEditor> 
     </p:column> 
    </p:dataTable> 


</h:body> 

</html> 

回答

0

Primefaces Showcase使用

<p:ajax event="cellEdit" listener="#{dtEditView.onCellEdit}" update=":form:msgs" /> 

所以更新的形式,而不是數據表,併爲輸入字段沒有更新的屬性。

+0

謝謝我會研究它 –