开发者

How do i remove a row from an icefaces datatable?

I have a simple ice:dataTable which has 2 columns, one an action column the other a string representing a regular expression. The action column has as its header an add action, and for each row a remove action. I dont really care how this works as long as it does. Right now I am attempting to mimic the icefaces composite component editableTable which requires you to select a row at which point the actions get rendered for that row then when you click an action it is applied to the selected row. So in my attempt to make this work, I created simple datatable with an rowSelector that sets my item.selected for the selected row:

    <ice:dataTable value="#{configuration.selectedTagPositiveRegexes}"
      var="item">
      <ice:column>
        <ice:rowSelector value="#{item.selected}" />
        <f:facet name="header">
          <ice:commandLink styleClass="linkBlue"
            action="#{configuration.tagRegexAdd}">
            <ice:outputText value="Add" />
          </ice:commandLink>
        </f:facet>
      开发者_开发百科  <ice:commandLink styleClass="linkBlue"
          action="#{configuration.tagRegexRemove}"
          rendered="#{item.selected}">
          <ice:outputText value="Remove" />
        </ice:commandLink>
      </ice:column>
      <ice:column>
        <f:facet name="header">
          <ice:outputText value="Regular Expression" />
        </f:facet>
        <ice:inputText value="#{item.object}" size="100" />
      </ice:column>
    </ice:dataTable>

Then in my backing bean, I have these 2 methods:

public void tagRegexAdd() {
    log.debug( "add a new regex" );
    for ( SelectableRow<String> row : selectedTagPositiveRegexes ) {
        row.selected = false;
    }
    selectedTagPositiveRegexes.add( 0, new SelectableRow<String>( "", true ) );
}

public void tagRegexRemove() {
    log.debug( "remove an existing regex" );
    int i = 0;
    int selectedIndex = -1;
    for ( SelectableRow<String> row : selectedTagPositiveRegexes ) {
        if ( row.selected ) {
            selectedIndex = i;
            row.selected = false;
        }
        i++;
    }
    if ( selectedIndex >= 0 ) {
        selectedTagPositiveRegexes.remove( selectedIndex );
    }
}

What I notice happening as I step through this code is that the getter for selectedTagPositiveRegexes is getting called 3 times when the remove action is clicked, followed by the actual remove method followed by 1 more call to the getter at which point the browser receives a response that does what I want. However, some event must have been queued by something because after returning the response, the getter gets called 3 more times after which the item after that item that was removed gets replaced with the item that was removed. I have no idea what is going on here and must have a serious misunderstanding as to how this is used, but my assumption was that the datatable, being backed by a list of elements should obtain its content from that list. That way if i add or remove to/from the list, the datatable should represent the new state. But I appear to be terribly wrong in that assumption. Any insight whatsoever as to how this is actually working will be greatly appreciated.


I haven't tried it that way, but this has worked for me.

In your managed bean, create a property of type HtmlDataTable and then use the binding attribute of ice:dataTable to point to it. Now in the callback, do this:

RowClass row=(RowClass)htmlTable.getRowData();
rowList.remove(row);

In some cases I've had to run this to make it update correctly. I believe this only when you have nested tables:

htmlTable.getChildren().clear();


Try adding a binding to the datatable, could be an (org.icefaces.ace.component.datatable.DataTable) or (HtmlDatatable)

the code will be

<ice:dataTable value="#{configuration.selectedTagPositiveRegexes}"
      var="item" binding="#{configuration.tabla}">

and the bean:

private HtmlDatatable tabla;
public void tagRegexRemove() {
 objectClass   ob = (objectClass) this.tabla.getRowData();
 this.selectedTagPositiveRegexes.remove(ob);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