You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Rendy Tapestry <re...@gmail.com> on 2011/07/16 17:01:23 UTC

javascript & layout problem

Hi All,

I am using tapestry layout component, in page class I add @Import annotation
to import jquery library. I have another page that is being used along with
the layout component and having @Import annotation to import specific
javascript for that page. That javascript used jquery inside it, the problem
is, jQuery() is not recognized in that script. Solution I have right now, is
reimport the same jquery library in the page class, every time I need
jquery. In my opinion that is bothersome.

Here is the detail :

@Import(library = "context:javascript/jquery-1.6.2.min.js")
public class Layout
{
...
}


and
@Import(library = "context:javascript/test.js")
public class User
{
...
}

Inside test.js, I used jQuery, but an error show up telling that jQuery is
not recognized. But if I change User class to reimport jQuery the problem
solved.

@Import(library = {"context:javascript/jquery-1.6.2.min.js",
"context:javascript/test.js"})
public class User
{
...
}

Any suggestion please ?


Thanks,
Rendy.

Re: javascript & layout problem

Posted by Михаил Слободянюк <sl...@gmail.com>.
If you want include some script in *all* pages you may conribute to
MarkupRenderer
service. See org.apache.tapestry5.services.TapestryModule as example

Mihail

16 июля 2011 г. 19:05 пользователь Rendy Tapestry
<re...@gmail.com>написал:

> Hi Mihail,
>
> Thank you for your response. If that is how the correct thing should
> happened, I will accept it. I come to this question because in Tapestry 4,
> I
> am using decorator to build a template. In default.jsp I put an import to
> jquery lib once and never import it again in every page that use the
> template.
>
> Thanks,
> Rendy
>
> 2011/7/16 Михаил Слободянюк <sl...@gmail.com>
>
> > Hi, Rendy!
> >
> > You must import every used script in every page/component class same as
> > import other used java classes.
> >
> > Mihail Slobodyanuk.
> >
> > 2011/7/16 Rendy Tapestry <re...@gmail.com>
> >
> > > Hi All,
> > >
> > > I am using tapestry layout component, in page class I add @Import
> > > annotation
> > > to import jquery library. I have another page that is being used along
> > with
> > > the layout component and having @Import annotation to import specific
> > > javascript for that page. That javascript used jquery inside it, the
> > > problem
> > > is, jQuery() is not recognized in that script. Solution I have right
> now,
> > > is
> > > reimport the same jquery library in the page class, every time I need
> > > jquery. In my opinion that is bothersome.
> > >
> > > Here is the detail :
> > >
> > > @Import(library = "context:javascript/jquery-1.6.2.min.js")
> > > public class Layout
> > > {
> > > ...
> > > }
> > >
> > >
> > > and
> > > @Import(library = "context:javascript/test.js")
> > > public class User
> > > {
> > > ...
> > > }
> > >
> > > Inside test.js, I used jQuery, but an error show up telling that jQuery
> > is
> > > not recognized. But if I change User class to reimport jQuery the
> problem
> > > solved.
> > >
> > > @Import(library = {"context:javascript/jquery-1.6.2.min.js",
> > > "context:javascript/test.js"})
> > > public class User
> > > {
> > > ...
> > > }
> > >
> > > Any suggestion please ?
> > >
> > >
> > > Thanks,
> > > Rendy.
> > >
> >
>

Re: javascript & layout problem

Posted by Rendy Tapestry <re...@gmail.com>.
I was try it, but its still not working.

Thanks,
Rendy.

On Sat, Jul 16, 2011 at 11:26 PM, Taha Tapestry <ta...@gmail.com>wrote:

