1

I need to remove an element from a java.util.Set, I'm iterating over in a h:dataTable. Pretty simple, right? This is what I have (com is my set, endpoint the iteration variable):

<a4j:commandButton image="/img/delete.png"
    action="#{person.com.remove(endpoint)}"
    execute="@this" render="myTable" />

With JSF-2 implicit navigation, the boolean return value is converted via .toString() and used as the navigation outcome, which is pointless.

Sure, I can introduce another backing bean method that just swallows the return value but that seems like needless duplication. Can I avoid that, and if yes, how?

The environment has richfaces and omnifaces, so anything using convenience functions from there is fine as well.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
mabi
  • 5,279
  • 2
  • 43
  • 78

1 Answers1

1

(Ab)use the actionListener for that. It doesn't enforce navigation.

<a4j:commandButton image="/img/delete.png"
    actionListener="#{person.com.remove(endpoint)}"
    execute="@this" render="myTable" />

Only problem may be that exceptions on action listeners are not handled the same way, instead they are treated as an indication to bypass all remaining action listeners and the action, if any. They do thus not end up in an error page. Although, the remove() method is unlikely to cause an exception in this specific case. If the collection was empty, the action method would never have been enqueued in first place (or your code must be threadunsafe and the item must in the meanwhile already be removed by another thread between the queuing and the invocation of the action, but that's then not a JSF problem).

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • A'right, thanks. And no, no inter (front-end) thread communication here. That always ends badly. – mabi Nov 22 '13 at 13:36