You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alexander Baetz <ba...@arcor.de> on 2008/09/02 04:02:29 UTC

Dynamic include of a CSS stylesheet

Hi,

ok, this is not really a struts question but we came to it while 
creating tiles pages. it might be that i'm thinking wrong.

scenario:
in writing a tiles template. there i want to include an external 
stylesheet x. when an action (domain/namespace/myAction.action) is 
executed the result creates a page that uses this stylesheet.
now the problem: i want to avoid to include the stylesheet with the full 
path, including the domain. i would rather like to use the relative 
path. But how can i do that?

Correct me if i'm wrong, but the relative path differs, depending on the 
url of the action. how can i create a link to the stylesheet that works 
for all actions?

Greetings,
Alexander

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


Re: Dynamic include of a CSS stylesheet

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Roger wrote:
>> I often use:
>>
>> <link type="text/css" rel="stylesheet" href="/css/main.css">
>> <link type="text/css" rel="stylesheet"
>> href="${pageContext.request.contextPath}/css/main.css">
>> <link type="text/css" rel="stylesheet" href="${initParam.css}/main.css">
>>
>> where ${initParam.css} refers to an init param in web.xml (useful if it
>> needs to change with the deployment, such as a version number)
>>
>>     
>
> Could you point me at some code examples on how to set this up. I've a need to 
> load a different style sheet depending upon either the locale of the user, or 
> a user selected locale.
>
>   

If dealing with Locale, I'd take a different approach.  Struts2 sets the 
locale on the response object, and the i18n interceptor allows it to be 
overridden with the request_locale parameter.

So you could:

a. Reference the locale directly
eg.

<link type="text/css" rel="stylesheet" href="/css/${pageContext.response.locale}/main.css">



or b.  use the s:text tag to reference a path specified in a resource 
bundle for the current locale
eg.

<link type="text/css" rel="stylesheet" href="<s:text value="env.csspath">/main.css">

 

or c. Use Tiles and Sitemesh to include a different tile/decoration 
based on the locale (as both support this).
eg. <tiles:includeDefinition name="page.cssIncludes"/>


I don't have any non-trivial i18n experience, so there's probably better 
ways.  It really depends on what else needs to change on the page; if 
you're using a lot of s:text then that's a good approach; if you're 
using different tiles then that seems a good approach.





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


Re: Dynamic include of a CSS stylesheet

Posted by Chris Pratt <th...@gmail.com>.
I'm pretty sure that wouldn't work without modifying the Struts TLD file
since you can't use JSTL EL in <s: tags.  (*Chris*)

On Wed, Sep 3, 2008 at 5:51 AM, Martin Gainty <mg...@hotmail.com> wrote:

>
> try this
>
> <s:if test="${pageContext.request.contextPath}">
>     <link type="text/css" rel="stylesheet"
> href="${pageContext.request.contextPath}/css/main.css">
> <s:elseif test="${initParam.css}">
>    <link type="text/css" rel="stylesheet"
> href="${initParam.css}/css/main.css">
> </s:elseif>
> ?
> Martin Gainty
>
> ______________________________________________
> Disclaimer and confidentiality note
> Everything in this e-mail and any attachments relates to the official
> business of Sender. This transmission is of a confidential nature and Sender
> does not endorse distribution to any party other than intended recipient.
> Sender does not necessarily endorse content contained within this
> transmission.
>
>
> > From: roger.varley@googlemail.com
> > To: user@struts.apache.org
> > Subject: Re: Dynamic include of a CSS stylesheet
> > Date: Wed, 3 Sep 2008 14:02:10 +0300
> >
> > >
> > > I often use:
> > >
> > > <link type="text/css" rel="stylesheet" href="/css/main.css">
> > > <link type="text/css" rel="stylesheet"
> > > href="${pageContext.request.contextPath}/css/main.css">
> > > <link type="text/css" rel="stylesheet"
> href="${initParam.css}/main.css">
> > >
> > > where ${initParam.css} refers to an init param in web.xml (useful if it
> > > needs to change with the deployment, such as a version number)
> > >
> >
> > Could you point me at some code examples on how to set this up. I've a
> need to
> > load a different style sheet depending upon either the locale of the
> user, or
> > a user selected locale.
> >
> > Regards
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
>
> _________________________________________________________________
> See how Windows connects the people, information, and fun that are part of
> your life.
> http://clk.atdmt.com/MRT/go/msnnkwxp1020093175mrt/direct/01/

