Reputation: 315
so I found this issue, it is really weird..
So I have this xhtml page:
<h:form>
<rich:dataTable value="#{carsBean.myList}" var="car">
<rich:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:inputText value="#{car.name}">
<p:ajax event="keyup" listener="#{carsBean.print}" />
</h:inputText>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="Company" />
</f:facet>
<h:inputText value="#{car.company}">
<p:ajax event="keyup" listener="#{carsBean.print}" />
</h:inputText>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="Address" />
</f:facet>
<h:inputText value="#{car.address}">
<p:ajax event="keyup" listener="#{carsBean.print}" />
</h:inputText>
</rich:column>
</rich:dataTable>
<h:commandButton value="save-empty">
</h:commandButton>
</h:form>
The following is the managedbean:
@ManagedBean(name="carsBean")
@SessionScoped
public class CarsBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = -7818770780064447805L;
private List<Car> myList;
private String test;
public CarsBean(){}
public void print(){
System.out.println("I got hit!");
}
/**
* @return the myList
*/
@PostConstruct
void initialiseSession() {
FacesContext fc = FacesContext.getCurrentInstance();
fc.getExternalContext().getSession(true);
if(myList==null){
myList = new ArrayList<Car>();
};
if(myList.isEmpty()){
for(int a=0;a<10;a++){
myList.add(new Car("test","test","test"));
}
}
}
public List<Car> getMyList() {
return myList;
}
/**
* @param myList the myList to set
*/
public void setMyList(List<Car> myList) {
this.myList = myList;
}
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
public static class Car{
private String name;
private String company;
private String address;
public Car(){}
public Car(String name, String company, String address) {
super();
this.name = name;
this.company = company;
this.address = address;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the company
*/
public String getCompany() {
return company;
}
/**
* @param company the company to set
*/
public void setCompany(String company) {
this.company = company;
}
/**
* @return the address
*/
public String getAddress() {
return address;
}
/**
* @param address the address to set
*/
public void setAddress(String address) {
this.address = address;
}
}
}
Now the aim is to save the users input in the sessionscope such that even if the user closes the tab or makes a new request the data gets persisted.
The above code works, but I have noticed, when I remove the ajax events on the input box it dosent.
Any ideas?
THanks
Upvotes: 1
Views: 1201
Reputation: 17435
The ajax events are causing your changes to be sent to the server, and persisted in the session. If you don't have them, you will need something else to do it. Clasically, you would do a normal post (any submit button on your form will do, really). But your users will have to click the button to explicitly save their changes.
If your goal is really that your users can play around, close their tab, and when they come back everything is as they left it, you will need the ajax events anyway.
Upvotes: 4