So, basically, what one can do to pop a dialog with ADF Rich Faces, is 2 simple steps:
1. Define a popup with a dialog in it
2. Set showPopupBehavior of the link or button to point to that popup.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<af:panelGroupLayout halign="center" layout="horizontal"> | |
<af:panelFormLayout rows="1"> | |
<af:commandButton text="#{msg.ADD}" id="add" | |
actionListener="#{CorpinfoBean.onAddAction}" | |
disabled="#{not empty CorpinfoBean.dirtyRows}"/> | |
<af:commandButton text="#{msg.DELETE}" id="delete"> | |
<af:showPopupBehavior popupId="confirmDelete" | |
triggerType="action" align="afterStart"/> | |
</af:commandButton> | |
<af:commandButton text="#{msg.COMMIT}" id="commit" | |
actionListener="#{CorpinfoBean.onCommitAction}"/> | |
<af:popup id="confirmDelete"> | |
<af:dialog title="#{msg.CONFIRM_DELETE_POPUP_TITLE}" | |
dialogListener="#{CorpinfoBean.dialogListener}"> | |
<af:activeOutputText value="#{msg.CONFIRM_DELETE_POPUP_MESSAGE}"/> | |
</af:dialog> | |
</af:popup> | |
</af:panelFormLayout> | |
</af:panelGroupLayout> |
Pretty simple, isn’t it? Now the question is how to achieve the same behavior per row in a table. If we set the same showPopupBehavior popupId to a command object found in a column, it won’t work and JDeveloper will mark it as an erroneous syntax (“Reference Id confirmDelete not found”). Well, the trick is that the popup should be defined inside the column, and that’s actually it. Here’s a code snippet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table varstatus="rowStat" value="#{SchedulerBean.localCollectionModel}" | |
fetchsize="25" contentdelivery="immediate" | |
rows="#{SchedulerBean.localCollectionModel.rowCount}" | |
emptytext="#{msg.SCHED_EMPTY_TABLE}" rowselection="single" width="100%" | |
var="row" rowbandinginterval="0" binding="#{SchedulerBean.schedTable}" | |
id="schedTable"> | |
<column headertext="#{msg.ACTIONS}" sortable="false" | |
inlinestyle="background-color:#{(not empty row[SchedulerBean.columns[6].label] and row[SchedulerBean.columns[6].label] eq 'RUNNING'? '#00ff00' :'')};" | |
width="#{set.ACTIONS_COLUMN_WIDTH}"> | |
<panelformlayout rows="1"> | |
<commandlink actionlistener="#{SchedulerBean.toggleStatus}" | |
id="toggleStatus"> | |
<image source="/images/start.png" | |
rendered="#{empty row[SchedulerBean.columns[6].label] or row[SchedulerBean.columns[6].label] eq 'KILLED'}"/> | |
<image source="/images/stop.png" | |
rendered="#{not empty row[SchedulerBean.columns[6].label] and row[SchedulerBean.columns[6].label] eq 'RUNNING' or row[SchedulerBean.columns[6].label] eq 'ACTIVE'}"/> | |
</commandlink> | |
<commandlink> | |
<image source="/images/delete.png"/> | |
<showpopupbehavior popupid="deleteRow" triggertype="action" | |
align="startAfter"/> | |
</commandlink> | |
<popup id="deleteRow"> | |
<dialog title="#{msg.CONFIRM_DELETE_POPUP_TITLE}" | |
dialoglistener="#{SchedulerBean.onDeleteConfirmation}"> | |
<activeoutputtext value="#{msg.CONFIRM_DELETE_POPUP_MESSAGE}"/> | |
</dialog> | |
</popup> | |
</panelformlayout> | |
</column> | |
</table> |
The method in the backing bean looks like:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void onDeleteConfirmation(oracle.adf.view.rich.event.DialogEvent de) { | |
if(de.getOutcome().equals(oracle.adf.view.rich.event.DialogEvent.Outcome.ok)) { | |
deleteSelectedRow(); | |
FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), "", "scheduler"); | |
} | |
} |
The navigation part is intended to refresh the page (there’s a global rule in the faces-config.xml for outcome “scheduler” to navigate to this page), because dialog handler doesn’t do it automatically with JSF controller.
Hope this helps!
No comments:
Post a Comment