Re: [Wicket-user] Best way to insert inline Javascript

2007-05-23 Thread Mark van Leeuwen
Thanks, that's interesting, I didn't realise that AbstractBehaviour could be
used for rendering into the html body.

I ended up overriding the DropDownChoice onRender method to get what I
wanted. In my case the script is so specific that there's little point in
creating a reusable behavior.

Thanks to everyone for their contributions. 

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:wicket-user-
> [EMAIL PROTECTED] On Behalf Of Harald Gruber
> Sent: Wednesday, 23 May 2007 5:55 PM
> To: wicket-user@lists.sourceforge.net
> Subject: Re: [Wicket-user] Best way to insert inline Javascript
> 
> 
> you could implement it as behavior and just add it to the dropdown...
> 
> have a look at my example. the javascript is composed and written in the
> "onRendered"
> method so its written out right after the component.
> 
> harald
> 
> 
>  example ---
> 
> import org.apache.wicket.Component;
> import org.apache.wicket.ResourceReference;
> import org.apache.wicket.Response;
> import org.apache.wicket.behavior.AbstractBehavior;
> import org.apache.wicket.markup.ComponentTag;
> import org.apache.wicket.markup.html.IHeaderContributor;
> import org.apache.wicket.markup.html.IHeaderResponse;
> import
> org.apache.wicket.markup.html.resources.JavascriptResourceReference;
> 
> public class RoundedCorners extends AbstractBehavior implements
> IHeaderContributor {
>   private static final long serialVersionUID = 1L;
> 
>   private String componentTag;
>   private String options;
> 
>   public RoundedCorners() {
>   this.options = "normal,all";
>   }
> 
>   public RoundedCorners(final String options) {
>   this.options = options;
>   }
> 
>   public void bind(final Component component) {
>   component.setOutputMarkupId(true);
>   }
> 
>   public void onComponentTag(final Component component, final
> ComponentTag tag) {
>   componentTag = tag.getName();
>   }
> 
>   public void onRendered(Component component) {
>   String markupId = component.getMarkupId();
>   Response response = component.getResponse();
>   response.write("\n\n");
>   response.write("<!--\n");
>   response.write("Nifty(\"");
>   response.write(componentTag);
>   response.write("#");
>   response.write(markupId);
>   response.write("\",\"");
>   response.write(options);
>   response.write("\");\n");
>   response.write(" -->\n");
>   response.write("");
>   }
> 
>   public void renderHead(IHeaderResponse response) {
>   response.renderCSSReference(new
> ResourceReference(RoundedCorners.class, "nifty.css"));
>   response.renderJavascriptReference(new
> JavascriptResourceReference(RoundedCorners.class, "nifty.js"));
>   }
> 
> }
> 
> 
> -
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> ___
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] Best way to insert inline Javascript

2007-05-23 Thread Harald Gruber

you could implement it as behavior and just add it to the dropdown...

have a look at my example. the javascript is composed and written in the 
"onRendered"
method so its written out right after the component.

harald


 example ---

import org.apache.wicket.Component;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.Response;
import org.apache.wicket.behavior.AbstractBehavior;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.IHeaderContributor;
import org.apache.wicket.markup.html.IHeaderResponse;
import org.apache.wicket.markup.html.resources.JavascriptResourceReference;

public class RoundedCorners extends AbstractBehavior implements 
IHeaderContributor {
private static final long serialVersionUID = 1L;

private String componentTag;
private String options;

public RoundedCorners() {
this.options = "normal,all";
}

public RoundedCorners(final String options) {
this.options = options;
}

public void bind(final Component component) {
component.setOutputMarkupId(true);
}

public void onComponentTag(final Component component, final 
ComponentTag tag) {
componentTag = tag.getName();
}

public void onRendered(Component component) {
String markupId = component.getMarkupId();
Response response = component.getResponse();
response.write("\n\n");
response.write("\n");
response.write("");
}

public void renderHead(IHeaderResponse response) {
response.renderCSSReference(new 
ResourceReference(RoundedCorners.class, "nifty.css"));
response.renderJavascriptReference(new 
JavascriptResourceReference(RoundedCorners.class, "nifty.js"));
}

}


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] Best way to insert inline Javascript

2007-05-23 Thread Nino Saturnino Martinez Vazquez Wael
http://www.w3schools.com/jsref/jsref_onload.asp

