我在默认构造函数中的AllUsersBean类中收到错误。 它没有识别此行中的subBean users.add(subBean.clone()); 我使用subBi.clone将用户的提交信息克隆到名为users的UsersList。 谢谢你的任何建议。
这是错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-
compile) on project Test: Compilation failure
[ERROR] ......(here was path to this class) AllUsersBean.java:[25,18] cannot find symbol
[ERROR] symbol: variable subBean
要解决这个问题,我试图在UserBean类中为appBean添加getter和setter,但它不起作用。
package testpkg;
/*Importing required java libraries */
import javax.inject.Named;
import javax.enterprise.context.ApplicationScoped;
import java.util.ArrayList;
import java.util.List;
@Named("appBean")
@ApplicationScoped
public class AllUsersBean {
private List<UserBean> users;
public AllUsersBean(){
users = new ArrayList<UserBean>();
users.add(subBean.clone());
}
public List<UserBean> getUsers() {
return users;
}
public void setUsers(List<UserBean> users) {
this.users = users;
}
}
package testpkg;
/*Importing required java libraries */
import java.io.Serializable;
import javax.inject.Named;
import javax.inject.Inject;
import javax.enterprise.context.SessionScoped;
@Named("subBean")
@SessionScoped
public class UserBean implements Serializable{
private String fname;
@Inject
private AllUsersBean appBean;
public UserBean() {
this.fname = null;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public AllUsersBean getAppbean() {
return appBean;
}
public void setAppbean(AllUsersBean appBean) {
this.appBean =appBean;
}
}
答案 0 :(得分:0)
您是否尝试过创建一个名为subBean to AllUsersBean的字段,并使用注释@PostConstruct进行初始化?而且一般来说使用克隆不是一个好习惯