You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paul Cantrell <ca...@pobox.com> on 2005/12/14 20:19:17 UTC

How to include Javascript with correct absolute path?

I'm trying to use Tacos, and have run into the problem of including  
dojo.

Tacos recommends I include dojo like this:

     <script type="text/javascript" src="js/dojo/dojo.js"></script>

The trick is that my pages have a custom URL structure involving  
slashes, so that the path for a page might look like this:

     /myapp/article/6738

...and instead of looking in /myapp/js/dojo/dojo.js, the browser  
tries to load the script from /myapp/article/js/dojo/dojo.js!

Of course, I can hard-code the correct full path in my JS include,  
with the initial slash, but that's an awful hack -- there's no reason  
to think that my app will always be deployed as "myapp".

I don't want to use the Script component (I think...), because it  
would actually inline the whole massive dojo script in my page, and I  
only want clients to have to download it once -- plus, it would only  
push the include path problem back one level, without actually  
solving it.

Would it work to include the script as an asset, and let Tapestry  
build the correct path for me? If so, how would I do that?

Should I just write my own ScriptAsset component...?

Or is there some other solution to this problem?

Cheers,

Paul

_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net



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


Re: How to include Javascript with correct absolute path?

Posted by Leonardo Quijano Vincenzi <le...@dtqsoftware.com>.
I have this in my Border component:

<script jwcid="@Any" type="text/javascript" src="ognl:baseURL + 
'/js/dojo/dojo.js'"></script>

And in the java file:

    @InjectObject("infrastructure:request")
    public abstract WebRequest getWebRequest();

    public String getBaseURL() {
        return getWebRequest().getContextPath();
    }

Hope it helps ;).

-- 
Ing. Leonardo Quijano Vincenzi
DTQ Software

Paul Cantrell wrote:
> I'm trying to use Tacos, and have run into the problem of including dojo.
>
> Tacos recommends I include dojo like this:
>
>     <script type="text/javascript" src="js/dojo/dojo.js"></script>
>
> The trick is that my pages have a custom URL structure involving 
> slashes, so that the path for a page might look like this:
>
>     /myapp/article/6738
>
> ...and instead of looking in /myapp/js/dojo/dojo.js, the browser tries 
> to load the script from /myapp/article/js/dojo/dojo.js!
>
> Of course, I can hard-code the correct full path in my JS include, 
> with the initial slash, but that's an awful hack -- there's no reason 
> to think that my app will always be deployed as "myapp".
>
> I don't want to use the Script component (I think...), because it 
> would actually inline the whole massive dojo script in my page, and I 
> only want clients to have to download it once -- plus, it would only 
> push the include path problem back one level, without actually solving 
> it.
>
> Would it work to include the script as an asset, and let Tapestry 
> build the correct path for me? If so, how would I do that?
>
> Should I just write my own ScriptAsset component...?
>
> Or is there some other solution to this problem?
>
> Cheers,
>
> Paul
>
> _________________________________________________________________
> Piano music podcast: http://inthehands.com
> Other interesting stuff: http://innig.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


-- 
Ing. Leonardo Quijano Vincenzi
DTQ Software



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


Re: How to include Javascript with correct absolute path?

Posted by Paul Cantrell <ca...@pobox.com>.
That does the trick!

Leonardo's suggestion also seems to work.

BTW, I think one of my app's crash reporters just sent a message to  
the list. If it did, I'm sorry about that! Weird.

On Dec 14, 2005, at 1:45 PM, Jason Suplizio wrote:

