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
See how you would solve these known algorithm problems
Implementing tokenizer and adding tokens to the linked listCheck if two strings are anagrams or not
Find K Complementary numbers from array Java implementation
testing k complementary pairs algorithm with junit
String Ordered Permutation Algorithm Problem
binary tree problems with solution
Find the first occurence of number in the sorted array
Find longest palindrom from sequence of characters
Changing decimal number to its binary equivalent
find longest word in the sentence