You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jan Kriesten <ja...@renitence.de> on 2007/07/30 19:50:21 UTC

Behaviour adding to Component body

Hi,

I have the following situation and haven't found a solution yet:

My Panel gets the following Markup from the designer:

<object wicket:id="swf" movie="res/mymovie.swf" width="200" height="150">
</object>

I'm now looking for a way to add a behaviour to the swf-MarkupContainer, which
changes the attributes/body depending on the browser. My problem is with
changing the body:

<object wicket:id="swf" width="200" height="150">
 <param name="movie" value="res/mymovie.swf" />
</object>

I only can use onComponentTag or onRendered. onRendered already closed the
object-Tag again. onComponentTag seems to be the point to start. But there
doesn't seem to be a way to have the component open tag be rendered and then
have something written to the stream...

Any hints?

Best regards, --- Jan.



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


Re: Behaviour adding to Component body

Posted by Eelco Hillenius <ee...@gmail.com>.
> i really dont think oncomponenttagbody() belongs in behaviors. this should
> be done without a behavior by subclassing the component and overriding
> oncomponenttagbody() there.

I'm also a bit afraid that exposing that would be too dangerous (not
to mention that the interface is already pretty big).

> that said you can still hack it by using
> AbstractTransformerBehavior and some string manipulation code.

Oh, first time I looked at that. That's a smart trick. Jan, even if
you can't/ don't want to use AbstractTransformerBehavior directly, you
should be able to do the trick in a similar way.

Eelco

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


Re: Behaviour adding to Component body

Posted by Eelco Hillenius <ee...@gmail.com>.
On 7/30/07, Martijn Dashorst <ma...@gmail.com> wrote:
> Yep, I was wondering why not create your own ShockWaveComponent that
> exposes the parameters using some API, and renders them using a
> repeating view?

Yeah, you could do that as well. Though directly writing them out in
onComponentTagBody would be a bit cheaper.

Eelco

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


Re: Behaviour adding to Component body

Posted by Eelco Hillenius <ee...@gmail.com>.
> yes, tried that already. strangely, <object> gets an additional
> xmlns:wicket="http://wicket.apache.org"-attribute?! but it doesn't seem to hurt.

Yeah, that happens in onComponentTag:

	public void onComponentTag(final Component component, final ComponentTag tag)
	{
		tag.put("xmlns:wicket", "http://wicket.apache.org");

What you could do is rather than extending that behavior directly,
create one from scratch that does the same thing. Just look at the
source for idea. Or we could make adding that attribute conditional
(seems to be particular for XSLT). Or decide that it doesn't hurt :)

> > Btw, if you ever get to it, a nice Flash
> > component with a demo for wicket-examples would be very welcome!
>
> Yep. :-)

That would be great!

Eelco

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


Re: Behaviour adding to Component body

Posted by Jan Kriesten <ja...@renitence.de>.
Hi Eelco,

> You should be able to pull that off if you use
> AbstractTransformerBehavior.

yes, tried that already. strangely, <object> gets an additional
xmlns:wicket="http://wicket.apache.org"-attribute?! but it doesn't seem to hurt.

> Btw, if you ever get to it, a nice Flash
> component with a demo for wicket-examples would be very welcome!

Yep. :-)

Best regards, --- Jan.



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


Re: Behaviour adding to Component body

Posted by Eelco Hillenius <ee...@gmail.com>.
> I thought I could just concentrate on the last aspect and apply only the needed
> changes... (i.e. move an attribute to a <param name...>).

You should be able to pull that off if you use
AbstractTransformerBehavior. Btw, if you ever get to it, a nice Flash
component with a demo for wicket-examples would be very welcome!

Eelco

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


Re: Behaviour adding to Component body

Posted by Jan Kriesten <ja...@renitence.de>.
Hi Martijn,

> Yep, I was wondering why not create your own ShockWaveComponent that
> exposes the parameters using some API, and renders them using a
> repeating view?

yes, I think there's no other clean way. The problem with <object></object> is,
that it allows nested/alternative content which the browsers show if the
object's content-type isn't supported (e.g. an alternative image). Second, that
different browsers need different attributes within <object> and as <param
name...>.

I thought I could just concentrate on the last aspect and apply only the needed
changes... (i.e. move an attribute to a <param name...>).

Best regards, --- Jan.



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


Re: Behaviour adding to Component body

Posted by Martijn Dashorst <ma...@gmail.com>.
Yep, I was wondering why not create your own ShockWaveComponent that
exposes the parameters using some API, and renders them using a
repeating view?

Martijn

