0

使用 jsf 我想编辑员工资料,当用户单击任何特定的数据表行时,然后

我能够在数组列表中获得所选患者的所有详细信息。现在我想将 arraylist 中的所有属性设置为 page1.xhtml backingbean ,因此当用户选择特定行时,他将导航到 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。

告诉我该怎么做(走。

4

1 回答 1

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);
于 2012-05-28T18:41:39.487 回答