Question

I have a CRUD form backed up by a primefaces datatable. Every time a new entity is created, the table is updated. But the thing is the creation only works once, subsequent requests in the same view do not trigger the backing bean action. Upon close inspection the only difference I found out is that subsequent requests lacks the javax.faces.ViewState attribute in POST data, wich, I think, ends up creating a whole new bean.

Is this the default for JSF 2.2?

Here's the view:

<h:form id="create">
    <p:outputLabel value="label" for="inp"/>
    <p:inputText id="inp" value="#{newJSFManagedBean.newEntity.foo}"/>

    <p:commandButton action="#{newJSFManagedBean.create()}" 
                     update="@form, :table" value="Create"/>
</h:form>

<br />

<p:dataTable value="#{newJSFManagedBean.entities}" var="entity"
             id="table">
    <p:column headerText="foo">#{entity.foo}</p:column>
</p:dataTable>

The bean:

@Named
@javax.faces.view.ViewScoped
public class NewJSFManagedBean implements Serializable {
    private NewEntity newEntity;
    @EJB
    private NewEntityFacade entityFacade;

    private Collection<NewEntity> entities;

    @PostConstruct
    private void init() {
        newEntity = new NewEntity();
        entities = entityFacade.findAll();
    }

    // ...

}

The EJB too:

@Stateless
public class NewEntityFacade {
    @PersistenceContext
    private EntityManager em;

    // ...

}
Was it helpful?

Solution

This behaviour is, apparently, an issue with glassfish 4. It happens when an update attribute contains a form id. A workaround is to update an inner container instead of the whole form.

More here: http://forum.primefaces.org/viewtopic.php?f=3&t=31280

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top