Brian Long wrote:
Hi folks - newbie here with a quick question:
I'm converting JSPs to struts, and they have a lot of stuff that looks
like this:
<old>
Service managedService =
(Service) session.getAttribute("managedService");
.
.
.
<% if (group.getExpirationDate() != null) { %>
.
.
.
</old>
What's the mechanism in struts to accomplish pulling an object out of
the session and using it in a jsp?
I prefer to initialize-if-not-exists :)
<jsp:useBean id="managedService" scope="session" class="mypkg.Service" />
<c:if test="${!empty group.expirationDate}">
...
</c:if>
Of course for that last one, group needs to be in the scope as well.
I'm always hesitant to use beans with EL without first declaring them
somehow (jsp:useBean, c:set, etc.). Kind of like using a variable
without declaring it (where syntactically permissible in the language),
it can make things more difficult to understand if you just go ahead and
use session-scoped variables or other variables that automatically come
from somewhere.
So if you had an Action that did this:
request.setAttribute( "quickMessage", "This is my message." );
And you simply did this in your JSP:
<c:out value="${quickMessage}" />
or, simply
${quickMessage}
Then when somebody read your page, they'd have no idea where
quickMessage came from. If you declare it first,
<jsp:useBean id="quickMessage" scope="request" class="java.lang.String" />
You immediately know that quickMessage is just a string, and may have
existed beforehand, but will no longer exist after the request is
finished. All this without looking at the Action class.
- Scott
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]