You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Marvan Spagnolo <ma...@gmail.com> on 2008/12/16 20:51:43 UTC

newbie help with JavascriptUtils

Hi,
I'm trying to write some javascript in a page's markup (subclass of another
page using <wicket:child>/<wicket:extend> mechanism)
via JavascriptUtils.writeJavascript().

The fact is it doesn't do anything at all nor I can't find anything related
in the stack trace (the page displays well with no exceptions nor problems
at all),
the expected javascript is simply not in the generated markup.
Before calling JavascriptUtils I add a form to the page (which works
normally as expected).

The actual code looks like:

---
public class MyPage extends MyBasePage
{
     public MyPage()
     {
         add( new MyForm( "formid" ));
         String js = "... javascript code here ...";
         JavascriptUtils.writeJavascript( getResponse(), js);
     }
}
---

Can anyone please help ? Should I maybe use something else instead of
getResponse() ?
I expected that the javascript would have been written before the
</wicket:extend> closing tag, or wherever but it's not in the markup at all.
I'm using wicket 1.3.5 on tomcat 6 and jdk 1.6.

Reza Marvan Spagnolo

Re: newbie help with JavascriptUtils

Posted by Jeremy Thomerson <je...@wickettraining.com>.
You can add JS with JavascriptUtils - but in the constructor you're not in
the render phase, so if I remember correctly, the response isn't ready to be
written to, etc.

On Tue, Dec 16, 2008 at 2:30 PM, Marvan Spagnolo <ma...@gmail.com> wrote:

> Thank you Francisco,
> I attached a behaviour to the page using the snippet you included in your
> reply as a base and that worked !
>
> I thought I could use JavascriptUtils for quickly adding js code in the
> markup but that maybe worked in previous versions of wicket or it could
> work
> in other contexts, not directly in a page.
>
> Cheers,
>
> Reza Marvan Spagnolo
>
> On Tue, Dec 16, 2008 at 8:56 PM, francisco treacy <
> francisco.treacy@gmail.com> wrote:
>
> > your page should implement IHeaderContributor
> >
> > or attach a behaviour to your components.
> >
> > for instance (first snippet i found out there):
> >
> > private static class MyJSBehavior extends AbstractBehavior {
> >       private static final long serialVersionUID = 1L;
> >       @Override
> >       public void renderHead(IHeaderResponse response) {
> >           super.renderHead(response);
> >           response.renderOnDomReadyJavascript("alert('test');");
> >       }
> >   }
> >
> >
> > this is widely documented so you should be able to find better
> > examples, but that's the way to go
> >
> > francisco
> >
> >
> > On Tue, Dec 16, 2008 at 8:51 PM, Marvan Spagnolo <ma...@gmail.com>
> > wrote:
> > > Hi,
> > > I'm trying to write some javascript in a page's markup (subclass of
> > another
> > > page using <wicket:child>/<wicket:extend> mechanism)
> > > via JavascriptUtils.writeJavascript().
> > >
> > > The fact is it doesn't do anything at all nor I can't find anything
> > related
> > > in the stack trace (the page displays well with no exceptions nor
> > problems
> > > at all),
> > > the expected javascript is simply not in the generated markup.
> > > Before calling JavascriptUtils I add a form to the page (which works
> > > normally as expected).
> > >
> > > The actual code looks like:
> > >
> > > ---
> > > public class MyPage extends MyBasePage
> > > {
> > >     public MyPage()
> > >     {
> > >         add( new MyForm( "formid" ));
> > >         String js = "... javascript code here ...";
> > >         JavascriptUtils.writeJavascript( getResponse(), js);
> > >     }
> > > }
> > > ---
> > >
> > > Can anyone please help ? Should I maybe use something else instead of
> > > getResponse() ?
> > > I expected that the javascript would have been written before the
> > > </wicket:extend> closing tag, or wherever but it's not in the markup at
> > all.
> > > I'm using wicket 1.3.5 on tomcat 6 and jdk 1.6.
> > >
> > > Reza Marvan Spagnolo
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
> --
> Reza Marvan Spagnolo
>
> SW & Network Engineer - Freelancer
> @ :: marvans@gmail.com
> m :: + 34 622 161 746
> skype :: mrvspg
>



-- 
Jeremy Thomerson
http://www.wickettraining.com

Re: newbie help with JavascriptUtils

