I need your help in solving the issue with the CommandButton in the dialog as I am calling a method called UpdatePrint() in the action and it is not called. The jsf page code is as follow:
<h:form id="Requests">
.
.
.
<p:commandButton update=":Requests:#{hr.dialogueName}" oncomplete="PF('#{hr.certificateDialogue}').show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{hr}" target="#{hrd.selectedRequest}"/>
</p:commandButton>
.
.
<p:dialog header="cert1" widgetVar="cert1" modal="true" showEffect="fade" hideEffect="fade" resizable="true">
<p:outputPanel id="HRCEEN" style="text-align:center;">
</p:outputPanel>
<p:commandButton value="Print" action="#{hrd.UpdatePrint}" type="button" icon="ui-icon-print" style="display:block;margin-bottom: 20px">
<p:printer target="HRCEEN"/>
</p:commandButton>
</p:dialog>
.
.
<p:dialog header="cert2" widgetVar="cert2" modal="true" showEffect="fade" hideEffect="fade" resizable="true">
<p:outputPanel id="HRSSEN" style="text-align:center;">
</p:outputPanel>
<p:commandButton value="Print" action="#{hrd.UpdatePrint}" type="button" icon="ui-icon-print" style="display:block;margin-bottom: 20px">
<p:printer target="HRSSEN"/>
</p:commandButton>
</p:dialog>
</h:form>
I tried different ways, but I wasn't successful with them as it showed me that the section in the update is not found when I am referring in the update.
<p:commandButton update=":Requests:#{hr.dialogueName}" oncomplete="PF('#{hr.certificateDialogue}').show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{hr}" target="#{hrd.selectedRequest}"/>
</p:commandButton>
The action method is not called because of the type="button" attribute - there is no submit to the server. Remove type, then the action will be triggered (the button will assume the default submit type).
Related
I'm currently implementing a data table with a delete function in prime faces. Before deleting the user confirms his decision inside a dialog: if it's a "yes", then the "current" row (aka on which the user clicked the delete button) should be deleted. Currently the last row gets deleted irrespectable of on which row delete action has been triggered:
<p:dataTable var="var" value="#{bean.list}">
//some columns
//relevant column
<p:column id="id">
<p:commandButton id="deleteButton" onclick="PF('deleteDialog').show();" />
<p:confirmDialog id="deleteDialogId" widgetVar="deleteDialog" appendTo="#form">
<p:commandButton id="confirm" onclick="PF('deleteDialog').hide();"
actionListener="#{bean.deleteRowAction(var)}" />
<p:commandButton id="cancel" onclick="PF('deleteDialog').hide();" />
</p:confirmDialog>
</p:column>
</p:dataTable>
It seems like the actionListener of confirm button cannot access the current row by only getting var as an input. If I get rid of the dialog and trigger the action listener on deleteButton instead, everything works as expected:
// works, but no dialog
<p:dataTable var="var" value="#{bean.list}">
//some columns
//relevant column
<p:column id="id">
<p:commandButton id="deleteButton" actionListener="#{bean.deleteRowAction(var)}" />
</p:column>
</p:dataTable>
I have found How can I pass selected row to commandLink inside dataTable or ui:repeat? as well as JSF Delete entity on DataTable with p:dialog but unfortunately it didn't help.
Is there a way to somehow pass "the current" table entry onto an external button?
There is an easier way to do this, by using the p:confirmDialog. This allows you to simply add p:confirm to your p:commandButton and you're done:
<h:form>
<p:dataTable var="var" value="#{bean.list}">
<p:column id="id">
<p:commandButton id="deleteButton"
action="#{bean.deleteRowAction(var)}">
<p:confirm header="Confirmation"
message="Are you sure?"
icon="pi pi-exclamation-triangle" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:confirmDialog global="true">
<p:commandButton value="Yes" type="button"
styleClass="ui-confirmdialog-yes" icon="pi pi-check" />
<p:commandButton value="No" type="button"
styleClass="ui-confirmdialog-no" icon="pi pi-times" />
</p:confirmDialog>
</h:form>
I just use confirm right inside the column:
<p:dataTable var="item" ...
<p:column headerText="Item">
<p:commandButton action="#{myBean.deleteItem(item)}">
<p:confirm header="Confirmation" message="Delete item?" icon="ui-icon-alert"/>
</p:commandButton>
</p:column>
SOLUTION
Long story short, "not empty #{pastTxModel.currentTx.xml}" should be "#{not empty pastTxModel.currentTx.xml}". Yeah, I know...
UPDATE
The problem is here:
<p:inputTextarea id="test" value="#{pastTxModel.currentTx.xml}" rendered="not empty #{pastTxModel.currentTx.xml}"></p:inputTextarea>
Long story but the solution is -
Part 1-
<h:form id="alltxform">
<p:dataTable id="tablealltx" var="transaction" value="#{transactionListModel.txList}">
<p:column>
<p:commandButton update=":alltxform:xmlDetail" action="#{transactionListModel.setSelectedTx(transaction)}">
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Detail" widgetVar="dialog">
<p:outputPanel id="xmlDetail">
<p:inputTextarea id="test" value="#{pastTxModel.currentTx.xml}" rendered="not empty #{pastTxModel.currentTx.xml}"></p:inputTextarea>
</p:outputPanel>
</p:dialog>
</h:form>
Then Change -
<p:inputTextarea id="test" value="#{pastTxModel.currentTx.xml}" rendered="not empty #{pastTxModel.currentTx.xml}"></p:inputTextarea>
To -
<p:inputTextarea id="test" value="#{pastTxModel.currentTx.xml}" rendered="#{not empty pastTxModel.currentTx.xml}"></p:inputTextarea>
You need to update the whole dialog after clicking on the button.
<p:commandButton update=":alltxform:Detail" oncomplete="PF('dialog').show()">
<f:setPropertyActionListener value="#{transaction}"
target="#{transactionListModel.selectedTx}" />
</p:commandButton>
I open a modal window when I click a button:
<p:commandLink styleClass="mr" title="#{msg.edit_book}" rendered="#{sec:areAllGranted('ROLE_ADMIN')}" onclick="dlgEditBook.show();">
<p class="edit">#{msg.edit}</p>
<f:setPropertyActionListener value="#{b}" target="#{bookDAOImpl.selectedBook}" />
</p:commandLink>
A modal window is opened, but the program does not respond to any place there:
<p:dialog id="editDialog" modal="true" widgetVar="dlgEditBook" dynamic="true" resizable="false" header="#{msg.edit_book}" closable="false">
<h:form id="formEditBook">
<p:panelGrid columns="2" columnClasses="col1, col2" styleClass="edit_book_table" >
<p:panel id="imagePanel">
<p:graphicImage value="#{imageController.defaultImage}" width="110" height="150" id="bookImage"/>
</p:panel>
</p:panelGrid>
</h:form>
</p:dialog>
imageController.defaultImage doesn't work, checked the debugger, it will not be carrying out.
I have a datatable, and at the last column I will have an edit action, it will trigger the dialog box. However, I found the value in the dialog box is not updated. Can anybody to help on this?
My code as below. In fact the bean.currentItem.name and bean.currentItem.age should base on my selection from the table. I check the bean.currentItem is not null and is refer to my selection from preEdit method, but the value never show up in p:dialog.
<p:dataTable ....>
<p:column...
<p:column...
<p:column>
<f:facet name="header">
<h:outputLabel value="Update" />
</f:facet>
<p:remoteCommand name="preEdit" action="#{bean.preEdit}"
process="#this" update="#this #form:dlg">
<f:setPropertyActionListener target="#{bean.currentItem}"
value="#{thisItem}" />
</p:remoteCommand>
<p:commandLink styleClass="no-decor"
oncomplete="preEdit();PF('dlg').show();" value="Edit"/>
</p:column>
</p:dataTable>
<p:dialog header="#{lbl.tt_cat_upd}" widgetVar="dlg" id="dlg"
resizable="false" >
<h:outputLabel value="#{bean.currentItem.name}" />
<h:outputLabel value="#{bean.currentItem.age}" />
</p:dialog>
How about removing your p:remoteCommand and let your p:commandLink do all the work for you?
Assuming you have a h:form surrounding both your dataTable and your dialog
<p:commandLink action="#{bean.preEdit}" process="#this" update="dlg" styleClass="no-decor" oncomplete="PF('dlg').show()" value="Edit">
<f:setPropertyActionListener target="#{bean.currentItem}"
value="#{thisItem}" />
</p:commandLink>
If your dataTable is not in the same form with your dialog, you might replace update="dlg" by update=":formIdContainingDialog:dlg"
I have this piece of code:
<h:body>
<h:form id="form1">
<p:menuButton value="#{msgs.settingsMenuButton}">
<p:menuitem value="#{msgs.accountsMenuItem}" url="#" update=":dlgEdit" oncomplete="_dlgEdit.show()"/>
</p:menuButton>
<p:commandButton value="Accounts" icon="ui-icon-gear"
update=":dlgEdit"
oncomplete="_dlgEdit.show()"/>
</h:form>
<p:dialog id="dlgEdit" widgetVar="_dlgEdit" modal="true" closable="true" header="Accounts">
<h:form id="frmEdit" >
<p:panelGrid id="pnlEdit" columns="2">
<p:outputLabel id="lblName" for="eName" value="Name"/>
<p:inputText id="eName" value="#{tasksBean.selectedLocation}"/>
</p:panelGrid>
</h:form>
</p:dialog>
</h:body>
The dialog is not displayed when the menuItem is selected but it works when the commandButton is pressed.
The behaviors for both are the same...
Can you support me please?
Thanks,
Andrei
Try:
oncomplete="PF('_dlgEdit').show();"