Question about OGNL in JSP

View: New views
3 Messages — Rating Filter:   Alert me  

Question about OGNL in JSP

by Oscar Calderón-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi to all, this is my first question here. I have a doubt about the use of
OGNL expressions on JSP to access to an object that i declared in a
scriptlet in the same JSP.

I have the following code:

<%
   AnObject obj = request.getSession().getAttribute(AnObject.OBJECT_NAME);

%>

<s:if test="#attr['obj'].usuario.sesionAnonima == true">
                                        visitor
                                    </s:if>
                                    <s:else>
                                        something else
                                    </s:else>

I read in some books that when you call attr it searches in the page and
other scopes to find the variable that you specify, in my case obj, but it
doesn't find it. This is the right way to access to that object?

Re: Question about OGNL in JSP

by Musachy Barroso :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That's because creating an object in a scriptlet doesn't mean it will
be in the page context, you need to actually add it to the context.

musachy

On Mon, Nov 9, 2009 at 1:47 PM, Oscar Calderón <oscar.kalderon@...> wrote:

> Hi to all, this is my first question here. I have a doubt about the use of
> OGNL expressions on JSP to access to an object that i declared in a
> scriptlet in the same JSP.
>
> I have the following code:
>
> <%
>   AnObject obj = request.getSession().getAttribute(AnObject.OBJECT_NAME);
>
> %>
>
> <s:if test="#attr['obj'].usuario.sesionAnonima == true">
>                                        visitor
>                                    </s:if>
>                                    <s:else>
>                                        something else
>                                    </s:else>
>
> I read in some books that when you call attr it searches in the page and
> other scopes to find the variable that you specify, in my case obj, but it
> doesn't find it. This is the right way to access to that object?
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: Question about OGNL in JSP

by Oscar Calderón-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ohh ok, thanks. I googled about that and i found that i can add a variable
or Object to page context with this:

pageContext.setAttribute("obj", obj);

Thanks.

2009/11/9 Musachy Barroso <musachy@...>

> That's because creating an object in a scriptlet doesn't mean it will
> be in the page context, you need to actually add it to the context.
>
> musachy
>
> On Mon, Nov 9, 2009 at 1:47 PM, Oscar Calderón <oscar.kalderon@...>
> wrote:
> > Hi to all, this is my first question here. I have a doubt about the use
> of
> > OGNL expressions on JSP to access to an object that i declared in a
> > scriptlet in the same JSP.
> >
> > I have the following code:
> >
> > <%
> >   AnObject obj = request.getSession().getAttribute(AnObject.OBJECT_NAME);
> >
> > %>
> >
> > <s:if test="#attr['obj'].usuario.sesionAnonima == true">
> >                                        visitor
> >                                    </s:if>
> >                                    <s:else>
> >                                        something else
> >                                    </s:else>
> >
> > I read in some books that when you call attr it searches in the page and
> > other scopes to find the variable that you specify, in my case obj, but
> it
> > doesn't find it. This is the right way to access to that object?
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>


--
Visita mi blog
http://codigo-java.com
http://aeblogs.com/uiq