concept data model selection in category seam

appears as: data model selection, data model selection
Seam in Action

This is an excerpt from Manning's book Seam in Action.

An important change had to be made to the ProfileAction component to support clickable lists. The @DataModel property is now scoped to the page context (i.e., ScopeType.PAGE) rather than the event context. In order for @DataModelSelection to capture the selected row, the original @DataModel collection must be available on postback. If the collection changes, it may cause the wrong row to be selected. This happens because the row index captured by the event no longer points to the correct row in the collection on postback. If the collection disappears altogether, the result will be a “ghost click” (see the accompanying sidebar). The latter happens because the portion of the JSF component tree that held that event is discarded and thus the event doesn’t fire. Regardless of how hard Seam searches, it won’t be able to locate the data model selection and the @DataModelSelection and @DataModelSelectionIndex annotations are helpless. UIData components (e.g., <h:dataTable>) depend on the underlying data to be stable during subsequent requests. To guarantee that the collection remains stable, you can store it in the UI component tree by scoping @DataModel to the page context, as we’ve done in this example. Always remember this point when dealing with UIData components. You have to get your DataModel to make the leap from render to postback. In the next chapter you’ll learn how conversations are even better suited to deal with this problem since they can carry data across an arbitrary number of postbacks and even non-JSF requests.