data injection from h:dataTable
blacky Nov 10, 2005 6:39 AMHello everyone!
I have problem updating fields of entitie beans. I have a page which contains dataTable jsf-component, with one inputText field, I insert some data into. I got also link-cell which fires update to the backing session bean:
table.jsp
<h:dataTable id="animals" value="#{animals}" var="anima"> ... <h:column> <f:facet name="header"> <h:outputText value="type" /> </f:facet> <h:inputText id="type" value="#{anima.type}" /> </h:column> <h:column> <h:commandLink id="changeData" action="#{manage.update}" value="Change" /> </h:column>
Animal is simple entity bean defined this way:
@Entity @Table(name = "animal") public class Animal implements Serializable { private String type = ""; public String getType() { return type; } public void setType(String type) { this.type = type; } ... }
The manage object is session bean described this way:
ManageBean.java
@Stateful @Name("manage") @Scope(ScopeType.SESSION) @Intercept(InterceptionType.ALWAYS) @Interceptor(SeamInterceptor.class) @Conversational(ifNotBegunOutcome = "main") @Local( { Manage.class }) public class ManageBean implements bussiness.Manage, Serializable { @PersistenceContext(unitName = "manager", type = PersistenceContextType.EXTENDED) protected EntityManager em; @DataModel private List<Animal> animals; @DataModelSelectionIndex private int animalIndex; public String update() { Animal animal = this.animals.get(this.animalIndex); em.persist(animal); return "end"; } public String obtainAnimals() { this.animals = (List) this.getAnimals(); return "success"; } public Collection getAnimals() { animals = em.createQuery("from Animal a").getResultList(); return animals; } ... }
obtainAnimals is called from the index.jsp page and redirects to the table.jsp. Everything renders fine, I can see content of my database. I change the value in input text of the animal type in my web-browser. When I press my changeData link, update method of the ManageBean is fired. I obtain entity bean to animal local variable, which represents the row I've chosen in the browser. And then the problem appears - bean contains its old values - no new values inserted in the form. Besides, the new values don't apear enywhere later. Why the component isn't updated before the update call? Haven't I bound it properly?
Thanks in advance for help