JSF request scope with get parameter -
i know there many similar threads no mine:
i have requestscope bean:
@managedbean @requestscoped public class bean implements serializable{ private string username = ""; //managed textbox private string password = ""; //managed textbox private string id ="-"; //load parameter usual: @postconstruct public void fetchparams(){ system.out.println("fetch params"); facescontext facescontext = facescontext.getcurrentinstance(); string id = facescontext.getexternalcontext().getrequestparametermap().get("id"); if(id == null || id.length() == 0) return; setid(id); } // getters & setters public void dosomething(){ //executed when clicked on sumbit-button on jsf-site staticfunctions.dosomething(this); } }
the code following: retrieves get-parameter "id" , saves string id (confirmed string.out....).
but when method dosomething() executed , stored "id" read , returns "-" (like nothing happened).
why so?
your managedbean @requestscoped
, destroyed @ end of request. when dosomething()
executed user submitted form , started new request. should see "fetch params" twice in console because 2 beans created second request id
null
.
you can find detailed explanation 4 jsf-scopes here.
Comments
Post a Comment