Java 如何通过手动单击添加新按钮在rich:datatable中添加多行?
我正在设计一个网页,其中有一个rich:DataTable,我正在使用它在数据库中添加新的客户信息 因此,每次单击“AddNew”按钮时,RichDataTable中都会出现一个新行,输入文本字段为空 问题:即使单击“添加新”按钮多少次,表中也只剩下一行 以下是我的网页代码:Java 如何通过手动单击添加新按钮在rich:datatable中添加多行?,java,jsf,jsf-2,richfaces,Java,Jsf,Jsf 2,Richfaces,我正在设计一个网页,其中有一个rich:DataTable,我正在使用它在数据库中添加新的客户信息 因此,每次单击“AddNew”按钮时,RichDataTable中都会出现一个新行,输入文本字段为空 问题:即使单击“添加新”按钮多少次,表中也只剩下一行 以下是我的网页代码: 以下是AdminBean的代码: @ManagedBean @ViewScoped public class AdminBean { private String currentType; priva
以下是AdminBean的代码:
@ManagedBean
@ViewScoped
public class AdminBean {
private String currentType;
private String currentItem;
private List<Customer> customerList = new ArrayList<Customer>();
private List<Account> accountList;
private List optionList;
public List getOptionList() {
optionList = new ArrayList<String>();
if (currentType.equals("Add New User")) {
optionList.add("Participant");
optionList.add("Administrator");
} else if (currentType.equalsIgnoreCase("Manage Balance")) {
optionList.add("Withdrawl");
optionList.add("Deposit");
}
return optionList;
}
public void setOptionList(List optionList) {
this.optionList = optionList;
}
public List<Account> getAccountList() {
return accountList;
}
public void setAccountList(List<Account> accountList) {
this.accountList = accountList;
}
public List<Customer> getCustomerList() {
System.out.println("got list..................");
return customerList;
}
public void setCustomerList(List<Customer> customerList) {
this.customerList = customerList;
}
public String getCurrentItem() {
return currentItem;
}
public void setCurrentItem(String currentItem) {
this.currentItem = currentItem;
}
public String getCurrentType() {
return currentType;
}
public void setCurrentType(String currentType) {
this.currentType = currentType;
}
public void addCustAction(){
System.out.println("kshitij jain.......actionListener"+customerList.size());
Customer cust = new Customer();
customerList.add(cust);
}
}
@ManagedBean
@视域
公共类AdminBean{
私有字符串类型;
私有字符串项;
private List customerList=new ArrayList();
私人名单;
私人列表选择列表;
公共列表getOptionList(){
optionList=新的ArrayList();
if(currentType.equals(“添加新用户”)){
选择列表。添加(“参与者”);
选项列表。添加(“管理员”);
}else if(currentType.equalsIgnoreCase(“管理余额”)){
选择列表。添加(“撤回”);
选择列表。添加(“存款”);
}
返回选项列表;
}
公共作废设置选项列表(列表选项列表){
this.optionList=optionList;
}
公共列表getAccountList(){
返回帐户列表;
}
公共作废setAccountList(列表accountList){
this.accountList=accountList;
}
公共列表getCustomerList(){
System.out.println(“获取列表”);
返回客户列表;
}
public void setCustomerList(列表customerList){
this.customerList=customerList;
}
公共字符串getCurrentItem(){
返回当前项目;
}
公共无效setCurrentItem(字符串currentItem){
this.currentItem=currentItem;
}
公共字符串getCurrentType(){
返回电流类型;
}
公共无效setCurrentType(字符串currentType){
this.currentType=currentType;
}
公共无效addCustAction(){
System.out.println(“kshitij jain…….actionListener”+customerList.size());
客户客户=新客户();
customerList.add(客户);
}
}
您的代码中有一些问题:
- 每个
都应该包装在ui命令
中才能工作。请参阅,第1节 - 您没有以正确的方式声明
方法,该方法需要actionListener
参数。看起来您想使用ActionEvent事件
。有关更多信息,请参阅操作
- 在RichFaces4中,不需要将
与
一起使用,这就是
的目的。从文件中: 该组件类似于JavaServerFaces(JSF)组件,但还包括Ajax支持
无需对托管bean进行任何更改。我将所有内容放入表单后,CommandButton停止工作。它甚至没有调用action方法。我已经更改了代码,现在对datatable和action方法的调用进行得很好,但仍然面临另一个问题:我遇到以下异常:javax.el.PropertyNotFoundException:/adminhome.xhtml@145,73 value=“#{cust1.Id}”:类“bank.persistence.entity.Customer”没有属性“Id”。但是我已经看到我的bean中已经有了这个属性。我正在更新上述代码。@KshitijJain请确保代码中没有嵌套的
s。下次不要盲目复制/粘贴代码,而是根据您的需要调整发布的代码。另外,请阅读答案中的链接和参考资料,它们是为了提供有关建议的更多详细信息。抱歉,您没有按照建议将
更改为
(至少您没有实际编辑)。首先,非常感谢您提供的链接。他们真的很有帮助。我的代码中没有嵌套表单。我还没有更新代码以包含,因为该代码不起作用。最后,现在相同的代码运行良好。我意识到在向dataTable添加新行时,需要再次呈现完整的面板。因此,与Datascroller一起工作的一切都很好。我正在更新上面的正确代码。与BeanPropertyNot found相关的问题正在发生,因为我在Customer Bean中放置了具有错误命名conv.的字段。