On 7/30/07, Eelco Hillenius <ee...@gmail.com> wrote:
> > I don't think this should belong in a subclass. IMHO manipulating attributes for
> > a certain type of object should be handled by simply adding a Behaviour. SWF's
> > are only one example. Other Objects (QuickTime, Real, WMV) have other Attributes
> >  and parameter needs which is where Behaviours do what they do best:
> > manipulating them. The Problem is, that Objects aren't handled Browser
> > independend. So it's enough for FF & Co. to have a 'data'-Attribute for the SWF,
> > whereas IE needs the  <param name="movie"...> and no 'data' to have the movie
> > streamed.
> >
> > ATM it looks like this:
> >
> > WebMarkupContainer swf = new WebMarkupContainer( "swf" );
> > ResourceReference resRef = new ResourceReference( HeaderPanel.class,
> > "res/mymovie.swf" );
> > swf.add( new FlashAttributes( urlFor( resRef ).toString(), "700", "70" ) );
> > add( swf );
> >
> > It really looks messy if you subclass it and take into account the 20 other
> > parameters you could add the Object...
>
> Well, what you can do is rather than using a generic
> WebMarkupContainer, create a custom class that overrides
> onComponentTagBody, create some interface for parameters that this
> class understands, expose the ability to add instances of this
> interface, and then when the component renders, let it loop through
> these instances and print out the parameters. Sounds like a decent
> solution to me tbh. Actually more explicit than allowing to add
> behaviors that can alter the body.
>
> Eelco
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Wicket joins the Apache Software Foundation as Apache Wicket
Apache Wicket 1.3.0-beta2 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta2/

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


Re: Behaviour adding to Component body

Posted by Eelco Hillenius <ee...@gmail.com>.
> since I haven't overridden onComponentTagBody yet - what happens to child-Tags
> then, do I have to manage these, too?

If that's an issue, it's better to follow Martijn's advice and make
this component a panel with a list view for the parameters.

Eelco

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


Re: Behaviour adding to Component body

Posted by Jan Kriesten <ja...@renitence.de>.
Hi Eelco,

> Well, what you can do is rather than using a generic
> WebMarkupContainer, create a custom class that overrides
> onComponentTagBody, create some interface for parameters that this
> class understands, expose the ability to add instances of this
> interface, and then when the component renders, let it loop through
> these instances and print out the parameters. Sounds like a decent
> solution to me tbh. Actually more explicit than allowing to add
> behaviors that can alter the body.

since I haven't overridden onComponentTagBody yet - what happens to child-Tags
then, do I have to manage these, too?

E.g.:

<object wicket:id="swf" movie="res/mymovie.swf" width="200" height="150">
 <img src="res/alt-img.jpg" width="200" height="150"/>
</object>

Best regards, --- Jan.



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


Re: Behaviour adding to Component body

Posted by Eelco Hillenius <ee...@gmail.com>.
> I don't think this should belong in a subclass. IMHO manipulating attributes for
> a certain type of object should be handled by simply adding a Behaviour. SWF's
> are only one example. Other Objects (QuickTime, Real, WMV) have other Attributes
>  and parameter needs which is where Behaviours do what they do best:
> manipulating them. The Problem is, that Objects aren't handled Browser
> independend. So it's enough for FF & Co. to have a 'data'-Attribute for the SWF,
> whereas IE needs the  <param name="movie"...> and no 'data' to have the movie
> streamed.
>
> ATM it looks like this:
>
> WebMarkupContainer swf = new WebMarkupContainer( "swf" );
> ResourceReference resRef = new ResourceReference( HeaderPanel.class,
> "res/mymovie.swf" );
> swf.add( new FlashAttributes( urlFor( resRef ).toString(), "700", "70" ) );
> add( swf );
>
> It really looks messy if you subclass it and take into account the 20 other
> parameters you could add the Object...

Well, what you can do is rather than using a generic
WebMarkupContainer, create a custom class that overrides
onComponentTagBody, create some interface for parameters that this
class understands, expose the ability to add instances of this
interface, and then when the component renders, let it loop through
these instances and print out the parameters. Sounds like a decent
solution to me tbh. Actually more explicit than allowing to add
behaviors that can alter the body.

Eelco

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


Re: Behaviour adding to Component body

Posted by Igor Vaynberg <ig...@gmail.com>.
On 7/30/07, Jan Kriesten <ja...@renitence.de> wrote:
>
>
> Hi Igor,
>
> > i really dont think oncomponenttagbody() belongs in behaviors. this
> should
> > be done without a behavior by subclassing the component and overriding
> > oncomponenttagbody() there. that said you can still hack it by using
> > AbstractTransformerBehavior and some string manipulation code.
>
> I don't think this should belong in a subclass. IMHO manipulating
> attributes for
> a certain type of object should be handled by simply adding a Behaviour.


yes i agree 100%. but, you are not manipulating attributes, you are
generating additional markup int component's body.

SWF's
> are only one example. Other Objects (QuickTime, Real, WMV) have other
> Attributes
> and parameter needs which is where Behaviours do what they do best:
> manipulating them. The Problem is, that Objects aren't handled Browser
> independend. So it's enough for FF & Co. to have a 'data'-Attribute for
> the SWF,
> whereas IE needs the  <param name="movie"...> and no 'data' to have the
> movie
> streamed.
>
> ATM it looks like this:
>
> WebMarkupContainer swf = new WebMarkupContainer( "swf" );
> ResourceReference resRef = new ResourceReference( HeaderPanel.class,
> "res/mymovie.swf" );
> swf.add( new FlashAttributes( urlFor( resRef ).toString(), "700", "70" )
> );
> add( swf );
>
> It really looks messy if you subclass it and take into account the 20
> other
> parameters you could add the Object...


