Skip to content

Instantly share code, notes, and snippets.

@bertomartin
Forked from biemond/FacesContext.java
Created October 24, 2012 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bertomartin/3946898 to your computer and use it in GitHub Desktop.
Save bertomartin/3946898 to your computer and use it in GitHub Desktop.
FacesContext and ADF
// FacesContext
FacesContext facesCtx = FacesContext.getCurrentInstance();
// find UIComponent
UIComponent input = facesCtx.getViewRoot().findComponent("f1");
// change the locale
facesCtx.getViewRoot().setLocale( Locale.ENGLISH);
// el expression
Application app = facesCtx.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesCtx.getELContext();
ValueExpression valueExp = elFactory.createValueExpression(elContext,
"#{xxxx}",
Object.class);
Object result = valueExp.getValue(elContext);
// add a message
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_WARN,
"header",
"detail");
facesCtx.addMessage(input.getClientId(facesCtx), msg);
// ExternalContext
ExternalContext ectx = facesCtx.getExternalContext();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment