繁体   English   中英

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

[英]How to change the attribute value of a table on click of button in ADF

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

本文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”值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM