Я использую IceFaces 2.0.
Когда я нажимаю на запись с данными для редактирования, я передаю серийный номер и извлекаю данные для этого серийного номера из БД и устанавливаю значение для объекта в сеансе.
<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>
On 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 и вседругие переменные - ноль, в то время как значение для personList сохраняется в компоненте, находящемся в сеансе.
Не удается найти причину.
- Есть ли какой-либо другой лучший способ решения этой задачи?