just insert an empty img then, although this messes the cleanness of the 
idea a bit up:(

Mark van Leeuwen wrote:
> Unfortunately onload is available only for body / img /applet type tags, not
> select.
>
> Mark
>
>   
>> -Original Message-
>> From: [EMAIL PROTECTED] [mailto:wicket-user-
>> [EMAIL PROTECTED] On Behalf Of Nino Saturnino Martinez
>> Vazquez Wael
>> Sent: Wednesday, 23 May 2007 5:42 PM
>> To: wicket-user@lists.sourceforge.net
>> Subject: Re: [Wicket-user] Best way to insert inline Javascript
>>
>> Another way could be to create the javascript component and invoke it by
>> adding a onload behavior to your dropdown, this should work?
>>
>> I've implemented a simple progress indicator this way, although I used
>> the onclick event.
>>
>> regards Nino
>>
>> Mark van Leeuwen wrote:
>> 
>>> Thanks for the suggestions but I don't like either of these solutions.
>>>
>>> First one involving the use of the label is the hack to which I have
>>>   
>> already
>> 
>>> referred. In my case I am extending DropDownChoice and it would be messy
>>>   
>> to
>> 
>>> require a special label component to go with it. I want to use just the
>>>   
>> one
>> 
>>> component. If I make it a panel, then I lose the advantage of allowing
>>>   
>> the
>> 
>>>  and  tags to be used directly.
>>>
>>> The 2nd option is also a pain. The script needs to be invoked when the
>>>   
>> page
>> 
>>> is being loaded. To invoke script in the header means calling it from
>>>   
>> body
>> 
>>> onload etc. Much simpler to just have the script inline after the
>>>   
>> component
>> 
>>> html.
>>>
>>> I am investigating now whether I might be able to by overriding
>>> DropDownChoice.onRender().
>>>
>>> Maybe a new behavior would be a more generic solution.
>>>
>>> Any other ideas would be welcome...
>>>
>>>
>>>
>>>   
>>>> -Original Message-
>>>> From: [EMAIL PROTECTED] [mailto:wicket-user-
>>>> [EMAIL PROTECTED] On Behalf Of Alex Objelean
>>>> Sent: Wednesday, 23 May 2007 5:02 PM
>>>> To: wicket-user@lists.sourceforge.net
>>>> Subject: Re: [Wicket-user] Best way to insert inline Javascript
>>>>
>>>>
>>>>
>>>> There is at least two solutions.
>>>> 1. The ideea is to use 

Re: [Wicket-user] Best way to insert inline Javascript

2007-05-23 Thread Alex Objelean

I do not see a problem with the first solution. You can use a wicket:border
to decorate your custom component with a 

Re: [Wicket-user] Best way to insert inline Javascript

2007-05-23 Thread Nino Saturnino Martinez Vazquez Wael
code sniplet:

create a panel like this:


function showProgress()
{
   ! do the stuff here!  
}




add the panel to your page(the javascript will be appended in head).

created a attributemodifier:
public class ProgressAttributeModifier extends AttributeAppender {

public ProgressAttributeModifier() {
super("onclick", true, new Model("showProgress()"), ";");

}

}

add that to your componet, this is a nice way of doing it I think.


Nino Saturnino Martinez Vazquez Wael wrote:
> Another way could be to create the javascript component and invoke it by 
> adding a onload behavior to your dropdown, this should work?
>
> I've implemented a simple progress indicator this way, although I used 
> the onclick event.
>
> regards Nino
>
> Mark van Leeuwen wrote:
>   
>> Thanks for the suggestions but I don't like either of these solutions.
>>
>> First one involving the use of the label is the hack to which I have already
>> referred. In my case I am extending DropDownChoice and it would be messy to
>> require a special label component to go with it. I want to use just the one
>> component. If I make it a panel, then I lose the advantage of allowing the
>>  and  tags to be used directly.
>>
>> The 2nd option is also a pain. The script needs to be invoked when the page
>> is being loaded. To invoke script in the header means calling it from body
>> onload etc. Much simpler to just have the script inline after the component
>> html.
>>
>> I am investigating now whether I might be able to by overriding
>> DropDownChoice.onRender().
>>
>> Maybe a new behavior would be a more generic solution.
>>
>> Any other ideas would be welcome...
>> 
>>
>>   
>> 
>>> -Original Message-
>>> From: [EMAIL PROTECTED] [mailto:wicket-user-
>>> [EMAIL PROTECTED] On Behalf Of Alex Objelean
>>> Sent: Wednesday, 23 May 2007 5:02 PM
>>> To: wicket-user@lists.sourceforge.net
>>> Subject: Re: [Wicket-user] Best way to insert inline Javascript
>>>
>>>
>>>
>>> There is at least two solutions.
>>> 1. The ideea is to use 

Re: [Wicket-user] Best way to insert inline Javascript

2007-05-23 Thread Mark van Leeuwen
Unfortunately onload is available only for body / img /applet type tags, not
select.

Mark

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:wicket-user-
> [EMAIL PROTECTED] On Behalf Of Nino Saturnino Martinez
> Vazquez Wael
> Sent: Wednesday, 23 May 2007 5:42 PM
> To: wicket-user@lists.sourceforge.net
> Subject: Re: [Wicket-user] Best way to insert inline Javascript
> 
> Another way could be to create the javascript component and invoke it by
> adding a onload behavior to your dropdown, this should work?
> 
> I've implemented a simple progress indicator this way, although I used
> the onclick event.
> 
> regards Nino
> 
> Mark van Leeuwen wrote:
> > Thanks for the suggestions but I don't like either of these solutions.
> >
> > First one involving the use of the label is the hack to which I have
> already
> > referred. In my case I am extending DropDownChoice and it would be messy
> to
> > require a special label component to go with it. I want to use just the
> one
> > component. If I make it a panel, then I lose the advantage of allowing
> the
> >  and  tags to be used directly.
> >
> > The 2nd option is also a pain. The script needs to be invoked when the
> page
> > is being loaded. To invoke script in the header means calling it from
> body
> > onload etc. Much simpler to just have the script inline after the
> component
> > html.
> >
> > I am investigating now whether I might be able to by overriding
> > DropDownChoice.onRender().
> >
> > Maybe a new behavior would be a more generic solution.
> >
> > Any other ideas would be welcome...
> >
> >
> >
> >> -Original Message-
> >> From: [EMAIL PROTECTED] [mailto:wicket-user-
> >> [EMAIL PROTECTED] On Behalf Of Alex Objelean
> >> Sent: Wednesday, 23 May 2007 5:02 PM
> >> To: wicket-user@lists.sourceforge.net
> >> Subject: Re: [Wicket-user] Best way to insert inline Javascript
> >>
> >>
> >>
> >> There is at least two solutions.
> >> 1. The ideea is to use 

Re: [Wicket-user] Best way to insert inline Javascript

2007-05-23 Thread Nino Saturnino Martinez Vazquez Wael
Another way could be to create the javascript component and invoke it by 
adding a onload behavior to your dropdown, this should work?

I've implemented a simple progress indicator this way, although I used 
the onclick event.

regards Nino

Mark van Leeuwen wrote:
> Thanks for the suggestions but I don't like either of these solutions.
>
> First one involving the use of the label is the hack to which I have already
> referred. In my case I am extending DropDownChoice and it would be messy to
> require a special label component to go with it. I want to use just the one
> component. If I make it a panel, then I lose the advantage of allowing the
>  and  tags to be used directly.
>
> The 2nd option is also a pain. The script needs to be invoked when the page
> is being loaded. To invoke script in the header means calling it from body
> onload etc. Much simpler to just have the script inline after the component
> html.
>
> I am investigating now whether I might be able to by overriding
> DropDownChoice.onRender().
>
> Maybe a new behavior would be a more generic solution.
>
> Any other ideas would be welcome...
> 
>
>   
>> -Original Message-
>> From: [EMAIL PROTECTED] [mailto:wicket-user-
>> [EMAIL PROTECTED] On Behalf Of Alex Objelean
>> Sent: Wednesday, 23 May 2007 5:02 PM
>> To: wicket-user@lists.sourceforge.net
>> Subject: Re: [Wicket-user] Best way to insert inline Javascript
>>
>>
>>
>> There is at least two solutions.
>> 1. The ideea is to use 

Re: [Wicket-user] Best way to insert inline Javascript

2007-05-23 Thread Mark van Leeuwen
Thanks for the suggestions but I don't like either of these solutions.

First one involving the use of the label is the hack to which I have already
referred. In my case I am extending DropDownChoice and it would be messy to
require a special label component to go with it. I want to use just the one
component. If I make it a panel, then I lose the advantage of allowing the
 and  tags to be used directly.

The 2nd option is also a pain. The script needs to be invoked when the page
is being loaded. To invoke script in the header means calling it from body
onload etc. Much simpler to just have the script inline after the component
html.

I am investigating now whether I might be able to by overriding
DropDownChoice.onRender().

Maybe a new behavior would be a more generic solution.

Any other ideas would be welcome...


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:wicket-user-
> [EMAIL PROTECTED] On Behalf Of Alex Objelean
> Sent: Wednesday, 23 May 2007 5:02 PM
> To: wicket-user@lists.sourceforge.net
> Subject: Re: [Wicket-user] Best way to insert inline Javascript
> 
> 
> 
> There is at least two solutions.
> 1. The ideea is to use 

Re: [Wicket-user] Best way to insert inline Javascript

2007-05-23 Thread Alex Objelean


There is at least two solutions.
1. The ideea is to use 

[Wicket-user] Best way to insert inline Javascript

2007-05-22 Thread Mark van Leeuwen
Writing my first custom component...

I want to initialise the component using inline Javascript placed
immediately after the component markup.

Searching the message archive I found one solution which is to use a label
to output the script. Seems a bit of a hack.

Is there a better way?




-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user