I'm having some inconsistent behaviour when combining a hidden input and a commandlink with jsf ajax.
<p:fieldset id="someFieldset">
<h:inputHidden>
<f:validator validatorId="myValidator"/>
<f:attribute name="input1"
value="#{backingBean1.someField}"/>
<f:attribute name="input2"
value="#{backingBean2.someOtherField}"/>
</h:inputHidden>
<p:dataTable id="someTable"
value="..."
var="someVar">
<p:column>
....
</p:column>
....
<p:column>
<p:commandLink id="deleteBtn"
process="someForm:someFieldset"
rendered="..."
oncomplete="if (args && !args.validationFailed {PF('someDialog').show()}">
<f:ajax type="onclick" listener="#{backingBean1.setSomeField(someVar.reference)}" />
</p:commandLink>
</p:column>
</p:datatable
</p:fieldset>
The desired behaviour is the onclick event being fired first before the commandlink will process the hidden input and fire the validator.
The behaviour is however inconsistent. Sometimes the onclick will fire first and other times the validator will fire first (receiving an attribute that hasn't been set first)
Any ideas how I can guarantee the setter being called before the validator?
Related
I am using a primefaces dialog box. I have a list of items, and whenever I choose an item, I want the dialog box to display that item name. However, this is not happening. Rather than displaying the item name, the dialog is not displaying any name at all. I've posted my code below.
<h:form>
<h:dataTable binding="#{table}" value="#{item.itemList}" >
<h:column>
<h:link value="#{item.itemList[table.rowIndex]}" outcome="item">
<f:param name="itemName" value="#{item.itemList[table.rowIndex]}" />
</h:link>
</h:column>
<h:column>
<p:commandButton action="#{item.setItem(item.itemList[table.rowIndex])}" id="showDialogButton"
type="link" value="Delete" onclick="dlg.show()" />
</h:column>
</h:dataTable>
<br />
<p:dialog header="Item" widgetVar="dlg" resizable="false">
<!-- I've also tried Item: #{item.item} -->
<p>Item: <f:attribute name="contentId" value="#{item.item}"/> </p>
<p:commandButton id="submitButton" value="Yes" action=
"#{item.deleteItem}" oncomplete="dlg.hide();">
</p:commandButton>
<p:commandButton id="cancelButton" value="Cancel" oncomplete="dlg.hide();" />
</p:dialog>
</h:form>
My getters and setters are just generic getters and setters.
You forgot to update the dialog before opening.
<p:commandButton ... update="dialogId" />
I also suggest to use oncomplete instead of onclick to open the dialog.
See also:
Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
How to show details of current row from p:dataTable in a p:dialog and update after save
Primefaces p:dialog doesn't always show up if update="dlg" in commandButton
I have to implement the search the functionality in primefaces dialog. After submitiing the search commandbutton the table beside the search needs to get updated. But everytime i am hitting the search button the popup gets closed. Please guide.Below is my code snippet for reference:
......
<p:commandButton id="search" value="Search" actionListener="#{createTicketBaseBean.searchUserFromList}" update="#form" onclick="dlg.show()"></p:commandButton>
</h:panelGrid>
</h:panelGroup>
<h:panelGroup style="float:right" >
<p:dataTable id="table" var="user" value="#{createTicketBaseBean.userList}" selection="#{createTicketBaseBean.selectedUser}" selectionMode="single" rowKey="#{user.email}" >
<p:column headerText="Name" >
<p:commandLink id="nameselect" value="#{user.name}" onclick="dlg.hide()"/>
</p:column>
<p:column headerText="Email">
<h:outputText value="#{user.email}" />
</p:column>
<p:column headerText="Department">
<h:outputText value="#{user.department}" />
</p:column>
</p:dataTable>
Replace onclick in your p:commandbutton with oncomplete. onclick event is happening immediate when button is clicked. As this is AJAX button (in Primefaces this is default) there will be race conditioning between AJAX request and dialog opening. When using oncomplete it will be called after AJAX request is completed.
The problem is with "p:ajax event="rowDblselect" listener="#{companyBean.update()}" ... ", when i doubleClick for the first time, the method "update()" is called one time (Perfect !), but after that when i press on the commandButton "button1" and i doubleClick on the component again , the "update()" is called 2 times. When i repeat one more time, the "update()" is called 3 times ... ... ... ...
This is very weird !! I think when i update the datatable with the commandButton, the ajax event keeps the upgrade for itself. I dont know (?) ... Could anyone help me to solve it ??
<h:panelGrid id="panel" columns="5">
<p:commandButton id="button1" value="Search" actionListener="#{
companyBean.search()}" update="dataTable"/>
</h:panelGrid>
<p:dataTable id="dataTable" var="companyTO" value="#{companyBean.companiesTO}"
selection="#companyBean.selectedCompanyTO}" rowKey="#{companyTO}"
emptyMessage="" selectionMode="single" >
<p:ajax event="rowDblselect" listener="#{companyBean.update()}" immediate="true"
process="#this" />
<p:column >
...
<p:dataTable>
obs.: When i remove the "update="dataTable", the "event="rowDblselect"" works perfect, call the method only one time. So, the problem is on the update.
I found the same problem here : https://stackoverflow.com/questions/11904556/updating-datatable-with-own-datamodel-calls-method-more-and-more
Try to remove the immediate attribute of your ajax event and in your commandbutton add the attributes:
process="#this" partialSubmit="true" ajax="true"
Somethig like this:
Event:
<p:ajax event="rowDblselect" listener="#{companyBean.update()}" process="#this" partialSubmit="true" />
Button:
<p:commandButton id="button1" value="Search" actionListener="#{
companyBean.search()}" update="dataTable" process="#this" partialSubmit="true" ajax="true"/>
I use a Primefaces carousel component to display a list of items. What i would like to do is show a commandButton on every carousel item which triggers a method on the bean to confirm or decline the entry.
Now it works only for the first entry of the carousel. Clicking on another entry does not invoke the action confirmResource. I guess it has something to do with the IDs but i can't figure it out.
Here's the form:
<h:form id="form" prependId="false">
<p:carousel id="resourceCarousel" value="#{resourceRatingBean.resourceProposalList}" var="var" rows="1" itemStyle="width:500px; height: 400px; text-align:center;" circular="true">
<p:column>
<h:panelGrid columns="1" cellpadding="3">
<p:graphicImage value="/cache/images/#{var.imagePath}" width="100"/>
<h:outputText value="#{var.imagePath}" />
<h:outputText value="#{var.name}" />
<h:outputText value="#{var.description}" />
</h:panelGrid>
<p:commandButton value="confirm" action="#{resourceRatingBean.confirmResource}" process="#this">
<f:setPropertyActionListener value="#{var}" target="#{resourceRatingBean.ratedResource}" />
</p:commandButton>
</p:column>
</p:carousel>
</h:form>
I see two likely problems here:
The process="#this" is likely an issue as this will only invoke the process of the invoke the action of the commandButton and not the changes in the carousel component. Try setting this attribute to resourceCarousel or #form instead.
If you are still having issues and using JSF 2 + EL 2.2, then instead of depending on setPropertyActionListener to set the value of a managed property, then instead you can pass the argument var to an actionListener method through an EL expression.
Here is an example:
<p:commandButton value="confirm" actionListener="${resourceRatingBean.confirmResourceListener(var)}"
this="resourceCarousel" />
I have a composite displayed inside a dialog. I have an edit button that get the current bean #SessionScoped (item in a data table) and then update the UI. My app is very similar to a simple CRUD app like http://balusc.blogspot.com/2010/06/benefits-and-pitfalls-of-viewscoped.html.
The problem is that the UI is updated correctly when using <h:outputText/> but not when using a form element.
<h:inputTextarea value="#{cc.attrs.managedBean.assertionStatement}" />
<h:inputText value="#{cc.attrs.managedBean.assertionStatement}" />
<h:outputText value="#{cc.attrs.managedBean.assertionStatement}"/>
The UI shows an empty textarea and input but the outputText renders the correct value. The getAssertionStatement() is called 3 times which seems to be the correct behavior.
When I close the dialog and reopen it, everything (form element) is populated.
The dialog call (ag namespace is for composite component):
<p:dialog widgetVar="DataValueRuleDialog" modal="true" height="600" width="800">
<p:outputPanel id="DataValueRulePanel">
<ag:DataValueAssertion managedBean="#{dataValueAssertionController}" id="DataValueComposite" />
</p:outputPanel>
</p:dialog>
The composite that calls another composite:
<h:form id="DataValueForm">
<ag:assertionMetadataComponent
managedBean="#{cc.attrs.managedBean.dataValueAssertionBean.assertionMetadataBean}"
assertionStatementRows="5" />
<p:dataTable value="#{cc.attrs.managedBean.model}" var="item">
<p:column>
<f:facet name="header">Assertion Statement</f:facet>
<h:outputText rendered="#{item.profileBean.profileLocation == cc.attrs.managedBean.selectedComformanceProfile.name}" value="#{item.assertionMetadataBean.assertionStatement}" />
</p:column>
<p:column>
<p:commandButton rendered="#{item.profileBean.profileLocation == cc.attrs.managedBean.selectedComformanceProfile.name}" value="edit" immediate="true"
actionListener="#{cc.attrs.managedBean.editDataValueAssertion}" update=":DataValueComposite:DataValueForm">
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
When I remove the immediate=true the form is validated and since one of the required field (supposed to be populated) is missing, I got a validation error. This is why I have immediate=true but it should be necessary since all the items in the data table should be valid.