0
votes

I'm using primefaces 3.3 with JSF 2.1. In the code below, I have a primeFaces dataTable that contains rows of data drawn from the database which is correctly activated from a tree component on the left part of my page. The dataTable displays and behaves correctly. I have a delete functionality that calls "update" which refreshes my dataTable and reflects my changes after the database was updated. My problem is with with f:facet (id="header"). Contained in that facet is a commandLink that creates a new row in my dataTable. It works in the sense that my database is correctly updated. The dataTable is not refreshed after this. In order to refresh my dataTable, I have to click on another node in my tree component (on the left of the page) and then return to the original treeNode to see my dataTable perfectly updated. What can I add to my code to update the dataTable dynamically? Unfortunately, I can't add all my permutations that I've tried here - I've spent a long time on this problem - and your inputs will be greatly appreciated!

    <h:form id="formRight" >            
    <p:dataTable var="material" value="#{entityCrudTreeBean.materialList}" id="materials" editable="true" paginator="true" rows="10" sortBy="#{material.name}">
                <p:ajax event="rowEdit" listener="#{entityCrudTreeBean.onEditRow}"/>
                <f:facet id="header" name="header">
                    In-Cell Material Editing
                    <br />
                    <p:commandLink id="create" value="Add new material" action="#{entityCrudTreeBean.createNewMaterial}" update=":formRight"/>
                </f:facet>
                <p:column headerText="Name" style="width:125px">
                    <p:cellEditor>
                        ...
                    </p:cellEditor>
                </p:column>

                <p:column headerText="Options" style="width:10px" >
                    <p:rowEditor />
                    <p:commandLink id="delete" action="#{entityCrudTreeBean.deleteRow(material)}" update=":formRight">
                        <h:graphicImage value="#{resource['icons:Delete-icon.png']}" />
                    </p:commandLink>
                </p:column>
            </p:dataTable>
    </h:form>

edit: changing the line to <p:commandLink id="create" value="Add new material" action="#{entityCrudTreeBean.createNewMaterial}" update=":formRight:materials"/> doesn't work either edit: changing to : <f:facet id="header" name="header"> In-Cell Material Editing <br /> <p:commandLink id="create" value="Add new material" ajax="true" process="@this" action="#{entityCrudTreeBean.createNewMaterial}" update="@form"/> </f:facet> doesn't solve the problem either.

2
haven't read the whole question (just the subject)... try to replace update=":formRight" with update="@form"Daniel
Thanks, Daniel. Unfortunately, code: <p:commandLink id="create" value="Add new material" action="#{entityCrudTreeBean.createNewMaterial}" update="@form"/> doesn't work eitherRick
any chance that <h:form id="formRight" > is being wrapped by some other form ?Daniel
no, it's part of <ui:define name="centreContent">. And id="delete" is working well.Rick
just wondering , try to place the delete link in a separate column , maybe there are some issue of adding additional buttons inside a <p:rowEditor /> columnDaniel

2 Answers

2
votes

I had a similar issue as you a while back.

My working code looks like:

<f:facet name="header">Product List
<p:commandLink id="create" value="Add new product" ajax="true" process="@this" 
action="#{modelBean.save}" update="@form"/>
</f:facet>
0
votes

Stephen, you're on the right track! It was solved in a simpler way: I updated my dataTable list in managed bean - which I did for the delete but not for the insert. Massive oversight there. This code works: <p:commandLink id="create" value="Add new material" action="#{entityCrudTreeBean.createNewMaterial}" update=":formRight"/> Tip for people after me: Primefaces 3.3 has a known issue concerning updating within the dataTable. You need to wrap the dataTable with another component like a layout of a form. Calling update on the wrapper works. According to the primefaces blog from Aug 15, this has been fixed in 3.4.RC1. But they changed the tree components. I'll wait for the 3.4 final release before upgrading.