Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在数据库中保存DATATABLE的多个h:inputText值_Java_Jsf_Primefaces - Fatal编程技术网

Java 如何在数据库中保存DATATABLE的多个h:inputText值

Java 如何在数据库中保存DATATABLE的多个h:inputText值,java,jsf,primefaces,Java,Jsf,Primefaces,在网页中,我使用来展示它们 JSF页面的示例: <h:dataTable value="#{bean.scores}" rowIndexvar="index"> <h:column> <h:outputText value="#{index+1}" /> </h:column> <h:column> <h:outputText value="#{score.studentId}" /

在网页中,我使用
来展示它们

JSF页面的示例:

<h:dataTable value="#{bean.scores}" rowIndexvar="index">
    <h:column>
      <h:outputText value="#{index+1}" />
    </h:column>
    <h:column>
      <h:outputText value="#{score.studentId}" />
    </h:column>
    <h:column>
       <h:inputText value="#{score.teacherScore}" />
    </h:column>
</h:dataTable>

<h:commandButton value="Save" action="#{useMB.save}" />
<h:messages />

这些问题与我的ManagedBean有关:useMB.java

1.我需要编写什么getter和setter方法来存储
数据库中的值

2.如何使用dataTable、JSF和java在数据库中保存同一科目的不同学生分数


3.我需要在xhtml页面中做什么更改?

您需要在托管bean中使用一个集合来保存表中行的值。表中的每一行表示集合中的单个元素,每个元素都可以通过
var
属性中给出的别名在
dataTable
中访问

<h:dataTable value="#{bean.scores}" rowIndexvar="index" var="score">
    <h:column>
      <h:outputText value="#{index+1}" />
    </h:column>
    <h:column>
      <h:outputText value="#{score.studentId}" />
    </h:column>
    <h:column>
       <h:inputText value="#{score.teacherScore}" />
    </h:column>
</h:dataTable>
分数等级应(至少)如下所示:

public class Score {
    private String studentId;

    private String teacherScore;

    public String getStudentId() { return studentId; }

    public void setStudentId(String studentId) { this.studentId = studentId; }

    public String getTearcherScore() { retyrn teacherScore; }

    public void setTeacherScore(String tearcherScore) { this.tearcherScore = tearcherScore; }
}

谢谢,现在工作很好。
public class Score {
    private String studentId;

    private String teacherScore;

    public String getStudentId() { return studentId; }

    public void setStudentId(String studentId) { this.studentId = studentId; }

    public String getTearcherScore() { retyrn teacherScore; }

    public void setTeacherScore(String tearcherScore) { this.tearcherScore = tearcherScore; }
}