> Are you using the Shell component in your Border? That writes a  
> base tag
> that sets the path for all referenced files in the HTML relative to  
> its
> href's attribute value.
>
> On 12/14/05, Paul Cantrell <ca...@pobox.com> wrote:
>>
>> Tried it, but it doesn't help. Don't really see why it would -- the
>> problem is that the browser thinks that the current directory is "/
>> myapp/article/," and my page has no way of knowing that, so it needs
>> to specify the include as an absolute path.
>>
>>
>> On Dec 14, 2005, at 1:23 PM, Patrick Casey wrote:
>>
>>>       Did you try the swiss army knife of paths the single dot :)?
>>>
>>>       e.g.
>>>
>>>       src = "./js/dojo/dojo.js"
>>>
>>>
>>>       --- Pat
>>>
>>>> -----Original Message-----
>>>> From: Paul Cantrell [mailto:cantrell@pobox.com]
>>>> Sent: Wednesday, December 14, 2005 11:19 AM
>>>> To: Tapestry users
>>>> Subject: How to include Javascript with correct absolute path?
>>>>
>>>> I'm trying to use Tacos, and have run into the problem of including
>>>> dojo.
>>>>
>>>> Tacos recommends I include dojo like this:
>>>>
>>>>      <script type="text/javascript" src="js/dojo/dojo.js"></script>
>>>>
>>>> The trick is that my pages have a custom URL structure involving
>>>> slashes, so that the path for a page might look like this:
>>>>
>>>>      /myapp/article/6738
>>>>
>>>> ...and instead of looking in /myapp/js/dojo/dojo.js, the browser
>>>> tries to load the script from /myapp/article/js/dojo/dojo.js!
>>>>
>>>> Of course, I can hard-code the correct full path in my JS include,
>>>> with the initial slash, but that's an awful hack -- there's no  
>>>> reason
>>>> to think that my app will always be deployed as "myapp".
>>>>
>>>> I don't want to use the Script component (I think...), because it
>>>> would actually inline the whole massive dojo script in my page,  
>>>> and I
>>>> only want clients to have to download it once -- plus, it would  
>>>> only
>>>> push the include path problem back one level, without actually
>>>> solving it.
>>>>
>>>> Would it work to include the script as an asset, and let Tapestry
>>>> build the correct path for me? If so, how would I do that?
>>>>
>>>> Should I just write my own ScriptAsset component...?
>>>>
>>>> Or is there some other solution to this problem?
>>>>
>>>> Cheers,
>>>>
>>>> Paul
>>>>
>>>> _________________________________________________________________
>>>> Piano music podcast: http://inthehands.com
>>>> Other interesting stuff: http://innig.net
>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------- 
>>>> --
>>>> To unsubscribe, e-mail: tapestry-user- 
>>>> unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: tapestry-user-
>>>> help@jakarta.apache.org
>>>
>>>
>>>
>>>
>>> -------------------------------------------------------------------- 
>>> -
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tapestry-user- 
>>> help@jakarta.apache.org
>>>
>>>
>>
>> _________________________________________________________________
>> Piano music podcast: http://inthehands.com
>> Other interesting stuff: http://innig.net
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user- 
>> help@jakarta.apache.org
>>
>>

_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net



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


Re: How to include Javascript with correct absolute path?

Posted by Jason Suplizio <su...@gmail.com>.
Are you using the Shell component in your Border? That writes a base tag
that sets the path for all referenced files in the HTML relative to its
href's attribute value.

On 12/14/05, Paul Cantrell <ca...@pobox.com> wrote:
>
> Tried it, but it doesn't help. Don't really see why it would -- the
> problem is that the browser thinks that the current directory is "/
> myapp/article/," and my page has no way of knowing that, so it needs
> to specify the include as an absolute path.
>
>
> On Dec 14, 2005, at 1:23 PM, Patrick Casey wrote:
>
> >       Did you try the swiss army knife of paths the single dot :)?
> >
> >       e.g.
> >
> >       src = "./js/dojo/dojo.js"
> >
> >
> >       --- Pat
> >
> >> -----Original Message-----
> >> From: Paul Cantrell [mailto:cantrell@pobox.com]
> >> Sent: Wednesday, December 14, 2005 11:19 AM
> >> To: Tapestry users
> >> Subject: How to include Javascript with correct absolute path?
> >>
> >> I'm trying to use Tacos, and have run into the problem of including
> >> dojo.
> >>
> >> Tacos recommends I include dojo like this:
> >>
> >>      <script type="text/javascript" src="js/dojo/dojo.js"></script>
> >>
> >> The trick is that my pages have a custom URL structure involving
> >> slashes, so that the path for a page might look like this:
> >>
> >>      /myapp/article/6738
> >>
> >> ...and instead of looking in /myapp/js/dojo/dojo.js, the browser
> >> tries to load the script from /myapp/article/js/dojo/dojo.js!
> >>
> >> Of course, I can hard-code the correct full path in my JS include,
> >> with the initial slash, but that's an awful hack -- there's no reason
> >> to think that my app will always be deployed as "myapp".
> >>
> >> I don't want to use the Script component (I think...), because it
> >> would actually inline the whole massive dojo script in my page, and I
> >> only want clients to have to download it once -- plus, it would only
> >> push the include path problem back one level, without actually
> >> solving it.
> >>
> >> Would it work to include the script as an asset, and let Tapestry
> >> build the correct path for me? If so, how would I do that?
> >>
> >> Should I just write my own ScriptAsset component...?
> >>
> >> Or is there some other solution to this problem?
> >>
> >> Cheers,
> >>
> >> Paul
> >>
> >> _________________________________________________________________
> >> Piano music podcast: http://inthehands.com
> >> Other interesting stuff: http://innig.net
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: tapestry-user-
> >> help@jakarta.apache.org
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
> _________________________________________________________________
> Piano music podcast: http://inthehands.com
> Other interesting stuff: http://innig.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: How to include Javascript with correct absolute path?

