Link to home
Start Free TrialLog in
Avatar of ssherlock
ssherlock

asked on

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
Avatar of paskal
paskal
Flag of Netherlands image

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.
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
Avatar of ssherlock
ssherlock

ASKER

Thanks both, but any ideas how to do it in a more struts-like way?
Thanks both, but any ideas how to do it in a more struts-like way?
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
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
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"/>

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") ?
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
<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"
<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"
<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"
<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"
ASKER CERTIFIED SOLUTION
Avatar of cheekycj
cheekycj
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
glad u figured it out.  Thanx for the "A"

CJ