Last active
August 4, 2022 11:27
-
-
Save CedricL46/31aa6d64f4b3684999e6939f9527c863 to your computer and use it in GitHub Desktop.
Check full article on https://cedricleruth.com/how-to-get-current-column-value-of-selected-richtable-row-from-iterator-in-adf/
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
//Function to call as follow : | |
//Object myValue = MyBean.getRichTableSelectedRowAttributeValue("tableID", "VoAttributeName"); | |
public Object getRichTableSelectedRowAttributeValue(String tableID, String attributeName) { | |
Object value = null; | |
RichTable richTable = (RichTable)findComponentInRoot(tableID); //part of the JSFUtils opensource class | |
if (richTable != null) { | |
ViewObject vo = getViewObjectFromTable(richTable); //part of the ADFUtils opensource class | |
if (vo != null) { | |
//Get select row from the view object | |
Row row = vo.getCurrentRow(); | |
if (row != null) { | |
//Get the attribute value from the view object row | |
value = (Object)row.getAttribute(attributeName); | |
} | |
} | |
} | |
return value; | |
} | |
//The function use the findComponentInRoot util, usually set in a bean called JSFUtils. If you don't have it already here it is: | |
/** | |
* Method find in the JSFUtils ADF toolkit : https://github.com/CedricL46/Oracle-ADF-and-JSF-Utils-libraries | |
* Locate an UIComponent in view root with its component id. Use a recursive way to achieve this. | |
* @param id UIComponent id | |
* @return UIComponent object | |
*/ | |
public static UIComponent findComponentInRoot(String id) { | |
UIComponent component = null; | |
if (id != null) { | |
FacesContext facesContext = FacesContext.getCurrentInstance(); | |
if (facesContext != null) { | |
UIComponent root = facesContext.getViewRoot(); | |
if (root != null) { | |
component = findComponent(root, id); | |
} | |
} | |
} | |
return component; | |
} | |
public static ViewObject getViewObjectFromTable(RichTable richTable) { | |
if (richTable != null) { | |
CollectionModel model = (CollectionModel)richTable.getValue(); | |
JUCtrlHierBinding treeBinding = (JUCtrlHierBinding)model.getWrappedData(); | |
return treeBinding.getDCIteratorBinding().getViewObject(); | |
} else { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment