Class ItemListModel<T,​ID>

    • Field Detail

      • LOG

        protected static final org.slf4j.Logger LOG
      • all

        protected List<T> all
      • filtered

        protected List<T> filtered
      • globalFilter

        protected String globalFilter
      • hasAddNewEntity

        protected boolean hasAddNewEntity
      • marked

        protected List<T> marked
      • selected

        protected T selected
    • Constructor Detail

      • ItemListModel

        protected ItemListModel()
    • Method Detail

      • addMarked

        public void addMarked​(T entity)
        Description copied from interface: IItemListModel
        Adds the given entity to the List of marked entities
        Specified by:
        addMarked in interface IItemListModel<T>
        Parameters:
        entity - to be added
      • addNew

        public void addNew()
        Description copied from interface: IItemListModel
        Sets 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:
        addNew in interface IItemListModel<T>
      • delete

        public String delete()
        Description copied from interface: IItemListModel
        Deletes the currently selected model from the database. If the currently selected model IItemListModel.isNew(), does nothing.
        Specified by:
        delete in interface IItemListModel<T>
        Returns:
        A view ID of the page to show after the model was deleted.
      • deleteEntity

        public String deleteEntity​(T entity)
        Description copied from interface: IItemListModel
        Same as IItemListModel.delete(), but takes the model to be deleted as an argument instead of deleting the currently selected model.
        Specified by:
        deleteEntity in interface IItemListModel<T>
        Parameters:
        entity - The model to be deleted.
        Returns:
        A view ID of the page to show after the model was deleted.
      • deleteEntity

        public String deleteEntity​(String targetView,
                                   T entity)
        Description copied from interface: IItemListModel
        Same as IItemListModel.deleteEntity(Object), but takes the model to be deleted as an argument instead of deleting the currently selected model.
        Specified by:
        deleteEntity in interface IItemListModel<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.
      • getGlobalFilter

        public String getGlobalFilter()
      • setGlobalFilter

        public void setGlobalFilter​(String globalFilter)
      • getMarked

        public List<T> getMarked()
        Specified by:
        getMarked in interface IItemListModel<T>
        Returns:
        List of entities that have been marked (i.e. for further processing)
      • setMarked

        public void setMarked​(List<T> marked)
        Description copied from interface: IItemListModel
        Sets the list of marked entities
        Specified by:
        setMarked in interface IItemListModel<T>
        Parameters:
        marked - List of entities to be marked
      • getSelected

        public T getSelected()
        Specified by:
        getSelected in interface IItemListModel<T>
        Returns:
        The currently selected model. A new model if none is selected.
      • setSelected

        public void setSelected​(T selected)
        Description copied from interface: IItemListModel
        Sets 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 the IItemListModel.getSelected() model may not refer to the same instance as the given model.
        Specified by:
        setSelected in interface IItemListModel<T>
        Parameters:
        selected - The model to be selected.
      • isMarkedDeletable

        public boolean isMarkedDeletable()
        Specified by:
        isMarkedDeletable in interface IItemListModel<T>
        Returns:
        true iff every single marked entity is deletable. false otherwise
      • isNew

        public boolean isNew()
        Specified by:
        isNew in interface IItemListModel<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: IItemListModel
        Can be overridden to initialize lazily loaded fields on the entity. By default, does not load any lazy data.
        Specified by:
        loadLazyData in interface IItemListModel<T>
      • onRowSelect

        public void onRowSelect​(org.primefaces.event.SelectEvent<?> event)
        Specified by:
        onRowSelect in interface IItemListModel<T>
      • onToggleSelect

        public void onToggleSelect​(org.primefaces.event.ToggleSelectEvent event)
        Specified by:
        onToggleSelect in interface IItemListModel<T>
      • removeMarked

        public void removeMarked​(T entity)
        Description copied from interface: IItemListModel
        Removes the given entity from the List of marked entities
        Specified by:
        removeMarked in interface IItemListModel<T>
        Parameters:
        entity - to be removed
      • save

        public void save​(boolean addSuccessMessage,
                         boolean addErrorMessage)
      • save

        public void save()
        Description copied from interface: IItemListModel
        Saves the currently selected model to the database. If it IItemListModel.isNew(), creates a new entry in the database, otherwise updates the existing entry.
        Specified by:
        save in interface IItemListModel<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:
        setSelectedFromMarked in interface IItemListModel<T>
      • castTo

        protected T castTo​(Object object)
      • crudDelete

        protected abstract void crudDelete​(T item)
                                    throws Exception
        Throws:
        Exception
      • fetchAll

        protected abstract List<T> fetchAll()
                                     throws Exception
        Fetches all available entities. By default, this simple reads all entities matching the QueryCriteriaManager provided in the constructor. Override this for custom logic. If you choose to override this, you may provide null for the QueryCriteriaManager, 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

        protected abstract String findName​(T item)
      • getId

        protected abstract ID getId​(T item)
      • getNew

        protected abstract T getNew()
      • isDetached

        protected abstract boolean isDetached​(T item)
      • isPersisted

        protected abstract boolean isPersisted​(T item)
      • performDelete

        protected boolean performDelete​(T item)
      • 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

        protected void onSelectionChanged​(T selected)
        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.