You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Yellek <ye...@yahoo.com> on 2008/04/29 06:51:19 UTC

Context Root for Image Button src attribute

I am trying to write an image button of the form:

<s:submit type="image" src="context-root/images/search1.gif" name="search"/>

where context-root is the configured context root of my web application. Can
anyone suggest a good way to dynamically populate the context root?

I am assuming that the src string is being interpreted via OGNL but I can't
figure out an appropriate expression to use to extract the context root from
the request.


-- 
View this message in context: http://www.nabble.com/Context-Root-for-Image-Button-src-attribute-tp16952908p16952908.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Context Root for Image Button src attribute

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Jukka Välimaa wrote:
> Getting the context path in jsp is something struts doesn't really
> support--something I've had trouble with many times. One way to get around
> the problem is scriptlet like Jim showed you. Recently, we used url tag for
> the same purpose:
>
> <s:url id="saveImg" value="/images/save.gif" />
>
> <s:submit type="image"  src="%{saveImg}" />
>
>   

I agree it's strange it's not readily available in the valuestack.  I 
avoid using it in struts tags myself.
eg. 
I'd use <input type="submit" 
src="${pageContext.request.contextPath}/images/save.gif">

You're not obliged to use struts tags.

An alternative approach is to put it into scope using JSP and the get it 
out in the struts tag.

eg.
<% pageContext.setAttribute("contextPath", request.getContextPath());%>

<s:submit type="image"  src="%{#attr.contextPath}/images/save.gif" />


I don't do that because its prone to errors whereas the former approach 
is understood by all IDEs.

If you wanted to get clever you could place it into the context using an 
interceptor (although the framework should do it, but doesn't).



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


Re: Context Root for Image Button src attribute

Posted by Jukka Välimaa <va...@gmail.com>.
Getting the context path in jsp is something struts doesn't really
support--something I've had trouble with many times. One way to get around
the problem is scriptlet like Jim showed you. Recently, we used url tag for
the same purpose:

<s:url id="saveImg" value="/images/save.gif" />

<s:submit type="image"  src="%{saveImg}" />

On Tue, Apr 29, 2008 at 3:22 PM, Jim Kiley <jh...@summa-tech.com> wrote:

> I did something like src="<%=request.getContextPath()%>/images/header.gif"
>
> On Tue, Apr 29, 2008 at 12:51 AM, Yellek <ye...@yahoo.com> wrote:
>
> >
> > I am trying to write an image button of the form:
> >
> > <s:submit type="image" src="context-root/images/search1.gif"
> > name="search"/>
> >
> > where context-root is the configured context root of my web application.
> > Can
> > anyone suggest a good way to dynamically populate the context root?
> >
> > I am assuming that the src string is being interpreted via OGNL but I
> > can't
> > figure out an appropriate expression to use to extract the context root
> > from
> > the request.
> >
> >
> > --
> > View this message in context:
> >
> http://www.nabble.com/Context-Root-for-Image-Button-src-attribute-tp16952908p16952908.html
> > Sent from the Struts - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> --
> Jim Kiley
> Technical Consultant | Summa
> [p] 412.258.3346 [m] 412.445.1729
> http://www.summa-tech.com
>

Re: Context Root for Image Button src attribute

Posted by Jim Kiley <jh...@summa-tech.com>.
I did something like src="<%=request.getContextPath()%>/images/header.gif"

On Tue, Apr 29, 2008 at 12:51 AM, Yellek <ye...@yahoo.com> wrote:

>
> I am trying to write an image button of the form:
>
> <s:submit type="image" src="context-root/images/search1.gif"
> name="search"/>
>
> where context-root is the configured context root of my web application.
> Can
> anyone suggest a good way to dynamically populate the context root?
>
> I am assuming that the src string is being interpreted via OGNL but I
> can't
> figure out an appropriate expression to use to extract the context root
> from
> the request.
>
>
> --
> View this message in context:
> http://www.nabble.com/Context-Root-for-Image-Button-src-attribute-tp16952908p16952908.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com