> Did you try directly inserting the script in layout by using script tag
> inside head tag
>
> Regards
> Taha
>
> On Jul 16, 2011, at 9:35 PM, Rendy Tapestry <re...@gmail.com>
> wrote:
>
> > Hi Mihail,
> >
> > Thank you for your response. If that is how the correct thing should
> > happened, I will accept it. I come to this question because in Tapestry
> 4, I
> > am using decorator to build a template. In default.jsp I put an import to
> > jquery lib once and never import it again in every page that use the
> > template.
> >
> > Thanks,
> > Rendy
> >
> > 2011/7/16 Михаил Слободянюк <sl...@gmail.com>
> >
> >> Hi, Rendy!
> >>
> >> You must import every used script in every page/component class same as
> >> import other used java classes.
> >>
> >> Mihail Slobodyanuk.
> >>
> >> 2011/7/16 Rendy Tapestry <re...@gmail.com>
> >>
> >>> Hi All,
> >>>
> >>> I am using tapestry layout component, in page class I add @Import
> >>> annotation
> >>> to import jquery library. I have another page that is being used along
> >> with
> >>> the layout component and having @Import annotation to import specific
> >>> javascript for that page. That javascript used jquery inside it, the
> >>> problem
> >>> is, jQuery() is not recognized in that script. Solution I have right
> now,
> >>> is
> >>> reimport the same jquery library in the page class, every time I need
> >>> jquery. In my opinion that is bothersome.
> >>>
> >>> Here is the detail :
> >>>
> >>> @Import(library = "context:javascript/jquery-1.6.2.min.js")
> >>> public class Layout
> >>> {
> >>> ...
> >>> }
> >>>
> >>>
> >>> and
> >>> @Import(library = "context:javascript/test.js")
> >>> public class User
> >>> {
> >>> ...
> >>> }
> >>>
> >>> Inside test.js, I used jQuery, but an error show up telling that jQuery
> >> is
> >>> not recognized. But if I change User class to reimport jQuery the
> problem
> >>> solved.
> >>>
> >>> @Import(library = {"context:javascript/jquery-1.6.2.min.js",
> >>> "context:javascript/test.js"})
> >>> public class User
> >>> {
> >>> ...
> >>> }
> >>>
> >>> Any suggestion please ?
> >>>
> >>>
> >>> Thanks,
> >>> Rendy.
> >>>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: javascript & layout problem

Posted by Taha Tapestry <ta...@gmail.com>.
Did you try directly inserting the script in layout by using script tag inside head tag

Regards
Taha 

On Jul 16, 2011, at 9:35 PM, Rendy Tapestry <re...@gmail.com> wrote:

> Hi Mihail,
> 
> Thank you for your response. If that is how the correct thing should
> happened, I will accept it. I come to this question because in Tapestry 4, I
> am using decorator to build a template. In default.jsp I put an import to
> jquery lib once and never import it again in every page that use the
> template.
> 
> Thanks,
> Rendy
> 
> 2011/7/16 Михаил Слободянюк <sl...@gmail.com>
> 
>> Hi, Rendy!
>> 
>> You must import every used script in every page/component class same as
>> import other used java classes.
>> 
>> Mihail Slobodyanuk.
>> 
>> 2011/7/16 Rendy Tapestry <re...@gmail.com>
>> 
>>> Hi All,
>>> 
>>> I am using tapestry layout component, in page class I add @Import
>>> annotation
>>> to import jquery library. I have another page that is being used along
>> with
>>> the layout component and having @Import annotation to import specific
>>> javascript for that page. That javascript used jquery inside it, the
>>> problem
>>> is, jQuery() is not recognized in that script. Solution I have right now,
>>> is
>>> reimport the same jquery library in the page class, every time I need
>>> jquery. In my opinion that is bothersome.
>>> 
>>> Here is the detail :
>>> 
>>> @Import(library = "context:javascript/jquery-1.6.2.min.js")
>>> public class Layout
>>> {
>>> ...
>>> }
>>> 
>>> 
>>> and
>>> @Import(library = "context:javascript/test.js")
>>> public class User
>>> {
>>> ...
>>> }
>>> 
>>> Inside test.js, I used jQuery, but an error show up telling that jQuery
>> is
>>> not recognized. But if I change User class to reimport jQuery the problem
>>> solved.
>>> 
>>> @Import(library = {"context:javascript/jquery-1.6.2.min.js",
>>> "context:javascript/test.js"})
>>> public class User
>>> {
>>> ...
>>> }
>>> 
>>> Any suggestion please ?
>>> 
>>> 
>>> Thanks,
>>> Rendy.
>>> 
>> 

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


Re: javascript & layout problem

Posted by Rendy Tapestry <re...@gmail.com>.
Hi Mihail,

Thank you for your response. If that is how the correct thing should
happened, I will accept it. I come to this question because in Tapestry 4, I
am using decorator to build a template. In default.jsp I put an import to
jquery lib once and never import it again in every page that use the
template.

Thanks,
Rendy

2011/7/16 Михаил Слободянюк <sl...@gmail.com>

