The generated default selectionListener for the table would be like selectionListener="#{bindings.EmpDeptVO.collectionModel.makeCurrent}". This will actually make the selected row as current row. As we're removing the default selectionListener, we need to call the same default selection listener method in the custom selectionListener method. Then only we can get handle to the selected row.
Sample Use Case:
Suppose I have employees table and when I select a row in the table, immediately I need to show a popup with the selected employee name. Sample application can be downloaded from here.
Implementation Steps:
1. Drop the VO as a table in the jsf page. Remove the default selectionListener and specify your own backing bean method for the selectionListener.
<af:table value="#{bindings.EmpDeptVO.collectionModel}" var="row" rows="#{bindings.EmpDeptVO.rangeSize}" emptyText="#{bindings.EmpDeptVO.viewable ? 'No data to display.' : 'Access Denied.'}" fetchSize="#{bindings.EmpDeptVO.rangeSize}" rowBandingInterval="0" rowSelection="single" id="t1" partialTriggers=":::qryId1 ::ctb1 ::commandToolbarButton1" columnStretching="column:c1" styleClass="AFStretchWidth" columnSelection="multiple" first="0" contentDelivery="immediate" autoHeightRows="10" binding="#{pageFlowScope.ExampleBean.searchResultsTable}" selectionListener="#{pageFlowScope.ExampleBean.rowSelected}">
2. In the custom selectionListener method, call the default selectionListener method which will set the selected row as the current row. We can use ADFUtil.invokeEL() to invoke the same default EL expression method and the selectionEvent as the parameter. Sample code below.
ADFUtil.invokeEL("#{bindings.EmpDeptVO.collectionModel.makeCurrent}", new Class[] { SelectionEvent.class }, new Object[] { selectionEvent });
3. Now, the selected row is set as current row and you can get the current row reference by using the below EL. Now, you can get all attributes of the selected row by using the above reference.
Row selectedRow = (Row)ADFUtil.evaluateEL("#{bindings.EmpDeptVOIterator.currentRow}");
4. Get the attribute value of Ename from the selected row and set it to a pageFlowScope variable say #{pageFlowScope.empName}. Add a popup in the jsf page that displays the #{pageFlowScope.empName} as the selected employee. Write your logic to invoke the popup in the same selectionListener method.
Popup code in the jsf page:
<af:popup id="p1" binding="#{pageFlowScope.ExampleBean.displayNamePopup}"> <af:dialog id="d1" type="ok" title="Alert"> <af:outputText value="You have selected Employee: #{pageFlowScope.empName}" id="ot4"/> </af:dialog> </af:popup>
Backing bean containing the selectionListener method and popup binding:
public class ExampleBean { private RichPopup displayNamePopup; public void rowSelected(SelectionEvent selectionEvent) { ADFUtil.invokeEL("#{bindings.EmpDeptVO.collectionModel.makeCurrent}", new Class[] { SelectionEvent.class }, new Object[] { selectionEvent }); Row selectedRow = (Row)ADFUtil.evaluateEL("#{bindings.EmpDeptVOIterator.currentRow}"); ADFUtil.setEL("#{pageFlowScope.empName}", selectedRow.getAttribute("Ename")); PopupUtil.invokePopup(displayNamePopup.getClientId(FacesContext.getCurrentInstance())); ; } public void setDisplayNamePopup(RichPopup displayNamePopup) { this.displayNamePopup = displayNamePopup; } public RichPopup getDisplayNamePopup() { return displayNamePopup; } }
That's it. When the row is selected, the selectionListener method in the bean is called, current row is set to selected row, stores the current row's Ename attribute to pageFlowScope variable 'empName', invoke the popup programatically, and the same pageFlowScope variable will be displayed in the popup as selected employee name.
Sample screen shots:
Hi, on selecting the first row it displays the correct value, when navigating to another row still it displays the old value and not fetching the new selected row, actually I can see this on your sample screen shots... is there any way we can fix??
ReplyDeleteTry setting the content delivery of the popup to lazyUncached
ReplyDeleteGreat Article. Thank you for sharing! Really an awesome post for every one.
DeleteA Reinforcement Learning based Trust Model for Cluster Size Adjustment Scheme in Distributed Cognitive Radio Networks Project For CSE
A Symmetrical Component Feature Extraction Method for Fault Detection in Induction Machines Project For CSE
CamStyle A Novel Data Augmentation Method for Person Re identification Project For CSE
Computational Intelligence Based Demand Response Management in a Microgrid Project For CSE
Continuous Visual World Modeling for Autonomous Robot Manipulation Project For CSE
Cooperative Artificial Bee Colony Algorithm with Multiple Populations for Interval Multi Objective Optimization Problems Project For CSE
Deep Learning from Noisy Image Labels with Quality Embedding Project For CSE
Deep Neuro Cognitive Co Evolution for Fuzzy Attribute Reduction by Quantum Leaping PSO With Nearest Neighbor Memeplexes Project For CSE
Hi Is there an alternative for this in JSF 1.0 . I cannot use JSF 1.2 because its an old application and quiet stable.
ReplyDeleteWow....... Awesome weblog structure.......! you make blogging look very easy. The entire glance of your site is fantastic, The content material also really nice.
ReplyDelete20170303shizhong
ReplyDeletepandora uk
red bottoms shoes
true religion jeans
adidas uk
beats headphones
louboutin uk
pandora charms
hermes handbags
christian louboutin
nike factory store
red bottoms
true religion outlet store
ReplyDeletelouboutin outlet
coach factory outlet online
cheap oakley sunglasses
adidas outlet online
michael kors outlet store
yeezy shoes
cheap oakley sunglasses
nike outlet store
moncler jackets
170511yueqin
mbt
ReplyDeletecanada goose
longchamp outlet
jordan
ralph lauren
rolex watches
nba jerseys
michael kors outlet
ray ban sunglasses
ugg outlet
20181.10wengdongdong
burberry outlet
ReplyDeletecolumbia outlet
ray ban sunglasses
jordan
michael kors handbags
bcbg
jordans
nike epic react
longchamp
moose knuckles jackets
chenyingying20180801
kobe 11
ReplyDeletecarrera sunglasses
champion
argentina world cup jersey
coach outlet online
michael kors outlet
jordan xx9
nike outlet
10 deep clothing
soccer shoes
2018.8.21chenlixiang
birkin bag
ReplyDeletecoach factory outlet
nike outlet
michael kors outlet
nike air force 1 high
russell westbrook shoes
nike epic react flyknit
off white shoes
christian louboutin shoes
jordan retro
pop over to this site look at this website read the article more helpful hints More Bonuses find out here
ReplyDelete