单击ADF中的按钮时如何更改表的属性值

时间:2018-12-19 05:48:50

标签: oracle oracle-adf

我有一个命令按钮和一个表。单击命令按钮后,我希望将一列属性值从“ P”更改为“ R”。我该如何实现?

1 个答案:

答案 0 :(得分:0)

本文https://cedricleruth.com/how-to-get-current-column-value-of-selected-richtable-row-from-iterator-in-adf/说明了如何获取所选行的特定属性值。您可以按如下方式修改代码,以将属性设置为新值:

//Function to call as follow in your button ActionEventListener : 
//setRichTableSelectedRowAttributeValue("YourTableID", "YourVoAttributeName", "R");

public void setRichTableSelectedRowAttributeValue(String tableID, String attributeName, Object newAttributeValue) {
    RichTable richTable = (RichTable)JSFUtils.findComponentInRoot(tableID);
    if (richTable != null) {
        RowKeySet rks = richTable.getSelectedRowKeys();
        Iterator it = rks.iterator();
        while (it.hasNext()) {
            List selectedRowKeyPath = (List)it.next();
            Row row = ((JUCtrlHierNodeBinding)richTable.getRowData(selectedRowKeyPath)).getRow();
            row.setAttribute(attributeName, newAttributeValue); //Be sure that the attributeName is defined in the VO to avoid errors
        }
    }
}


//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
 * 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;
}

此代码将在所选表格行的所有YourVoAttributeName列中设置“ R”值。