使用jsf显示编辑员工的个人资料

时间:2012-05-28 14:46:01

标签: jsf-2 javabeans

使用jsf我想编辑员工档案,当用户点击任何特定的数据表行时,

  

我能够获得所选患者的所有细节   数组列表。现在我想把arraylist中的所有attritbutes设置为   page1.xhtml backbean,所以当用户选择一个特定的行时,   他将导航到page1.xhtml,在那里他将获得所有这些字段   由arraylist属性设置的表单。

我正在尝试这种方式。

> page1.xhtml

    <h:outputLabel  value="Name" />
    <p:inputText id="name1" value="#{employeeBB.emp.name}" >
                            </p:inputText>

    <h:outputLabel  value="age" />
                            <p:inputText id="ag" value="#{employeeBB.emp.age}" >
                            </p:inputText>


    <h:outputLabel  value="code" />
                            <p:inputText id="code1" value="#{employeeBB.emp.code}" >
                            </p:inputText>


@ManagedBean(name = "employee") 
@ViewScoped 
public class emp {
private String name;    
private String age;     
private String code;    
public String getName() 
{       return name;    
}

public void setName(String name) { 
this.name = name;   
}

public String getAge() {
return age;     
}

public void setAge(String age) {
this.age = age;     
}

    public String getCode() {
    return code;    
    }

public void setCode(String code) {
this.code = code;   
}

 }


    @SessionScoped
    @ManagedBean
    public class EmployeeBB implements serializable{

    private Employe emp;

        public Employee getEmp() {
            return emp;
        }

        public void setEmp(Employee emp) {
            this.emp = emp;
        }



    }

    @SessionScoped
    @ManagedBean
    public class AddEmployeeBB{

    private ArrayList<Employee>empList;


    private ArrayList<Employee>empList;


        public ArrayList<Employee> getEmpList() {
            if(empList==null){

                empList=new ArrayList<Employee>();
            }

            return empList;
        }

        public void setEmpList(ArrayList<Employee> empList) {
            this.empList = empList;
        }

    public void method() throws IOException{

    String code='123';

    EmployeeDAO obj=new EmployeeDAO();   // DAO class 

    empList=obj.getAllEmplInfo(code); // will get all needed information about employee of this code in this arrayist 

    for(int i=0;i<empList.size();i++){

    String name=empList.get(i).getName();
    String age=empList.get(i).getAge();
    String code=empList.get(i).getCode();

    Employee e=new Employee();

    e.setName(name);
    e.setAge(age);
    e.setCode(code);

    EmployeeBB obj1=new EmployeeBB();

    obj1.setEmp(e);  // now according to my logic object e will set to emp object of Employee, and 
    // that means  all these values name ,agem and code will be set to my  page1.xhtml and I will be able to see it.



    }

    }

但是我无法获得带有填充值的pag1.xhtml。

告诉我。

1 个答案:

答案 0 :(得分:1)

未显示的原因是您在要创建的对象中设置值

EmployeeBB obj1=new EmployeeBB();

obj1.setEmp(e);

每次看到空白时,JSF生命周期都不会知道这个对象。

AddEmployeeBB中添加此

@ManagedProperty(value="employeeBB")
private EmployeeBB employeeBB = null; // create getter setter for this

然后代替:

EmployeeBB obj1=new EmployeeBB();

obj1.setEmp(e);

使用此:

this.employeeBB.setEmp(e);