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]>--*"); } @Override public void onRendered(Component component) { super.onRendered(component); Response response = component.getResponse(); response.write("*![endif]--*"); } }
The result:
<!--[if lt IE 7]>--> 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
i think there is a little display problem with the “Markup (in head)” block.
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?
@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 🙂
oops, i didn’t see the ps 😡
@3 : hehe no problem.
u mean *ceases* to impress u rite?
No I mean, that it continues to impress me, by being simple and straight forward:)
Hehe I realize that I made a spelling error 🙂