Re: Dynamic include of a CSS stylesheet

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Al Sutton wrote:
> Any reason not to use;
>
> <link type="text/css" rel="stylesheet" href="<s:url 
> value='/css/main.css'/>">
>
> or did I miss something?
>
> Al.

That had never occurred to me!


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


Re: Dynamic include of a CSS stylesheet

Posted by Al Sutton <al...@alsutton.com>.
Any reason not to use;

<link type="text/css" rel="stylesheet" href="<s:url value='/css/main.css'/>">

or did I miss something?

Al.


Dave Newton wrote:
> --- On Wed, 9/3/08, Martin Gainty wrote:
>   
>> <s:if test="${pageContext.request.contextPath}">
>>     
>
> I'd be worried if that test failed.
>
>   
>>     <link type="text/css" rel="stylesheet"
>>           href="${pageContext.request.contextPath}/css/main.css">
>>     
>
> </s:if>
>
> Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>   


-- 
Al Sutton

W: www.alsutton.com
B: alsutton.wordpress.com
T: twitter.com/alsutton


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


RE: Dynamic include of a CSS stylesheet

Posted by Dave Newton <ne...@yahoo.com>.
--- On Wed, 9/3/08, Martin Gainty wrote:
> <s:if test="${pageContext.request.contextPath}">

I'd be worried if that test failed.

>     <link type="text/css" rel="stylesheet"
>           href="${pageContext.request.contextPath}/css/main.css">

</s:if>

Dave


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


RE: Dynamic include of a CSS stylesheet

Posted by Martin Gainty <mg...@hotmail.com>.
try this

<s:if test="${pageContext.request.contextPath}">
    <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/css/main.css">
<s:elseif test="${initParam.css}">
    <link type="text/css" rel="stylesheet" href="${initParam.css}/css/main.css">
</s:elseif>
?
Martin Gainty 

______________________________________________ 
Disclaimer and confidentiality note 
Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. 


> From: roger.varley@googlemail.com
> To: user@struts.apache.org
> Subject: Re: Dynamic include of a CSS stylesheet
> Date: Wed, 3 Sep 2008 14:02:10 +0300
> 
> >
> > I often use:
> >
> > <link type="text/css" rel="stylesheet" href="/css/main.css">
> > <link type="text/css" rel="stylesheet"
> > href="${pageContext.request.contextPath}/css/main.css">
> > <link type="text/css" rel="stylesheet" href="${initParam.css}/main.css">
> >
> > where ${initParam.css} refers to an init param in web.xml (useful if it
> > needs to change with the deployment, such as a version number)
> >
> 
> Could you point me at some code examples on how to set this up. I've a need to 
> load a different style sheet depending upon either the locale of the user, or 
> a user selected locale.
> 
> Regards
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

_________________________________________________________________
See how Windows connects the people, information, and fun that are part of your life.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093175mrt/direct/01/

Re: Dynamic include of a CSS stylesheet

Posted by Roger <ro...@googlemail.com>.
>
> I often use:
>
> <link type="text/css" rel="stylesheet" href="/css/main.css">
> <link type="text/css" rel="stylesheet"
> href="${pageContext.request.contextPath}/css/main.css">
> <link type="text/css" rel="stylesheet" href="${initParam.css}/main.css">
>
> where ${initParam.css} refers to an init param in web.xml (useful if it
> needs to change with the deployment, such as a version number)
>

Could you point me at some code examples on how to set this up. I've a need to 
load a different style sheet depending upon either the locale of the user, or 
a user selected locale.

Regards

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


Re: Dynamic include of a CSS stylesheet

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Alexander Baetz wrote:
> Hi,
>
> ok, this is not really a struts question but we came to it while 
> creating tiles pages. it might be that i'm thinking wrong.
>
> scenario:
> in writing a tiles template. there i want to include an external 
> stylesheet x. when an action (domain/namespace/myAction.action) is 
> executed the result creates a page that uses this stylesheet.
> now the problem: i want to avoid to include the stylesheet with the 
> full path, including the domain. i would rather like to use the 
> relative path. But how can i do that?
>
> Correct me if i'm wrong, but the relative path differs, depending on 
> the url of the action. how can i create a link to the stylesheet that 
> works for all actions?
>

I often use:

<link type="text/css" rel="stylesheet" href="/css/main.css">
<link type="text/css" rel="stylesheet" 
href="${pageContext.request.contextPath}/css/main.css">
<link type="text/css" rel="stylesheet" href="${initParam.css}/main.css">

where ${initParam.css} refers to an init param in web.xml (useful if it 
needs to change with the deployment, such as a version number)



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