> Hi, Rendy!
>
> You must import every used script in every page/component class same as
> import other used java classes.
>
> Mihail Slobodyanuk.
>
> 2011/7/16 Rendy Tapestry <re...@gmail.com>
>
> > Hi All,
> >
> > I am using tapestry layout component, in page class I add @Import
> > annotation
> > to import jquery library. I have another page that is being used along
> with
> > the layout component and having @Import annotation to import specific
> > javascript for that page. That javascript used jquery inside it, the
> > problem
> > is, jQuery() is not recognized in that script. Solution I have right now,
> > is
> > reimport the same jquery library in the page class, every time I need
> > jquery. In my opinion that is bothersome.
> >
> > Here is the detail :
> >
> > @Import(library = "context:javascript/jquery-1.6.2.min.js")
> > public class Layout
> > {
> > ...
> > }
> >
> >
> > and
> > @Import(library = "context:javascript/test.js")
> > public class User
> > {
> > ...
> > }
> >
> > Inside test.js, I used jQuery, but an error show up telling that jQuery
> is
> > not recognized. But if I change User class to reimport jQuery the problem
> > solved.
> >
> > @Import(library = {"context:javascript/jquery-1.6.2.min.js",
> > "context:javascript/test.js"})
> > public class User
> > {
> > ...
> > }
> >
> > Any suggestion please ?
> >
> >
> > Thanks,
> > Rendy.
> >
>

Re: javascript & layout problem

Posted by Михаил Слободянюк <sl...@gmail.com>.
Hi, Rendy!

You must import every used script in every page/component class same as
import other used java classes.

Mihail Slobodyanuk.

2011/7/16 Rendy Tapestry <re...@gmail.com>

> Hi All,
>
> I am using tapestry layout component, in page class I add @Import
> annotation
> to import jquery library. I have another page that is being used along with
> the layout component and having @Import annotation to import specific
> javascript for that page. That javascript used jquery inside it, the
> problem
> is, jQuery() is not recognized in that script. Solution I have right now,
> is
> reimport the same jquery library in the page class, every time I need
> jquery. In my opinion that is bothersome.
>
> Here is the detail :
>
> @Import(library = "context:javascript/jquery-1.6.2.min.js")
> public class Layout
> {
> ...
> }
>
>
> and
> @Import(library = "context:javascript/test.js")
> public class User
> {
> ...
> }
>
> Inside test.js, I used jQuery, but an error show up telling that jQuery is
> not recognized. But if I change User class to reimport jQuery the problem
> solved.
>
> @Import(library = {"context:javascript/jquery-1.6.2.min.js",
> "context:javascript/test.js"})
> public class User
> {
> ...
> }
>
> Any suggestion please ?
>
>
> Thanks,
> Rendy.
>

Re: javascript & layout problem

Posted by Josh Canfield <jo...@gmail.com>.
> Inside test.js, I used jQuery, but an error show up telling that jQuery is
> not recognized. But if I change User class to reimport jQuery the problem
> solved.


The problem sounds like the order your scripts are getting included.
When you add the import to your page it moves the jquery import before
test.js.

You might be able to use a JavaScriptStack to solve it
(http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/javascript/JavaScriptStack.html).

This thread might also help:

http://tapestry.1045711.n5.nabble.com/Javascript-include-order-td2436634.html

Instead of using the annotation use RenderSupport.addScriptLink() in
an AfterRender handler to ensure that jquery get's imported first...

Josh

On Sat, Jul 16, 2011 at 8:01 AM, Rendy Tapestry
<re...@gmail.com> wrote:
> Hi All,
>
> I am using tapestry layout component, in page class I add @Import annotation
> to import jquery library. I have another page that is being used along with
> the layout component and having @Import annotation to import specific
> javascript for that page. That javascript used jquery inside it, the problem
> is, jQuery() is not recognized in that script. Solution I have right now, is
> reimport the same jquery library in the page class, every time I need
> jquery. In my opinion that is bothersome.
>
> Here is the detail :
>
> @Import(library = "context:javascript/jquery-1.6.2.min.js")
> public class Layout
> {
> ...
> }
>
>
> and
> @Import(library = "context:javascript/test.js")
> public class User
> {
> ...
> }
>
> Inside test.js, I used jQuery, but an error show up telling that jQuery is
> not recognized. But if I change User class to reimport jQuery the problem
> solved.
>
> @Import(library = {"context:javascript/jquery-1.6.2.min.js",
> "context:javascript/test.js"})
> public class User
> {
> ...
> }
>
> Any suggestion please ?
>
>
> Thanks,
> Rendy.
>

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