Primefaces - how to get a CellEditEvent column

I use straight 4.

I use an editable table, and when I edit a cell, the listener method is called by passing CellEditEvent

Like this

public void onCellEdit(CellEditEvent event) {  
    /*
     * The rowIndex here can be changed according to the sorting/filtering.

     * FilteredData starts as null, but primefaces initializes it, so you 
     * don't have to check for NPE here
     */
    int alteredRow = event.getRowIndex();
    UIColumn o = event.getColumn();

    System.out.println(this.filteredData.get(event.getRowIndex()).get(columns.get(0)));
}  

So far so good.

The event has getRowIndex ()

But it does not have getColumnIndex ().

Instead, it has a getColumn () method that returns a UIColumn object.

The problem is that when debugging, I could not find a way to get information about the columns (name, identifier, etc.)

I can hack a column to have a unique identifier like this

 <p:ajax event="cellEdit" listener="#{myMB.onCellEdit}"/>
 <c:forEach items="#{myMB.columns}" var="column" varStatus="loop">

    <p:column id="col#{loop.index}" headerText="#{column}" sortBy="#{column}" filterBy="#{column}" filterMatchMode="contains"/>

      <p:cellEditor>

       <f:facet name="output">
        <h:outputText value="#{dataRow[column]}" />
       </f:facet>

       <f:facet name="input">
        <p:inputText value="#{dataRow[column]}"  />
       </f:facet>

    </p:cellEditor>     

    </p:column>

 </c:forEach>               

But still I can't find a way to get the column id from CellEditEvent

So, assuming the cell is something that has a row and column, I should ask

How to get edited cell column in CellEditEvent?

. , - , , ?

update - , ,

org.primefaces.component.column.Column o = (org.primefaces.component.column.Column)event.getColumn();

, . : -)

+4
2

, , .

bean :

public void onCellEdit(CellEditEvent event) {  

int alteredRow = event.getRowIndex();
String column_name;
column_name=event.getColumn().getHeaderText();

 // now you can use this to identify the column we are working on.

}

getColumnId() getColumnKey() , , .

+6

p:columns, p:column - - event.getColumn() DynamicColumn, UIColumn. :

((DynamicColumn) event.getColumn()). GetIndex()

. column.isDynamic() .

.

0

Source: https://habr.com/ru/post/1527709/


All Articles