In addition to my question "Creating an “Edit my Item”-page in Java Server Faces with Facelets" I would liek to cover an issue that this provided.
When I press the commandButton the ID=100 is removed and the page is refreshed, and this is Before it even runs the method, right, so this means that I do not have the ID when i press the button.
How do you solve this?
By having this Managed Bean
public class BeanWithId implements Serializable {
private String id;
private String info;
private void populateInfo() {
info = "Some info from data source for id=" + id;
}
public String getId() { return id; }
public void setId(String id) {
this.id = id;
populateInfo();
}
public String getInfo() { return info; }
public void setInfo(String info) { this.info = info; }
public String save() {
System.out.println("Saving changes to persistence store");
return null; // no navigation
}
}
And adding
<p><h:commandButton action="#{beanWithId.save}" value="Save" /></p>
To my facelet-page. Now I also have the correct information in my faces-config.xml and when I access my page using ?ID=100 I do get the correct Item returned.