thanks igor,
it's always so refreshing how easy things can be done in wicket with the
right hint....
perhaps this is usefull for somebody, so i post the code here (as i work
with seam i use org.jboss.el.lang.ExpressionBuilder.Expressions):
public class ReplaceElContainer extends WebComponent{
protected void onComponentTagBody(MarkupStream _markupStream,
ComponentTag _openTag) {
CharSequence markup = _markupStream.get().toCharSequence();
Matcher mat =
java.util.regex.Pattern.compile("#\\{([^#])+?\\}").matcher(markup);
StringBuffer sb = new StringBuffer();
while(mat.find()) {
String elExpr = mat.group();
Object elValue =
Expressions.instance().createValueExpression(elExpr).getValue();
if( elValue!=null )
mat.appendReplacement(sb, elValue.toString());
}
mat.appendTail(sb);
replaceComponentTagBody(_markupStream, _openTag, sb);
On Thu, Feb 5, 2009 at 4:53 PM, Igor Vaynberg <[email protected]>wrote:
> On Thu, Feb 5, 2009 at 4:43 AM, janneru <[email protected]> wrote:
> > * simple components:
> > in my html i have many lines where i need just little modifications of
> the
> > html:
> >
> > e.g. in jsf i had 10 lines like: <link rel="stylesheet" type="text/css"
> > href="#{mediaPath.cssFolder}/header.css" /> (mediaPath is dynamic)
> > in wicket this will be 10 lines with: <link wicket:id="headerCssLink"
> > rel="stylesheet" type="text/css" href="header.css" /> and 10 components
> > added to the page, like: add( new HrefChanger( "headerCssLink",
> > LINKTYPE_CSS) );
> > the HrefChanger-Component just takes the tag from the html and changes
> the
> > href attribute by prepending the css-path;
> >
> > is this the correct way?
>
> > seems that sth like the wicket:link tag would be right for this - can i
> > write my own wicket:cssLink tag or can i somehow extend the behaviour of
> the
> > wicket:link tag?
>
> you can write your own wicket:cssLink, see IMarkupFilter; however, an
> easiest solution if you need pragmatic manipulation of the url is just
> to use IHeaderContributor and write out the urls from java via
> response.renderCssReference(myurl);
>
> > * changing html content for inline styles or javascript:
> > in jsf i had this dynamic inline style definition: <style> a{color:
> > ${linkcolor}; } </style>
> > in wicket i tried: <style> a{color: <span wicket:id="linkColor"/>;
> }</style>
> >
> > and in the page: add( new Label("linkColor",
> > getLinkColor()).setRenderBodyOnly(true);
> >
> > but the span does not get parsed, wicket says: "...you have added a
> > component in code but forgot to reference it in the markup..."; same when
> i
> > want to replace something in a javascript function, e.g. alert( 'Hello
> > <span wicket:id="userName" !'/>
> >
> > whats the right way to do this?
>
>
> you can use TextTemplateContributor to contribute the entire
> <style></style> block into the page and have ${var} replacement.
>
> further you can create a label subclass that does ${var} replacement
> and attach it to the <style> tag:
>
> class interpolatinglabel extends webcomponent {
> protected void oncomponenttagbody(stream,tag) {
> String markup=stream.getrawmarkup();
> markup.replace("${foo}", "bar");
> replacecomponenttagbody(markup, tag);
> }
> }
>
> and taking this even further you can use something like an
> iresponsefilter to postprocess the html and replace any ${var}s then.
>
> -igor
>
> >
> >
> > thx in advance, uwe!
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>