Как изменить значение атрибута таблицы при нажатии кнопки в ADF - PullRequest
0 голосов
/ 19 декабря 2018

У меня есть командная кнопка и таблица.При нажатии кнопки команды я хочу, чтобы значение одного атрибута столбца было изменено с «P» на «R».Как мне этого добиться?

1 Ответ

0 голосов
/ 19 декабря 2018

В этой статье 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;
}

Этот код установит значение 'R' во все столбцы YourVoAttributeName выбранных строк таблицы.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...