Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

using bean:???? (write?) to display text in a JSP

I'm new to this so bear with me...  I have a JSP file that displays text from a class in a standard JSP way ie;
<%NominalSummaryForm bean = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");%>
with the following for extracting values:
<%=bean.getScreenTitle()%>

How can I use something like <bean:?something?> to display the data instead?  

All the tutorials I've managed to find don't seem to make it simple enough (for me anyway :)

Thanks, Simon
0
ssherlock
Asked:
ssherlock
1 Solution
 
paskalCommented:
See this example:

<jsp:useBean id="loginUser" scope="session" class="com.unilever.supplychain.model.admin.User"/>
<jsp:setProperty name="loginUser" property="name" value="paskal" />
<html>
<head>
<title>Some title</title>

</head>
<body >

<jsp:getProperty name="loginUser" property="name" />
</body>
</html>


This should get you at the right track.
0
 
cheekycjCommented:
in your case it should be just this:

<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.NominalSummaryForm"/>

<jsp:getProperty name="NominalSummaryForm" property="screenTitle" />

though I would recommend changing your attribute name that you set from "NominalSummaryForm" to something that isn't identical to the class name.. something like
"summaryForm" or "sessionSummaryForm"

CJ
0
 
ssherlockAuthor Commented:
Thanks both, but any ideas how to do it in a more struts-like way?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ssherlockAuthor Commented:
Thanks both, but any ideas how to do it in a more struts-like way?
0
 
cheekycjCommented:
0
 
cheekycjCommented:
You still have to  use <jsp:useBean> to introduce a reference to an existing bean

to write out a property:

<bean:write name="NominalSummaryForm" property="screenTitle"/>

CJ
0
 
cheekycjCommented:
you may have to copy the bean over using:
<bean:define id="strutsSummaryForm" name="NominalSummaryForm" class="com.yourcompany.NominalSummaryForm"/>

<bean:write name="strutsSummaryForm" property="screenTitle"/>

CJ
0
 
kennethxuCommented:
CJ's suggest on <jsp:XXX> tag should works fine for you. but if you'd like to use struts, that's should get you on your way:

<jsp:useBean id="formBean" scope="session" class="com.yourcompany.NominalSummaryForm"/>

<bean:write name="formBean" property="screenTitle"/>

0
 
ssherlockAuthor Commented:
Thanks all, but now I can't seem to get the data out of the session (I told you I was new to this!).  How do I make use of something like:
=(NominalSummaryForm) session.getAttribute("NominalSummaryForm") ?
0
 
cheekycjCommented:
This didn't work:
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.NominalSummaryForm"/>


otherwise try this:
<%
  NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");
%>

then use

<bean:write name="summaryForm" property="screenTitle"/>

CJ
0
 
ssherlockAuthor Commented:
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.NominalSummaryForm"/> doesn't return any data but at least runs.

<%
 NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
0
 
ssherlockAuthor Commented:
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.NominalSummaryForm"/> doesn't return any data but at least runs.

<%
 NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
0
 
ssherlockAuthor Commented:
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.NominalSummaryForm"/> doesn't return any data but at least runs.

<%
 NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
0
 
ssherlockAuthor Commented:
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.NominalSummaryForm"/> doesn't return any data but at least runs.

<%
 NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
0
 
cheekycjCommented:
try this:
<%
NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");
%>

<bean:define id="strutsSummaryForm" name="summaryForm" class="com.yourcompany.NominalSummaryForm"/>

<bean:write name="strutsSummaryForm" property="screenTitle"/>

But is there a reason why you don't want to use getProperty and want to use Struts for writing.

CJ
0
 
ssherlockAuthor Commented:
Thanks, bean:define did the trick though the actual syntax was:
<bean:define id="Test" name="NominalSummaryForm" scope="session" toScope="page" type="com.pnc.visor.form.NominalSummaryForm" />

The only reason for not using getProperty is because we want to use the Struts way (and it's less typing :)

Thanks for your help.
0
 
cheekycjCommented:
glad u figured it out.  Thanx for the "A"

CJ
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now