Thanks for the hint... I did look into the source code and could figure out
the onComponentTagBody trick, too... replacing this with text is one
thing... but wrapping other components would not be as easily done (as far
as I am able to grasp this - correct me if I am wrong) - that's why I
brought up the ImageLink use case, too. Is it a good idea to add child
component tags to the component tag body programmatically and adding the
component instances later on, in onBeforeRender?

Cheers :)



Al Maw wrote:
> 
> For something like this, you probably want to avoid having markup files at
> all.
> 
> Seeing as you want something that is both a Link and a Label, a good
> starting point might be to look at the source code for both.
> 
> You should be able to extend the Link class, and override
> onComponentTagBody() in much the same way that Label does.
> 
> Alastair
> 
> 2008/8/26 Michael Sparer <[EMAIL PROTECTED]>:
>>
>> yes, you're right, that's a very common scenario :-)
>> we use an AbstractLinkPanel as base-class, markup goes like this:
>> [wicket:panel]
>>  [a href="#" wicket:id="link"][span
>> wicket:id="linkTitle"]Label[/span][/a]
>> [/wicket:panel]
>>
>> and then in java pass the label via constructor. and provide an abstract
>> method to return the link ... and add the link in the onbeforerender
>> method
>> ... e.g.
>>
>> new AbstractLinkPanel("id", new ResourceModel("label")) {
>>   protected AbstractLink getLink(id) {
>>      return new Link(id) {
>>      // snip
>>      }
>>  }
>> }
>>
>> for bookmarkablepagelinks with labels we just subclass AbstractLinkPanel,
>> return a BookmarkablePageLink there and pass the params _and_ the title
>> in
>> the constructor. e.g.
>>
>> new BookmarkablePageLinkPanel("id", new ResourceModel("label"),
>> FooPage.class, FooPage.getParams(pojo));
>>
>> well that's our approach, works pretty well ... but, as you said, would
>> be
>> great to have out-of-the box. but maybe that's already too specific to be
>> in
>> the wicket-core, as we as wicket-users are expected to implement exactly
>> such components that fit our needs ... would be interesting to hear a
>> developer's opinion about that.
>>
>> regards,
>> Michael
>>
>> PS: I'd be happy to share the above mentioned code with anybody
>> interested,
>> just mail me
>>
>> AbstractLink
>>
>>
>> pixologe wrote:
>>>
>>> Hi everybody,
>>>
>>> Perhaps I am just temporarily dumb, but I do not seem to be able to find
>>> an elegant solution for the following use case.
>>>
>>> I constantly create Links with just a single Label or a single Image in
>>> it. It would be convenient for me to create a LabeledLink or ImageLink,
>>> taking a content string/model or URL as param. (btw: I would LOVE to see
>>> something like this by default in wicket)
>>>
>>> My first idea was to inherit from BookmarkablePageLink and use
>>> wicket:extend to add markup - this does not work because markup file is
>>> ignored. This is understandable because wicket probably would not know
>>> where exactly to place the additional markup, because BPL does not have
>>> a
>>> wicket:child tag.
>>>
>>> So what is the best way to do this? I thought about inheriting from
>>> Panel,
>>> adding link and label, setting the panel's setRenderBodyOnly to true (to
>>> avoid useless markup) and override both the panel's and the link's
>>> onComponentTag method in order to adopt the original tag's attributes
>>> nevertheless... would work, but is definitely far away from being
>>> elegant...
>>>
>>> There is no way to inherit from a component and add markup when there's
>>> no
>>> wicket:child, right?
>>>
>>> Thanks for inspiration :)
>>>
>>
>>
>> -----
>> Michael Sparer
>> http://talk-on-tech.blogspot.com
>> --
>> View this message in context:
>> http://www.nabble.com/Implement-LabeledLink-and-ImageLink-components---what-is-the-most-elegant-way--tp19147651p19158566.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Implement-LabeledLink-and-ImageLink-components---what-is-the-most-elegant-way--tp19147651p19161989.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to