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("Nomi nalSummary Form");%>
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
<%NominalSummaryForm bean = (NominalSummaryForm) session.getAttribute("Nomi
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
in your case it should be just this:
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.Nom inalSummar yForm"/>
<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
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.Nom
<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
ASKER
Thanks both, but any ideas how to do it in a more struts-like way?
ASKER
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
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.Nom inalSummar yForm"/>
<bean:write name="strutsSummaryForm" property="screenTitle"/>
CJ
<bean:define id="strutsSummaryForm" name="NominalSummaryForm" class="com.yourcompany.Nom
<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.Nom inalSummar yForm"/>
<bean:write name="formBean" property="screenTitle"/>
<jsp:useBean id="formBean" scope="session" class="com.yourcompany.Nom
<bean:write name="formBean" property="screenTitle"/>
ASKER
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("Nomi nalSummary Form") ?
=(NominalSummaryForm) session.getAttribute("Nomi
This didn't work:
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.Nom inalSummar yForm"/>
otherwise try this:
<%
NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("Nomi nalSummary Form");
%>
then use
<bean:write name="summaryForm" property="screenTitle"/>
CJ
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.Nom
otherwise try this:
<%
NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("Nomi
%>
then use
<bean:write name="summaryForm" property="screenTitle"/>
CJ
ASKER
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.Nom inalSummar yForm"/> doesn't return any data but at least runs.
<%
NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("Nomi nalSummary Form");
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
<%
NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("Nomi
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
ASKER
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.Nom inalSummar yForm"/> doesn't return any data but at least runs.
<%
NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("Nomi nalSummary Form");
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
<%
NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("Nomi
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
ASKER
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.Nom inalSummar yForm"/> doesn't return any data but at least runs.
<%
NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("Nomi nalSummary Form");
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
<%
NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("Nomi
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
ASKER
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.Nom inalSummar yForm"/> doesn't return any data but at least runs.
<%
NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("Nomi nalSummary Form");
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
<%
NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("Nomi
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.N ominalSumm aryForm" />
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.
<bean:define id="Test" name="NominalSummaryForm" scope="session" toScope="page" type="com.pnc.visor.form.N
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
CJ
<jsp:useBean id="loginUser" scope="session" class="com.unilever.supply
<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.