【发布时间】:2011-11-14 07:56:55
【问题描述】:
我想做的是,我的列表映射到数据表中, 我有一个添加按钮,通过单击它,我在数据表中添加了一个空的 StudentVO。 在单击添加按钮时,我维护一个映射到 h:inputHidden 的计数器 cnt,
所以我在数据表的最后一行的每一列中获取输入文本,
但是当我再次单击“添加”按钮时,我的计数器会增加,但数据表列表没有新添加的学生,我得到两行空输入文本
所以再次在页面加载时,我得到最后一行输入文本,而我期待两行,一行包含输入文本,其中包含先前输入的数据,另一行包含空输入文本,
这是下面的代码,
public class StudentBeanThree {
@Resource(name="jdbc/rahul_sample_pool",type=DataSource.class)
private List<StudentVO> studentList;
private Integer cnt;
public List<StudentVO> getStudentList() {
-----
}
@PostConstruct
public void init(){
try{
loadStudents();
}catch(Exception e){
e.printStackTrace();
}
}
private void loadStudents() throws Exception{
//load student list
}
public String addNewStudent(){
// This method is called on click of the add button,
if(getCnt() == null){
setCnt(0);
}
this.cnt = getCnt();
this.cnt++;
this.setCnt(cnt);
if(this.getStudentList() == null){
loadStudents();
}
for(int x=0; x < getCnt().intValue();x++){
this.getStudentList().add(new StudentVO());
}
}
}
【问题讨论】:
标签: jsf