重定向后,JSF sessionbean值不会保留

时间:2011-11-17 12:42:14

标签: jsf-2 icefaces

我正在使用IceFaces 2.0。

当我点击要编辑的数据表条目时,我传递序列号并从DB获取该序列号的数据,并将值设置为会话中的对象。

<ice:column>
   <h:panelGroup>
    <span style="margin-right: 5px"><h:commandLink action="#{person.getPersonDetail}" value="Edit" >
    <f:param id="serialNo" name="serialNo" value="#{person.serialNo}"></f:param>
   </h:commandLink></span>
</h:panelGroup>
</ice:column>
</ice:dataTable>

Bean:

@ManagedBean(name="personBean")
@SessionScoped
public class PersonBean implements Serializable{

    private long serialNo;
    private String firstName;
    private String middleName;
    private String lastName;
    private Date dob;
    private java.sql.Date dateB; 
    private String gender;
    private String emailId;
    private PersonService personSerivce;
    private List<PersonBean> personList;
    private PersonBean person;

    //Getter - Setter for all the properties

    public PersonBean getPerson(){
        System.out.println("PersonBean.getPerson()");
        if(this.person==null)
        {
        PersonBean personB= (PersonBean)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("personBean");
            this.person=personB.person;
        }
        return this.person;
    }

    public String getPersonDetail(){
        try {
            System.out.println("Serial No: "+getSerialNo());
            //setPerson(getPersonSerivce().getPerson(getSerialNo()))
            if(this.person==null)
                this.person=getPersonSerivce().getPerson(getSerialNo());
            System.out.println("First Name: "+this.person.firstName);

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "getUser";
    }

faces-config条目:

<navigation-rule>
        <from-view-id>*</from-view-id>
        <navigation-case>
            <from-outcome>getUser</from-outcome>
            <to-view-id>/editUser.xhtml</to-view-id>
            <redirect/>
        </navigation-case>

在EditUser.xhtml上

<h:panelGroup>
    <h:panelGroup>
        <h:outputLabel value="First Name" />
     </h:panelGroup>
   <h:panelGroup>
        <h:inputText value="#{personBean.person.firstName}" id="fName"/>
    </h:panelGroup>
</h:panelGroup>

重定向后,personBean.person和所有其他变量中的值为null,而personList的值保留在会话中的bean中。

找不到原因。

  1. 任何其他更好的方法来完成这项任务?

0 个答案:

没有答案