Posted by Marvan Spagnolo <ma...@gmail.com>.
Thank you Francisco,
I attached a behaviour to the page using the snippet you included in your
reply as a base and that worked !

I thought I could use JavascriptUtils for quickly adding js code in the
markup but that maybe worked in previous versions of wicket or it could work
in other contexts, not directly in a page.

Cheers,

Reza Marvan Spagnolo

On Tue, Dec 16, 2008 at 8:56 PM, francisco treacy <
francisco.treacy@gmail.com> wrote:

> your page should implement IHeaderContributor
>
> or attach a behaviour to your components.
>
> for instance (first snippet i found out there):
>
> private static class MyJSBehavior extends AbstractBehavior {
>       private static final long serialVersionUID = 1L;
>       @Override
>       public void renderHead(IHeaderResponse response) {
>           super.renderHead(response);
>           response.renderOnDomReadyJavascript("alert('test');");
>       }
>   }
>
>
> this is widely documented so you should be able to find better
> examples, but that's the way to go
>
> francisco
>
>
> On Tue, Dec 16, 2008 at 8:51 PM, Marvan Spagnolo <ma...@gmail.com>
> wrote:
> > Hi,
> > I'm trying to write some javascript in a page's markup (subclass of
> another
> > page using <wicket:child>/<wicket:extend> mechanism)
> > via JavascriptUtils.writeJavascript().
> >
> > The fact is it doesn't do anything at all nor I can't find anything
> related
> > in the stack trace (the page displays well with no exceptions nor
> problems
> > at all),
> > the expected javascript is simply not in the generated markup.
> > Before calling JavascriptUtils I add a form to the page (which works
> > normally as expected).
> >
> > The actual code looks like:
> >
> > ---
> > public class MyPage extends MyBasePage
> > {
> >     public MyPage()
> >     {
> >         add( new MyForm( "formid" ));
> >         String js = "... javascript code here ...";
> >         JavascriptUtils.writeJavascript( getResponse(), js);
> >     }
> > }
> > ---
> >
> > Can anyone please help ? Should I maybe use something else instead of
> > getResponse() ?
> > I expected that the javascript would have been written before the
> > </wicket:extend> closing tag, or wherever but it's not in the markup at
> all.
> > I'm using wicket 1.3.5 on tomcat 6 and jdk 1.6.
> >
> > Reza Marvan Spagnolo
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Reza Marvan Spagnolo

SW & Network Engineer - Freelancer
@ :: marvans@gmail.com
m :: + 34 622 161 746
skype :: mrvspg

Re: newbie help with JavascriptUtils

Posted by francisco treacy <fr...@gmail.com>.
your page should implement IHeaderContributor

or attach a behaviour to your components.

for instance (first snippet i found out there):

private static class MyJSBehavior extends AbstractBehavior {
       private static final long serialVersionUID = 1L;
       @Override
       public void renderHead(IHeaderResponse response) {
           super.renderHead(response);
           response.renderOnDomReadyJavascript("alert('test');");
       }
   }


this is widely documented so you should be able to find better
examples, but that's the way to go

francisco


On Tue, Dec 16, 2008 at 8:51 PM, Marvan Spagnolo <ma...@gmail.com> wrote:
> Hi,
> I'm trying to write some javascript in a page's markup (subclass of another
> page using <wicket:child>/<wicket:extend> mechanism)
> via JavascriptUtils.writeJavascript().
>
> The fact is it doesn't do anything at all nor I can't find anything related
> in the stack trace (the page displays well with no exceptions nor problems
> at all),
> the expected javascript is simply not in the generated markup.
> Before calling JavascriptUtils I add a form to the page (which works
> normally as expected).
>
> The actual code looks like:
>
> ---
> public class MyPage extends MyBasePage
> {
>     public MyPage()
>     {
>         add( new MyForm( "formid" ));
>         String js = "... javascript code here ...";
>         JavascriptUtils.writeJavascript( getResponse(), js);
>     }
> }
> ---
>
> Can anyone please help ? Should I maybe use something else instead of
> getResponse() ?
> I expected that the javascript would have been written before the
> </wicket:extend> closing tag, or wherever but it's not in the markup at all.
> I'm using wicket 1.3.5 on tomcat 6 and jdk 1.6.
>
> Reza Marvan Spagnolo
>

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