I write solutions to the problems I can't find much about elsewhere on the Web, also some code/script snippets that are absolutely awesome and make my life easier. Will be glad if someone finds these posts interesting and helpful!

Monday, May 3, 2010

How to add showPopupBehavior to an ADF Rich Faces table column

I didn’t see the answer to that anywhere in the manual, so I had to experiment myself. Ofc I sort of figured out how to do it pretty easily. Still this tutorial can save someone’s time, I hope.
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.
<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>
view raw gistfile1.xml hosted with ❤ by GitHub

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.
<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>
view raw gistfile1.xml hosted with ❤ by GitHub

The method in the backing bean looks like:
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");
}
}
view raw gistfile1.java hosted with ❤ by GitHub

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