不更改jsf上的outputtext值

时间:2017-03-09 13:19:16

标签: jsf primefaces

我创建了一个带有primefaces的web项目。我将一个txt文件上传到datatable并制作一些特定的进程,然后想在assign列上做一些更改,但是当我输入内容时,outputtext不会改变。但输入文本更改。我的意思是如果行点击,显示新值但它没有,显示旧值。这是我的代码

@ManagedBean@ViewScoped 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>

1 个答案:

答案 0 :(得分:0)

Primefaces Showcase使用

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

因此它更新了表单而不是数据表,并且没有输入字段的更新属性。