Posted by Paul Cantrell <ca...@pobox.com>.
Tried it, but it doesn't help. Don't really see why it would -- the  
problem is that the browser thinks that the current directory is "/ 
myapp/article/," and my page has no way of knowing that, so it needs  
to specify the include as an absolute path.


On Dec 14, 2005, at 1:23 PM, Patrick Casey wrote:

> 	Did you try the swiss army knife of paths the single dot :)?
>
> 	e.g.
>
> 	src = "./js/dojo/dojo.js"
>
>
> 	--- Pat
>
>> -----Original Message-----
>> From: Paul Cantrell [mailto:cantrell@pobox.com]
>> Sent: Wednesday, December 14, 2005 11:19 AM
>> To: Tapestry users
>> Subject: How to include Javascript with correct absolute path?
>>
>> I'm trying to use Tacos, and have run into the problem of including
>> dojo.
>>
>> Tacos recommends I include dojo like this:
>>
>>      <script type="text/javascript" src="js/dojo/dojo.js"></script>
>>
>> The trick is that my pages have a custom URL structure involving
>> slashes, so that the path for a page might look like this:
>>
>>      /myapp/article/6738
>>
>> ...and instead of looking in /myapp/js/dojo/dojo.js, the browser
>> tries to load the script from /myapp/article/js/dojo/dojo.js!
>>
>> Of course, I can hard-code the correct full path in my JS include,
>> with the initial slash, but that's an awful hack -- there's no reason
>> to think that my app will always be deployed as "myapp".
>>
>> I don't want to use the Script component (I think...), because it
>> would actually inline the whole massive dojo script in my page, and I
>> only want clients to have to download it once -- plus, it would only
>> push the include path problem back one level, without actually
>> solving it.
>>
>> Would it work to include the script as an asset, and let Tapestry
>> build the correct path for me? If so, how would I do that?
>>
>> Should I just write my own ScriptAsset component...?
>>
>> Or is there some other solution to this problem?
>>
>> Cheers,
>>
>> Paul
>>
>> _________________________________________________________________
>> Piano music podcast: http://inthehands.com
>> Other interesting stuff: http://innig.net
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user- 
>> help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net



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


RE: How to include Javascript with correct absolute path?

Posted by Patrick Casey <pa...@adelphia.net>.
	Did you try the swiss army knife of paths the single dot :)?

	e.g.

	src = "./js/dojo/dojo.js"


	--- Pat

> -----Original Message-----
> From: Paul Cantrell [mailto:cantrell@pobox.com]
> Sent: Wednesday, December 14, 2005 11:19 AM
> To: Tapestry users
> Subject: How to include Javascript with correct absolute path?
> 
> I'm trying to use Tacos, and have run into the problem of including
> dojo.
> 
> Tacos recommends I include dojo like this:
> 
>      <script type="text/javascript" src="js/dojo/dojo.js"></script>
> 
> The trick is that my pages have a custom URL structure involving
> slashes, so that the path for a page might look like this:
> 
>      /myapp/article/6738
> 
> ...and instead of looking in /myapp/js/dojo/dojo.js, the browser
> tries to load the script from /myapp/article/js/dojo/dojo.js!
> 
> Of course, I can hard-code the correct full path in my JS include,
> with the initial slash, but that's an awful hack -- there's no reason
> to think that my app will always be deployed as "myapp".
> 
> I don't want to use the Script component (I think...), because it
> would actually inline the whole massive dojo script in my page, and I
> only want clients to have to download it once -- plus, it would only
> push the include path problem back one level, without actually
> solving it.
> 
> Would it work to include the script as an asset, and let Tapestry
> build the correct path for me? If so, how would I do that?
> 
> Should I just write my own ScriptAsset component...?
> 
> Or is there some other solution to this problem?
> 
> Cheers,
> 
> Paul
> 
> _________________________________________________________________
> Piano music podcast: http://inthehands.com
> Other interesting stuff: http://innig.net
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org




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