well the logic has to go somewhere so just do

SwfObject object=new SwfObject("swf", resRef, 700, 70); instead of putting
it into a behavior put it into a custom webmarkupcontainer subclass instead.

-igor



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

Re: Behaviour adding to Component body

Posted by Jan Kriesten <ja...@renitence.de>.
Hi Igor,

> i really dont think oncomponenttagbody() belongs in behaviors. this should
> be done without a behavior by subclassing the component and overriding
> oncomponenttagbody() there. that said you can still hack it by using
> AbstractTransformerBehavior and some string manipulation code.

I don't think this should belong in a subclass. IMHO manipulating attributes for
a certain type of object should be handled by simply adding a Behaviour. SWF's
are only one example. Other Objects (QuickTime, Real, WMV) have other Attributes
 and parameter needs which is where Behaviours do what they do best:
manipulating them. The Problem is, that Objects aren't handled Browser
independend. So it's enough for FF & Co. to have a 'data'-Attribute for the SWF,
whereas IE needs the  <param name="movie"...> and no 'data' to have the movie
streamed.

ATM it looks like this:

WebMarkupContainer swf = new WebMarkupContainer( "swf" );
ResourceReference resRef = new ResourceReference( HeaderPanel.class,
"res/mymovie.swf" );
swf.add( new FlashAttributes( urlFor( resRef ).toString(), "700", "70" ) );
add( swf );

It really looks messy if you subclass it and take into account the 20 other
parameters you could add the Object...

Best regards, --- Jan.



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


Re: Behaviour adding to Component body

Posted by Igor Vaynberg <ig...@gmail.com>.
On 7/30/07, Eelco Hillenius <ee...@gmail.com> wrote:
>
> On 7/30/07, Jan Kriesten <ja...@renitence.de> wrote:
> >
> > Hi Eelco,
> >
> > > You can use onRendered and write directly to the response using
> > > Response response = component.getResponse();
> >
> > not really. I tried that before, But that only writes the param after
> the close
> > tag which isn't what is intended. :-) Result:
> >
> > <object wicket:id="swf" width="200" height="150">
> > </object>
> > <param name="movie" value="res/mymovie.swf" />
> >
> > The param belongs inside the object-tag.
>
> Hmmm, yeah. So it looks to me like you *do* need something like
> onComponentTagBody then. Any other devs have alternatives ideas? Looks
> like a valid use case to me, though this is a pretty specific case
> that could be solved without using behaviors.


i really dont think oncomponenttagbody() belongs in behaviors. this should
be done without a behavior by subclassing the component and overriding
oncomponenttagbody() there. that said you can still hack it by using
AbstractTransformerBehavior and some string manipulation code.

-igor




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

Re: Behaviour adding to Component body

Posted by Eelco Hillenius <ee...@gmail.com>.
On 7/30/07, Jan Kriesten <ja...@renitence.de> wrote:
>
> Hi Eelco,
>
> > You can use onRendered and write directly to the response using
> > Response response = component.getResponse();
>
> not really. I tried that before, But that only writes the param after the close
> tag which isn't what is intended. :-) Result:
>
> <object wicket:id="swf" width="200" height="150">
> </object>
> <param name="movie" value="res/mymovie.swf" />
>
> The param belongs inside the object-tag.

Hmmm, yeah. So it looks to me like you *do* need something like
onComponentTagBody then. Any other devs have alternatives ideas? Looks
like a valid use case to me, though this is a pretty specific case
that could be solved without using behaviors.

Eelco

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


Re: Behaviour adding to Component body

Posted by Jan Kriesten <ja...@renitence.de>.
Hi Eelco,

> You can use onRendered and write directly to the response using
> Response response = component.getResponse();

not really. I tried that before, But that only writes the param after the close
tag which isn't what is intended. :-) Result:

<object wicket:id="swf" width="200" height="150">
</object>
<param name="movie" value="res/mymovie.swf" />

The param belongs inside the object-tag.


Best regards, --- Jan.

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


Re: Behaviour adding to Component body

Posted by Eelco Hillenius <ee...@gmail.com>.
> I only can use onComponentTag or onRendered. onRendered already closed the
> object-Tag again. onComponentTag seems to be the point to start. But there
> doesn't seem to be a way to have the component open tag be rendered and then
> have something written to the stream...

You can use onRendered and write directly to the response using
Response response = component.getResponse();

See for instance the date picker of the wicket-datetime project.

I don't think introducing onComponentTagBody would make it much better
tbh. It would be much more dangerous/ inviting for wrong usage to
expose that method. (I know you didn't suggest introducing this
method, just reflecting).

Eelco

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