You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by janneru <ja...@googlemail.com> on 2009/02/05 13:43:10 UTC
Another question for best practices
dear community,
still working on a reimplementation of a former jsf gui i have some more
questions about how to implement it correctly in wicket;
* 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?
* 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?
thx in advance, uwe!
Re: Another question for best practices
Posted by uwe janner <uj...@googlemail.com>.
i just tried it, the parser seems to ignore it,
i find the
<wicket:container wicket:id="linkColor"/>
unchanged in the html if i dont add a omponent to the page, and if i add the
component wicket complains that he cannot find the associated component in
the html (just as before)
On Thu, Feb 5, 2009 at 2:21 PM, Martin Makundi <
martin.makundi@koodaripalvelut.com> wrote:
> > in wicket i tried: <style> a{color: <span wicket:id="linkColor"/>;
> }</style>
>
> Have you tried <wicket:container wicket:id="linkColor"/> ?
>
> **
> Martin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Another question for best practices
Posted by Martin Makundi <ma...@koodaripalvelut.com>.
> in wicket i tried: <style> a{color: <span wicket:id="linkColor"/>; }</style>
Have you tried <wicket:container wicket:id="linkColor"/> ?
**
Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Another question for best practices
Posted by uwe janner <uj...@googlemail.com>.
ok, i got it :-)
the downside is, that then you have the names of the css in the java class;
as this is more the duty of the html designer, i looked for a way to let the
html designer say which css to take (and pull it from a static source) and a
mechanism that converts this to the "real" url by wicket.
so i used the <wicket:container id="cssLinks"> solution.
uwe.
On Fri, Feb 6, 2009 at 5:15 PM, Thomas Mäder <th...@devotek-it.ch>wrote:
> No, what I meant was a single tag link and a list view:
>
> <link wicket:id="cssList"></link>
>
> and in code:
>
> List cssFiles= Array.asList(new String[] { "base.css", "special.css" });
> add(new ListView("cssList", cssFiles) {
> public void populateItem(ListItem item) {
> String cssFile= item.getModelObjectAsString();
> item.add(new AttributeModifier("href", new AbstractReadOnlyModel() {
> public Object getModel() {
> return <the prefix, don't know where to get it>+"/"+cssFile
> }
> });
> }
> });
>
> this is off the top of my head, just to see if we're even on the same page.
>
> Thomas
>
> On Fri, Feb 6, 2009 at 12:15 PM, uwe janner <uj...@googlemail.com>
> wrote:
>
> > hi thomas,
> >
> > i dont really get your idea, maybe an example?
> >
> > what i did was: write the followning in the html:
> >
> > <link wicket:id="baseCss" href="base.css"/>
> > .... and many more ...
> > <link wicket:id="specialCss" href="special.css"/>
> >
> > and then i "repeat" myself in the page class (CssLink just puts the
> dynamic
> > url part before the original href value):
> >
> > add( new CssLink("baseCss"));
> > ... and many more ...
> > add( new CssLink("specialCss"));
> >
> >
> >
>
>
> --
> Thomas Mäder
> Wicket & Eclipse Consulting
> www.devotek-it.ch
>
Re: Another question for best practices
Posted by Thomas Mäder <th...@devotek-it.ch>.
No, what I meant was a single tag link and a list view:
<link wicket:id="cssList"></link>
and in code:
List cssFiles= Array.asList(new String[] { "base.css", "special.css" });
add(new ListView("cssList", cssFiles) {
public void populateItem(ListItem item) {
String cssFile= item.getModelObjectAsString();
item.add(new AttributeModifier("href", new AbstractReadOnlyModel() {
public Object getModel() {
return <the prefix, don't know where to get it>+"/"+cssFile
}
});
}
});
this is off the top of my head, just to see if we're even on the same page.
Thomas
On Fri, Feb 6, 2009 at 12:15 PM, uwe janner <uj...@googlemail.com> wrote:
> hi thomas,
>
> i dont really get your idea, maybe an example?
>
> what i did was: write the followning in the html:
>
> <link wicket:id="baseCss" href="base.css"/>
> .... and many more ...
> <link wicket:id="specialCss" href="special.css"/>
>
> and then i "repeat" myself in the page class (CssLink just puts the dynamic
> url part before the original href value):
>
> add( new CssLink("baseCss"));
> ... and many more ...
> add( new CssLink("specialCss"));
>
>
>
--
Thomas Mäder
Wicket & Eclipse Consulting
www.devotek-it.ch
Re: Another question for best practices
Posted by uwe janner <uj...@googlemail.com>.
hi thomas,
i dont really get your idea, maybe an example?
what i did was: write the followning in the html:
<link wicket:id="baseCss" href="base.css"/>
.... and many more ...
<link wicket:id="specialCss" href="special.css"/>
and then i "repeat" myself in the page class (CssLink just puts the dynamic
url part before the original href value):
add( new CssLink("baseCss"));
... and many more ...
add( new CssLink("specialCss"));
would look shorter if i do it in a loop iterationg over { "baseCss",
......... "specialCss" } but the bad thing about it is that i have to keep
these two in sync;
so i think i would implement it like this:
<wicket:container id="cssLinks">
<link href="base.css"/>
.... and many more ...
<link href="special.css"/>
</wicket:container>
and in the page i would add my custom ChangeHrefInBodyComponent, which would
directly change the hrefs in the body markup (not the child link components)
- bc i dont want to add those components explicitly by hand:
add( new ChangeHrefInBodyComponent( "cssLinks" );
or even simpler:
<wicket:cssLinks>
<link href="base.css"/>
.... and many more ...
<link href="special.css"/>
</wicket:cssLinks>
and nothing to add in the page (as with <wicket:links> )
cheersuwe!
On Thu, Feb 5, 2009 at 8:51 PM, Thomas Mäder <th...@devotek-it.ch>wrote:
> What I would have tried is this: have a list view of web markup containers.
> As a list item, create a WebMarkupContainer (mapped to the <link> tag). Add
> an attribute modifier that fixes up the "href" attribute of the link tag.
> You get the filename ("header.css") from the ListView's model. Or am I
> missing somthing here?
>
> Thomas
>
> --
> Thomas Mäder
> Wicket & Eclipse Consulting
> www.devotek-it.ch
>
Re: Another question for best practices
Posted by Thomas Mäder <th...@devotek-it.ch>.
What I would have tried is this: have a list view of web markup containers.
As a list item, create a WebMarkupContainer (mapped to the <link> tag). Add
an attribute modifier that fixes up the "href" attribute of the link tag.
You get the filename ("header.css") from the ListView's model. Or am I
missing somthing here?
Thomas
--
Thomas Mäder
Wicket & Eclipse Consulting
www.devotek-it.ch
Re: Another question for best practices
Posted by Igor Vaynberg <ig...@gmail.com>.
wicket also has a MapVariableInterpolator that can take care of ${var}
substitutions
-igor
On Thu, Feb 5, 2009 at 9:18 AM, uwe janner <uj...@googlemail.com> wrote:
> 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 <ig...@gmail.com>wrote:
>
>> On Thu, Feb 5, 2009 at 4:43 AM, janneru <ja...@googlemail.com> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Another question for best practices
Posted by uwe janner <uj...@googlemail.com>.
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 <ig...@gmail.com>wrote:
> On Thu, Feb 5, 2009 at 4:43 AM, janneru <ja...@googlemail.com> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Another question for best practices
Posted by Igor Vaynberg <ig...@gmail.com>.
On Thu, Feb 5, 2009 at 4:43 AM, janneru <ja...@googlemail.com> 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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org