problem creating managed bean instance

Hai all,

In my jsp page i want to set the username and browser session id in the managed bean DemoBean.java

for that i am using code like this in gettable.jsp page

<%

String user=request.getParameter("username");

String browsersession=(HttpSession) facesContext.getCurrentInstance().getExternalContext().getSession(false).getId();

FacesContext facescontext = FacesContext.getCurrentInstance();

DemoBean demobean=(DemoBean) facesContext..getApplication().getVariableResolver().resolveVariable(facescontext,"DemoBean");

demobean.setUserName(user);

demobean.setBrowserSessionID(browsersession);

%>

So when it is creating the DemoBean object it is creating a new instance, so all the previous values are lost.

Then i tried with this code

DemoBean demobean=(DemoBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap.get("DemoBean");

When this line is executing a new instance is created demobean is created withnull value.

I want to get the current instance of DemoBean not a new instance with all previous values. So how to go for it.

[1272 byte] By [Subrat.Ranjan.Raya] at [2007-11-27 8:36:27]
# 1

If you have to use JSP, then look into the jsp:useBean tag. It will let you pick out a bean from the session or request scope that may (or may not) have already been created and put there by JSF.

I'd question what you are trying to accomplish within the JSP though. Many professionals, including myself, feel that mixing in Java code into your JSP is breaking the MVC pattern. You are putting model logic into your view layer and breaking the separation between layers (or tiers, if you prefer that term).

I have rarely found the absolute need to use JSP code inside my pages while programming with JSF. There is probably a way to accomplish what you want in the model level while using JSF.

CowKing

IamCowKinga at 2007-7-12 20:33:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...