Prevent state saving for specific element - jsf-2

I have the following scenario:
I have a dataTable in which I have a column with the following code
<f:facet name="header">
<h:selectBooleanCheckbox styleClass="checkall"
id="my-id-chk" />
<h:outputLabel for="my-id-chk" />
</f:facet>
<h:selectBooleanCheckbox rendered="#{row.selectable}" value="#{row.selected}"
styleClass="checkall_remover" id="row-chk" />
<h:outputLabel for="row-chk" />
When I want to select all rows and delete them:
1) I click on the h:selectBooleanCheckbox in the <f:facet name="header"> and with js I select all rows checkboxes
2) Click on delete button that execute that dataTable and deletes all rows on server , that delete button also renders the dataTable so the deleted rows will be removed from it
Now the thing is that the h:selectBooleanCheckbox in the <f:facet name="header"> keeps its state (checked state)
How can I make that h:selectBooleanCheckbox in the <f:facet name="header"> to be unchecked ?
The solution that I use right now is to render the dataTable from a "proxy" button that is located in other h:form <-- Using that technique causes the h:selectBooleanCheckbox in the <f:facet name="header"> not to remember its state.
But I prefer a cleaner solution without using additional h:form
(I use MyFaces 2.2.3 with Tomcat 7)

Just use plain HTML. JSF state is indeed saved on server side, but HTML state not.
<f:facet name="header">
<input type="checkbox" class="checkall"
id="my-id-chk" />
<label for="my-id-chk" />
</f:facet>
An alternative would be to create a custom component whereby getters/setters don't delegate to UIComponent#getStateHelper() but instead to local properties.

Related

Upload multiple files in one form using h:inputFile JSF

I have one datatable and each row have a <h:inputFile>, one button to add a new row for table.
Each time button fired, the previous inputFiles were cleared -> that is not my aim.
I want to store all the upload file then submit.
The simple code here:
<h:form id="documentForm" enctype="multipart/form-data">
<p:dataTable value="#{documentList}" var="obj" >
<f:facet name="header">
<p:commandButton value="Add new row" action="#{contractDetailController.addNewDoc}" update="documentTable" ajax="false"/>
</f:facet>
<p:column headerText="Document File">
<h:inputFile value="#{obj.file}" />
</p:column>
</p:dataTable>
</h:form>
Through BalusC comment in this post : How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null / throws an error / not usable, it seems no way to store previous upload file through requests.
Is there any solutions for my case

Calling listener in p:selectBooleanCheckbox without refreshing the whole dataTable in Primefaces

I have a Primeface selectBooleanCheckbox in a column of a DataTable. Inside there is a <p:ajax that on check calls the method in the listener (mybean.checkCell(cell.field2)) and saves the status of the checkbox.
My problem is that the entire p:dataTable is refreshed when I check.
How do I call mybean.checkCell(cell.field2) without refreshing the whole dataTable?
Here is my code:
<p:dataTable var="cell" value="#{mybean.mycells}" widgetVar="cell" emptyMessage="No cells" filteredValue="#{mybean.filteredCells}">
<p:column filterBy="#{cell.field1}" headerText="Field1" filterMatchMode="contains">
<h:outputText value="#{cell.field1}" />
</p:column>
<p:column headerText="Checkbox">
<p:selectBooleanCheckbox value="#{cell.check}" partialSubmit="true">
<p:ajax process="#this" partialSubmit="true" update=":form:messages" listener="#{mybean.checkCell(cell.field2)}" onstart="PF('statusDialog').show();" oncomplete="PF('statusDialog').hide();" />
</p:selectBooleanCheckbox>
</p:column>
</p:dataTable>
You are updating the component specified in update=":form:messages" everytime click the checkbox. I guess "messages" ID belongs to a container where the datatable is in. If it is not right, i don't understend why the databled gets updated. If it is right, just delete the update attribute or update something that does not contain the datatable inside.

Filter Facet is not working in Richface 4.3x

In the Code below, You can observe two things:
1) Default sorting is getting utilized.
2) Image based custom filter is used.
Problem I am facing : When I click on filter image default sorting is getting triggered.
Need a way by which If I click on filter, default sorting doesn't get triggered. (This was achieved in Richface 3.3 by putting this custom filter in filter facet.)
Any help or hint would be greatly appreciated.
<rich:column sortBy="#{model.modVal}" label="Model Value"
sortable="true" id="modelVal" rendered="#{backingBean.renderMap['modVal']}">
<f:facet name="header">
<h:outputText value="Model Value" />
<h:graphicImage title="Filter"
value="#{backingBean.dataModel.modValFilter }">
<a4j:ajax event="click" render="filterCol"
execute="#form"
listener="#{backingBean.loadModalPanelData('modVal') }"
oncomplete="#{rich:component('filterCol')}.show()">
</a4j:ajax>
</h:graphicImage>
</f:facet>
<h:outputText value="#{model.modeVal}"
title="#{model.modelVal}" />
</rich:column>
Use manual sorting, and place a click-able panel in your header for sorting, and another panel for filtering.
The filter facet has been deprecated in favour of the header facet. So what you used to have in the filter facet, you can place in the header facet:
<f:facet name="header">
<h:panelGrid>
<h:outputText value="Model Value"/>
<h:graphicImage title="Model Filter"/>
</h:panelGrid>
</f:facet>

ignoreValidationFailed doesn´t work inside p:dataTable

I am using actionListener ajax call inside datatable and trying to do the following :
skip validation
update the model with the inserted values
I knew that omnifaces utility liberary by BalusC can do this using o:ignoreValidationFailed
But it failed with me to work inside primefaces datatable.
Also I found that it failed to work inside ui:repeat in another post here
I dont know if its a bug or not.
here is my code example
<o:form id ="trans_desc_form">
<p:outputPanel id="stkdetailsid">
<p:dataTable id="transactiondetailsid" value="#{stockTransactionsBean.stkTransHeader.stkTransDetailsList}"
var="stkTransDet" rowIndexVar="rowIndex">
<p:column>
<f:facet name="header">
<h:outputText value="Item Code" />
</f:facet>
<p:autoComplete id="dd" required="true"
value="#{stkTransDet.item}" var="i" itemLabel="#{i.itemno} #{i.itemnamee}"
itemValue="#{i}" converter="itemsConverter"
completeMethod="#{stockTransactionsBean.completeItems}"/>
</p:column>
<p:column>
<p:commandButton value="-" update="#form" process="#form"
actionListener="#{stockTransactionsBean.removeRow(rowIndex)}">
<o:ignoreValidationFailed />
</p:commandButton>
</p:column>
</p:dataTable>
</p:outputPanel>
</o:form>
As a workaround, I added
1- add a condition to the required field to know if the ajax come from submit button or not
to the autoComplete component where the trans_desc_form is thte entire form id and savetransid is the submit button save id
required="#{!empty param['trans_desc_form:savetransid']}"/>
2- I removed #NotNull from my JPA entity which force the validation
#JoinColumn(name = "ITEMNO", referencedColumnName = "ITEMNO")
#ManyToOne(optional = false, fetch = FetchType.LAZY)
//#NotNull
private Item item;
To skip validation you can use the immediate="true" attribute on your p:commandButton

I can't update from within a facet

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.
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>
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.

Resources