我有几个托管bean(ViewScoped),目前使用会话数据进行初始化。我想使用URL GET参数对它们进行初始化,以便在视图中提供要显示的实体ID的URL。类似于displayClient.xhtml?entityId=123
。
现在,在视图主实体的getter方法中,我正在考虑像这样的解决方案:
public clientModel getclientM() {
if (this.clientM == null) {
// TODO: Check for empty, non-integer or garbage parameters...
// Anything exists to "sanitize" URL parameters?
int entityId = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("entityId"));
// I guess I should check here if the logged user is authorized to
// load client entity with this entityId... anything else to check?
this.clientM = this.clientS.find(entityId);
}
return this.clientM;
}
任何最佳实践的提示或建议将不胜感激。