Wicket continues to impress me

11 12 2008

So I wanted to put in a conditional css thing to fix a IE problem, todo this thing in wicket I just though up a way. And wrote the code, it just worked:)

Heres how:
Markup (in head):

<style wicket:id="ieStyle" type="text/css">

</style>

A simple webmarkupcontainer, to put in the hack (with a resource reference)::

add(new WebMarkupContainer("ieStyle"){

@Override
protected void onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag) {
super.onComponentTagBody(markupStream, openTag);
String csshoverurl=urlFor(new ResourceReference(BasePage.class,"csshover2.htc")).toString();
getResponse().write("" +
"body {" +
"behavior: url("+csshoverurl+");" +
"}");

}

}

And to finish it up make it conditional so only IE picks it up, by adding a behavior:

public class IECheckBehaviorBehavior extends  AbstractBehavior {
public IECheckBehaviorBehavior() {
}
@Override
public void beforeRender(Component component) {
super.beforeRender(component);
Response response = component.getResponse();
response.write("*!--[if lt IE 7]&gt;--*");
}
@Override
public void onRendered(Component component) {
super.onRendered(component);
Response response = component.getResponse();
response.write("*![endif]--*");
}
}

The result:

<!--[if lt IE 7]&gt;-->
body {behavior: url(resources/zeuzgroup.web.page.BasePage/csshover2.htc;jsessionid=1pjzdpc4j8asn);}
<![endif]-->

Simple and and almost clean 🙂

Ps updated the post to show correct source

Advertisements

Actions

Information

7 responses

11 12 2008
nicogiard

i think there is a little display problem with the “Markup (in head)” block.

11 12 2008
Michael

Yepp “almost” clean 😉

You could also make the whole thing conditional on the server side, IE check if the User-Agent is lower than IE7 and make the HeaderContribution then, or am I missing something?

11 12 2008
ninomartinez

@2: No youre completely correct it’s two different styles of it.

My approach does less less on the server side, and only lets IE pickup the hack, although the code will still be there for firefox to ignore…

But my main point where that something that I thought would be hard todo in wicket, where just very easy 🙂

11 12 2008
nicogiard

oops, i didn’t see the ps 😡

11 12 2008
ninomartinez

@3 : hehe no problem.

8 04 2009
Joseph

u mean *ceases* to impress u rite?

10 04 2009
ninomartinez

No I mean, that it continues to impress me, by being simple and straight forward:)

Hehe I realize that I made a spelling error 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: