datatable/component not updated after deleting and adding new one

During working on tabular data, it is common to have edit and delete command buttons for each row.

And, after we update or delete we want the table to be updated. Let’s looks some simple example.

The table on the JSF might look like


<form id="tablularForm">
<h:datatable id="tabularData" value="#{someBean.list}"
binding="#{someBean.htmlDataTable}" var="data">
<h:column>
<h:outputText id="colum1" value="#{data.column}" />
</h:column>
<h:column>
<h:CommandLink id="edit" value="Edit" action="#{someBean.editAction}" reRender="tabularData"/>
</h:column>
<h:column>
<h:CommandLink id="delete" value="Delete" action="#{someBean.deleteAction}" reRender="tabularData"/>
</h:column>
</h:datatable>
<h:CommandButton id="add" value="add" action="#{someBean.addAction}" />
</h:form>

The above ideal table would work fine.

The datatable would store values by reading from bean and would be updated on Edit and Delete actions accordingly.

This is b/c of the reRender attribute of the components.

The glitch comes when there is no any data in the table. Say you daleted all the data and you want to add a new one.

Or it is the brand new table to be added.

The row would be added but it wont be shown on the table. In short the table would not be updated.

The thing is when we use reRender, we have to use the enclosing component not the component to be safe!.

When it tries to rerender if the component was not there initially, it wont rerender it.
So, here we can use the id of the form for rerendering the datatable and we would be OK.

See why jsf apps are slow in cases

Action in bean is never triggered/called from jsf page

One plus side of the compiled languages would be telling us every error during/after compilation which would save a lot time from chicanery. But, in JSF you may get unexpected error which is a silent.

The page would run and the action linked to, say command button or command link, may not be triggered.

If you got that, just check your form fields – especially if you are working with datatable, make sure all the conversion and validations are working as expected. If the validation/conversion is not working properly, then the framework would exit before reaching the backend.

One way to troubleshoot this would be to have <h:messages /> with appropriate attributes, like adding showDetail=”false” showSummary=”true”, on your form – that, definitely, would help you to debug the problem.