primefaces command button action invoked after datatable load - jsf-2

I am facing a problem with primefaces command button and datatable. I have two buttons inside the datatable. when I click on the button everytime datatable loaded first and then button action invoked. I just want to avoid the datatable loading when button is clicked.
<p:dataTable id="alphaTable" var="cs" binding="#{challengeSetBean.alphaChallengeSetTable}"
value="#{challengeSetBean.challengeSet}" styleClass="myTable"
style="list-style-type:none;width:600px;border:1px;" >
<p:column id="col" style="width:20px;font-size:12px;padding-left:7px;padding-bottom:7px;padding-top:7px;">
..................
................
</p:column>
<p:column style="width:28px;font-size:9px;padding-left:7px;padding-bottom:7px;padding-top:7px;">
<p:commandButton value="#{msg.updateAccount_reset}" action="#{challengeSetBean.editAnswer()}" immediate="true" rendered="#{!cs.editMode}" process="#this" update="col" >
</p:commandButton>
<p:commandButton value="#{msg.common_save}" action="#{challengeSetBean.saveAnswers()}" rendered="#{cs.editMode}" ajax="true" immediate="true" update="#form"/>
<p:commandButton value="#{msg.cancel}" action="#{challengeSetBean.cancelAnswer()}" rendered="#{cs.editMode}" ajax="true" immediate="true" update="#form"/>
<p:commandButton value="#{msg.common_delete}" action="#{challengeSetBean.deleteAnswer()}" rendered="#{!cs.editMode}" immediate="true" update="#form"/>
</p:column>
</p:dataTable>

Put the bean in the view scope so that it would be instantiated only once on initial GET request and be reused on subsequent postbacks. Remove the binding attribute from the <p:dataTable> so that the view scoped bean won't be recreated due to chicken-egg JSF issue 1492. Now you can just load the challengeSet in the (post)constructor of the bean. It won't be invoked during subsequent postbacks.
See also:
Binding kills backing beans...what am I doing wrong?
How can I pass selected row to commandLink inside dataTable?
Recommended JSF 2.0 CRUD frameworks

Related

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.

How to dynamically get value of component p:inputText inside a datatable?

I have a primefaces Datatable:
<p:dataTable id="tabela" var="item"
value="#{myBean.lista}"
rowIndexVar="rowindex">
<p:column>
<p:inputText
required="true" id="inputAliquota" value="#{item.taxa}"
>
</p:inputText>
</p:column>
</p:dataTable>
In my backing bean I have a lista:
private List<Aliquota> lista;
And a Button to remove columns from my datatable:
<p:commandLink
immediate="true" id="botaoExcluir"
action="#{myBean.excluirAliquota}"
>
<f:setPropertyActionListener value="#{item}"
target="#{myBean.aliquota}" />
</p:commandLink>
When I start the bean I populate "lista" with 5 empty Aliquota objects.
In excluirAliquota method I get the object that has to be removed, compare with the values of the List and delete it. But I'm having problems. When the user change the value of inputText the change don't reflect the Aliquota object on list.
My question is how to set this value without submit it?
You cannot reflect the value on the backing bean without submitting it. However, you can submit it using Ajax by adding a listener to the input text. The listener method doesn't have to do anything, it can be empty, but it needs to be there for an Ajax submit. It can be something like that:
<p:dataTable id="tabela" var="item"
value="#{myBean.lista}"
rowIndexVar="rowindex">
<p:column>
<p:inputText
required="true" id="inputAliquota" value="#{item.taxa}"
>
<p:ajax listener="#{myBean.dummyListener()}"/>
</p:inputText>
</p:column>
</p:dataTable>
This will instantly reflect all changes in the inputText to the taxa field of the corresponding item. If that's what you want, you can use this method.

Primefaces p:commandlink in p:datatable giving wrong value

I have a datatable which consists of a list of names taken from database. These names are displayed using the commandlink. The code is shown below:
<h:form id="formp">
<p:dataTable id="listpat" var="p" value="#{loginBean.patient}">
<p:column>
<p:commandLink value="#{p.firstname} #{p.lastname}" action="# {loginBean.getPatientID(p.firstname)}" onclick="tabview.select(1);">
</p:commandLink>
</p:column>
</p:dataTable>
</h:form>
clicking the commandlink calls a method getPatientID(p.firstname) in the backing bean. I realised the name on the link i click on does not correspond to what is in the backing bean. (e.g. the name clicked on in the commandlink is not the same as the name gotten by passing into the backing bean). What could be the reason? How can i solve it?
public void getPatientID(String fname) {
System.out.println(fname);
}
<p:commandLink value="#{p.firstname} #{p.lastname}" action="#{loginBean.getPatientID(p.firstname)}" onclick="tabview.select(1);">
<f:setPropertyActionListener target="#{loginBean.patient.firstname}" value="#{p.firstname}"
</p:commandLink>
maybe this will work

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

page navigation not occuring after enabling button from row select using ajax

I am using JSF 2.0 and primefaces 3.0
I am trying to enable a command(Submit) button after a row select from datatable
<p:datatable ....>
<p:ajax event="rowUnselect" onstart="showImageButton.disable();" />
<p:ajax event="rowSelect" onstart="showImageButton.enable();" />
</p:datatable>
<p:commandButton id="commandbuttonid" widgetVar="showImageButton" action="#{bean.methodreturningapage}" value="Submit"
ajax="false" disabled="true" />
after selecting the rows command button gets enabled but the action method is not firing.
Change the disabled attribute into something like #{bean.buttonDisabled}
take a look on this question
p:commandButton not working when disable=“true” initially
and this one
Re-enabled p:commandButton not firing ajax

Resources