Package de.xima.fc.gui.model.data
Class EntitySelectModel<T extends ITransferableEntity>
- 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.model.data.EntitySelectModel<T>
-
- All Implemented Interfaces:
IEntitySelectModel<T>
,Serializable
- Direct Known Subclasses:
CurrentProjectBean.EntitySelectModelImpl
,ProjectTemplateBean.EntitySelectModelImpl
public class EntitySelectModel<T extends ITransferableEntity> extends AMessaging implements IEntitySelectModel<T>
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Class<T>
entityClass
protected T
selected
-
Constructor Summary
Constructors Constructor Description EntitySelectModel(Class<T> entityClass)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description T
addNew()
Sets the currently selected model to a new model.protected void
create()
String
delete()
Do not override this method, but onlydelete(String)
.String
delete(String targetView)
Deprecated.Usedelete()
instead.protected IEntityContext
ec()
protected IGenericDao<T>
getDao()
protected T
getNew()
T
getSelected()
protected boolean
isDetached(de.xima.cmn.dao.interfaces.IEntity<Long> entity)
boolean
isNew()
void
loadLazyData()
Can be overriden to initialize lazily loaded fields on the entity.protected String
redirect(String targetView)
Deprecated.String
save()
Do not override this method, but onlysave(String, boolean, boolean)
.String
save(String targetView)
Do not override this method, but onlysave(String, boolean, boolean)
.String
save(String targetView, boolean addSuccessMessage, boolean addErrorMessage)
Deprecated.void
setSelected(T selected)
Sets the currently selected model to the given model.boolean
setSelectedById(long id)
Sets the selected model to one with the given ID.protected void
update()
void
updateSelected()
Rereads the currently model from the database, discarding any local, unsaved changes.-
Methods inherited from class de.xima.fc.gui.common.utils.msg.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, msg
-
Methods inherited from class de.xima.fc.gui.common.utils.msg.I18nUtils
getFacesContext, getLocale, rbValue, rbValue, rbValue, rbValueOrDefault, rbValueOrDefault
-
-
-
-
Field Detail
-
entityClass
protected final Class<T extends ITransferableEntity> entityClass
-
selected
protected T extends ITransferableEntity selected
-
-
Method Detail
-
addNew
public T addNew()
Description copied from interface:IEntitySelectModel
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 interfaceIEntitySelectModel<T extends ITransferableEntity>
- Returns:
- The newly created entity.
-
save
public final String save()
Do not override this method, but onlysave(String, boolean, boolean)
. Saves the currently selected model to the database. If itIEntitySelectModel.isNew()
, creates a new entry in the database, otherwise updates the existing entry.- Specified by:
save
in interfaceIEntitySelectModel<T extends ITransferableEntity>
- Returns:
- Outcome for the redirection.
-
save
public final String save(String targetView)
Do not override this method, but onlysave(String, boolean, boolean)
. Saves the currently selected model to the database. If itIEntitySelectModel.isNew()
, creates a new entry in the database, otherwise updates the existing entry. Performs a redirect to the view, if given.- Specified by:
save
in interfaceIEntitySelectModel<T extends ITransferableEntity>
- Parameters:
targetView
- If given, performs a redirect to this view if the action succeeds. Must be a name ofEnum.name()
, or a relative link.- Returns:
- Outcome for the redirection.
-
save
@Deprecated public String save(String targetView, boolean addSuccessMessage, boolean addErrorMessage)
Deprecated.Description copied from interface:IEntitySelectModel
Saves the currently selected model to the database. If itIEntitySelectModel.isNew()
, creates a new entry in the database, otherwise updates the existing entry. Performs a redirect to the view, if given.- Specified by:
save
in interfaceIEntitySelectModel<T extends ITransferableEntity>
- Parameters:
targetView
- If given, performs a redirect to this view if the action succeeds. Must be a name ofEnum.name()
, or a relative link.addSuccessMessage
- Whether a success message is added to the faces context (in case of success).addErrorMessage
- Whether an error message is added to the faces context (in case of an error).- Returns:
- Outcome for the redirection.
-
getSelected
public T getSelected()
- Specified by:
getSelected
in interfaceIEntitySelectModel<T extends ITransferableEntity>
- Returns:
- The currently selected model. A new model if none is selected.
-
loadLazyData
public void loadLazyData()
Description copied from interface:IEntitySelectModel
Can be overriden to initialize lazily loaded fields on the entity. By default, does not load any lazy data.- Specified by:
loadLazyData
in interfaceIEntitySelectModel<T extends ITransferableEntity>
-
setSelected
public void setSelected(T selected)
Description copied from interface:IEntitySelectModel
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 theIEntitySelectModel.getSelected()
model may not refer to the same instance as the given model.- Specified by:
setSelected
in interfaceIEntitySelectModel<T extends ITransferableEntity>
- Parameters:
selected
- The model to be selected.
-
setSelectedById
public boolean setSelectedById(long id)
Description copied from interface:IEntitySelectModel
Sets the selected model to one with the given ID. Reads the model from the database. If no such model exists, does nothing.- Specified by:
setSelectedById
in interfaceIEntitySelectModel<T extends ITransferableEntity>
- Parameters:
id
- ID of the model to be selected, as returned byIEntity.getId()
.- Returns:
- Whether the model could be selected, ie. iff an entity with the given ID exists.
-
isNew
public boolean isNew()
- Specified by:
isNew
in interfaceIEntitySelectModel<T extends ITransferableEntity>
- Returns:
- Whether the currently selected model is new, ie. whether it is persisted in the database or exists only in memory.
-
updateSelected
public void updateSelected()
Description copied from interface:IEntitySelectModel
Rereads the currently model from the database, discarding any local, unsaved changes. Does nothing iff the currently selected modelIEntitySelectModel.isNew()
.- Specified by:
updateSelected
in interfaceIEntitySelectModel<T extends ITransferableEntity>
-
delete
public final String delete()
Do not override this method, but onlydelete(String)
. Deletes the currently selected model from the database. If the currently selected modelIEntitySelectModel.isNew()
, does nothing.- Specified by:
delete
in interfaceIEntitySelectModel<T extends ITransferableEntity>
- Returns:
- A view ID of the page to show after the model was deleted.
-
delete
@Deprecated public String delete(String targetView)
Deprecated.Usedelete()
instead.Description copied from interface:IEntitySelectModel
Deletes the currently selected model from the database. If the currently selected modelIEntitySelectModel.isNew()
, does nothing.- Specified by:
delete
in interfaceIEntitySelectModel<T extends ITransferableEntity>
- Parameters:
targetView
- TheEnum.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.- Returns:
- A view ID of the page to show after the model was deleted.
-
getNew
protected T getNew()
-
create
protected void create()
-
update
protected void update()
-
getDao
protected IGenericDao<T> getDao()
-
ec
protected IEntityContext ec()
-
isDetached
protected boolean isDetached(de.xima.cmn.dao.interfaces.IEntity<Long> entity)
-
redirect
@Deprecated protected String redirect(String targetView)
Deprecated.
-
-