Friday, 10 June 2011

JSF scopes guidelines (draft notes...)

Request Scope
I request page foo.xhtml?myArg=1 (with GET method)...Then in foo.xhtml or its binding bean ( I can access myArg from request scope.

Flash Scope

When you want a variable to persist after a post-back use flash.

Example: foo.xhtml has inputText with id myInputText...I hit commandButton and action/actionListener submitData() is executed...I return to foo.xhtml and want the updated value of myInputText...then in  submitData() you should save myInputText value in flash

TODO: to elaborate more with examples...

Request vs Flash Scopes
  • In request scope you can access everything included in a HTTP GET request for a new page
  • In flash scope you can access
    • same as request scope (i.e. everything in request after a HTTP GET request)
    • everything in request after a JSF postback (HTTP POST request)
    • everything in request after a redirect
How to read from / write to Request Scope
From web page:

From backing bean:
Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();

How to read from / write to Flash Scope

From web page:
 [but makes no sense]

From backing bean:

Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();

No comments:

Post a Comment