?
Solved

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

Posted on 2003-04-01
17
Medium Priority
?
233 Views
Last Modified: 2010-05-19
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
Comment
Question by:ssherlock
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
17 Comments
 
LVL 3

Expert Comment

by:paskal
ID: 8245754
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
 
LVL 19

Expert Comment

by:cheekycj
ID: 8245823
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
 

Author Comment

by:ssherlock
ID: 8246060
Thanks both, but any ideas how to do it in a more struts-like way?
0
Independent Software Vendors: 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!

 

Author Comment

by:ssherlock
ID: 8246110
Thanks both, but any ideas how to do it in a more struts-like way?
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 8246197
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 8246231
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
 
LVL 19

Expert Comment

by:cheekycj
ID: 8246250
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8246382
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
 

Author Comment

by:ssherlock
ID: 8246511
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
 
LVL 19

Expert Comment

by:cheekycj
ID: 8246538
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
 

Author Comment

by:ssherlock
ID: 8246662
<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
 

Author Comment

by:ssherlock
ID: 8246731
<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
 

Author Comment

by:ssherlock
ID: 8246784
<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
 

Author Comment

by:ssherlock
ID: 8246829
<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
 
LVL 19

Accepted Solution

by:
cheekycj earned 1000 total points
ID: 8246837
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
 

Author Comment

by:ssherlock
ID: 8247388
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
 
LVL 19

Expert Comment

by:cheekycj
ID: 8247427
glad u figured it out.  Thanx for the "A"

CJ
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question