簡體   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