Class ItemListModel<T,ID>
java.lang.Object
de.xima.fc.gui.common.utils.msg.I18nUtils
de.xima.fc.gui.common.utils.msg.MessageUtils
de.xima.fc.gui.common.utils.msg.AMessaging
de.xima.fc.gui.common.model.data.ItemListModel<T,ID>
- All Implemented Interfaces:
IItemListModel<T>, IUpdatable, Serializable
- Direct Known Subclasses:
EntityListModel, ItemListModelSelectByView
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given entity to theListof marked entitiesvoidaddNew()Sets the currently selected model to a new model.protected Tvoidcreate()protected abstract TcrudCreate(T item) protected abstract voidcrudDelete(T item) protected abstract Tprotected abstract TcrudUpdate(T item) delete()Deletes the currently selected model from the database.deleteEntity(String targetView, T entity) Same asIItemListModel.deleteEntity(Object), but takes the model to be deleted as an argument instead of deleting the currently selected model.deleteEntity(T entity) Same asIItemListModel.delete(), but takes the model to be deleted as an argument instead of deleting the currently selected model.voidDeletes all marked entitiesfetchAll()Fetches all available entities.protected abstract StringgetAll()protected abstract IDprotected abstract TgetNew()booleanprotected abstract booleanisDetached(T item) booleanbooleanbooleanbooleanisNew()protected abstract booleanisPersisted(T item) voidCan be overridden to initialize lazily loaded fields on the entity.voidonRowSelect(org.primefaces.event.SelectEvent<?> event) voidonRowSelectCheckbox(org.primefaces.event.SelectEvent<?> event) voidonRowUnselectCheckbox(org.primefaces.event.UnselectEvent<?> event) protected voidonSelectionChanged(T selected) Called when the selection changes, e.g. when a new item is selected or the selection is cleared.voidonToggleSelect(org.primefaces.event.ToggleSelectEvent event) protected booleanperformDelete(T item) voidremoveMarked(T entity) Removes the given entity from theListof marked entitiesvoidsave()Saves the currently selected model to the database.voidsave(boolean addSuccessMessage, boolean addErrorMessage) protected voidCalled when no item is selected.voidsetFiltered(List<T> filtered) Sets the list of filtered models.voidsetGlobalFilter(String globalFilter) voidsetHasAddNewEntity(boolean isNewEntity) voidSets the list of marked entitiesvoidsetSelected(T selected) Sets the currently selected model to the given model.voidIf there is exactly one entity marked, makes it the selected onevoidupdate()voidvoidRereads the currently model from the database, discarding any local, unsaved changes.Methods inherited from class MessageUtils
addErrorMsg, addErrorMsg, addErrorMsg, addErrorMsg, addErrorMsg, addErrorMsg, addErrorMsgFromString, addErrorMsgFromString, addErrorMsgToComponent, addErrorMsgToComponent, addErrorMsgToComponent, addErrorMsgToComponent, addErrorMsgToComponent, addErrorMsgToComponent, addInfoMsg, addInfoMsg, addInfoMsg, addInfoMsg, addInfoMsgFromString, addInfoMsgFromString, addInfoMsgToComponent, addInfoMsgToComponent, addInfoMsgToComponent, addInfoMsgToComponent, addMsg, addMsg, addMsg, addMsg, addMsgs, addMsgs, addMsgToComponent, addMsgToComponent, addWarnMsg, addWarnMsg, addWarnMsg, addWarnMsg, addWarnMsgFromString, addWarnMsgFromString, addWarnMsgToComponent, addWarnMsgToComponent, addWarnMsgToComponent, addWarnMsgToComponent, cleanErrorMsg, errorMsg, errorMsg, getErrorMessage, getNewErrorMsg, getNewErrorMsg, getNewErrorMsg, getNewInfoMsg, getNewInfoMsg, getNewMsg, getNewWarnMsg, getNewWarnMsg, msgMethods inherited from class I18nUtils
getFacesContext, getLocale, rbValue, rbValue, rbValue, rbValueOrDefault, rbValueOrDefault
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG -
all
-
filtered
-
globalFilter
-
hasAddNewEntity
protected boolean hasAddNewEntity -
marked
-
selected
-
-
Constructor Details
-
ItemListModel
protected ItemListModel()
-
-
Method Details
-
addMarked
Description copied from interface:IItemListModelAdds the given entity to theListof marked entities- Specified by:
addMarkedin interfaceIItemListModel<T>- Parameters:
entity- to be added
-
addNew
public void addNew()Description copied from interface:IItemListModelSets the currently selected model to a new model. A new model is not yet persisted in the database and exists only in memory.- Specified by:
addNewin interfaceIItemListModel<T>
-
create
-
delete
Description copied from interface:IItemListModelDeletes the currently selected model from the database. If the currently selected modelIItemListModel.isNew(), does nothing.- Specified by:
deletein interfaceIItemListModel<T>- Returns:
- A view ID of the page to show after the model was deleted.
-
deleteEntity
Description copied from interface:IItemListModelSame asIItemListModel.delete(), but takes the model to be deleted as an argument instead of deleting the currently selected model.- Specified by:
deleteEntityin interfaceIItemListModel<T>- Parameters:
entity- The model to be deleted.- Returns:
- A view ID of the page to show after the model was deleted.
-
deleteEntity
Description copied from interface:IItemListModelSame asIItemListModel.deleteEntity(Object), but takes the model to be deleted as an argument instead of deleting the currently selected model.- Specified by:
deleteEntityin interfaceIItemListModel<T>- Parameters:
targetView- The name of a view whose view ID is returned after this operation completes successfully. Can also be a relative path, in which case that path is returned.entity- The model to be deleted.- Returns:
- A view ID of the page to show after the model was deleted.
-
deleteMarkedEntities
public void deleteMarkedEntities()Description copied from interface:IItemListModelDeletes all marked entities- Specified by:
deleteMarkedEntitiesin interfaceIItemListModel<T>
-
getAll
- Specified by:
getAllin interfaceIItemListModel<T>- Returns:
- A list of all models, not including a #
IItemListModel.isNew(), unsaved model.
-
getAllPlusNew
- Specified by:
getAllPlusNewin interfaceIItemListModel<T>- Returns:
- A list of all models, including the #
IItemListModel.isNew(), unsaved model, if it exists.
-
getFiltered
- Specified by:
getFilteredin interfaceIItemListModel<T>- Returns:
- A subset of
IItemListModel.getAll(), with some models excluded according to some filter criterion.
-
setFiltered
Description copied from interface:IItemListModelSets the list of filtered models. This should be subset ofIItemListModel.getAll().- Specified by:
setFilteredin interfaceIItemListModel<T>- Parameters:
filtered- List of filtered models to set.
-
getGlobalFilter
-
setGlobalFilter
-
getMarked
-
setMarked
Description copied from interface:IItemListModelSets the list of marked entities- Specified by:
setMarkedin interfaceIItemListModel<T>- Parameters:
marked-Listof entities to be marked
-
getSelected
- Specified by:
getSelectedin interfaceIItemListModel<T>- Returns:
- The currently selected model. A new model if none is selected.
-
setSelected
Description copied from interface:IItemListModelSets the currently selected model to the given model. If the given model exists in the database but is not currently managed by an entity manager, rereads the model from the database. Thus theIItemListModel.getSelected()model may not refer to the same instance as the given model.- Specified by:
setSelectedin interfaceIItemListModel<T>- Parameters:
selected- The model to be selected.
-
hasEntity
public boolean hasEntity()- Specified by:
hasEntityin interfaceIItemListModel<T>- Returns:
trueiff not #IItemListModel.isEmptyList()or the currently selected modelIItemListModel.isNew().
-
isEmptyList
public boolean isEmptyList()- Specified by:
isEmptyListin interfaceIItemListModel<T>- Returns:
trueiffIItemListModel.getAll()is empty.
-
isMarkedDeletable
public boolean isMarkedDeletable()- Specified by:
isMarkedDeletablein interfaceIItemListModel<T>- Returns:
trueiff every single marked entity is deletable.falseotherwise
-
isNew
public boolean isNew()- Specified by:
isNewin interfaceIItemListModel<T>- Returns:
- Whether the currently selected model is new, ie. whether it is persisted in the database or exists only in memory.
-
loadLazyData
public void loadLazyData()Description copied from interface:IItemListModelCan be overridden to initialize lazily loaded fields on the entity. By default, does not load any lazy data.- Specified by:
loadLazyDatain interfaceIItemListModel<T>
-
onRowSelect
public void onRowSelect(org.primefaces.event.SelectEvent<?> event) - Specified by:
onRowSelectin interfaceIItemListModel<T>
-
onRowSelectCheckbox
public void onRowSelectCheckbox(org.primefaces.event.SelectEvent<?> event) - Specified by:
onRowSelectCheckboxin interfaceIItemListModel<T>
-
onRowUnselectCheckbox
public void onRowUnselectCheckbox(org.primefaces.event.UnselectEvent<?> event) - Specified by:
onRowUnselectCheckboxin interfaceIItemListModel<T>
-
onToggleSelect
public void onToggleSelect(org.primefaces.event.ToggleSelectEvent event) - Specified by:
onToggleSelectin interfaceIItemListModel<T>
-
removeMarked
Description copied from interface:IItemListModelRemoves the given entity from theListof marked entities- Specified by:
removeMarkedin interfaceIItemListModel<T>- Parameters:
entity- to be removed
-
save
public void save(boolean addSuccessMessage, boolean addErrorMessage) -
save
public void save()Description copied from interface:IItemListModelSaves the currently selected model to the database. If itIItemListModel.isNew(), creates a new entry in the database, otherwise updates the existing entry.- Specified by:
savein interfaceIItemListModel<T>
-
isHasAddNewEntity
public boolean isHasAddNewEntity() -
setHasAddNewEntity
public void setHasAddNewEntity(boolean isNewEntity) -
setSelectedFromMarked
public void setSelectedFromMarked()If there is exactly one entity marked, makes it the selected one- Specified by:
setSelectedFromMarkedin interfaceIItemListModel<T>
-
update
-
updateData
public void updateData()- Specified by:
updateDatain interfaceIUpdatable
-
updateSelected
public void updateSelected()Description copied from interface:IItemListModelRereads the currently model from the database, discarding any local, unsaved changes. Does nothing iff the currently selected modelIItemListModel.isNew().- Specified by:
updateSelectedin interfaceIItemListModel<T>
-
castTo
-
crudCreate
-
crudDelete
-
crudRead
-
crudUpdate
-
fetchAll
Fetches all available entities. By default, this simple reads all entities matching theQueryCriteriaManagerprovided in the constructor. Override this for custom logic. If you choose to override this, you may providenullfor theQueryCriteriaManager, if you do not call this super method and do not attempt to use it yourself.- Returns:
- A list with all available entities. The order of the returned list is preserved.
- Throws:
Exception
-
findName
-
getId
-
getNew
-
isDetached
-
isPersisted
-
performDelete
-
selectDefault
protected void selectDefault()Called when no item is selected. Should select the default item by calling #setSelected(Object). Defaults to selecting the first item; or a new item if no items exists. Override for custom behavior. -
onSelectionChanged
Called when the selection changes, e.g. when a new item is selected or the selection is cleared.- Parameters:
selected- The currently selected item, or null if no item is selected.
-