• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP accessing data stored in Managed Bean

 
Saria Smalls
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a xhtml webform using JSF. The textbox inputs seems to be setting to the properties defined in the bean fine. My problem is trying to access the properties in a JSP page. After the user submits the form I need the JSP file to retrieve the data from the bean and output the data for confirmation. My output keeps displaying null. Any suggestions?
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

When you save the data, what are you returning? The page or null? Ideally if returning the page, the page's data get cleared. If null the data is still there. Also this applies to session scope or view scope for the managed bean. I doubt it works for request scope.
 
Saria Smalls
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I click the submit button the JSP page loads but the output shows "null" . I use the following code in my JSP to obtain the bean data:
<jsp:useBean id="Reg" class="RegistrationBean" scope="request" > </jsp:useBean>
<jsp:setProperty name="Reg" property="*" />

Then

<%=Reg.getFirstName()%> (this is what shows as "null")

Could the problem be the way Im accessing the page? In the Xhtml file I use JSF form tags and within the h:commandButton tag I set the action attribute to the JSP file.

Its getting lost between the JSF and JSP. I played around with the scope and still have the same problem.
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait a minute. If you are doing JSF, why need to use <jsp:useBean>? Actually you shouldn't need to use any jsp tags.

In JSF you can access the bean's methods and attributes by the name you give to the bean.



 
Saria Smalls
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <jsp:useBean> tag is used in my JSP file. Im using both JSP and JSF. But I figured it out. The problem was the id I used when referencing the bean. By default the id is the name of the bean starting with a lowercase letter. By making up my own id I was creating a new instance of the bean instead of referencing the one that already exists. I was using different ids in both files when they should have been the same and the default id name.

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!