thank your suggestion, I will try MarkupContainer approach !

On 9/14/05, Johan Compagner <[EMAIL PROTECTED] > wrote:
of courses you can make custom components that inherit the markup from the main page (or panel)
just extends MarkupContainer instead of Panel

Look what Link does or TextField.

If you want a Link that uses its model for its body content then make such a link
Just copy our current link and implement the onComponentTagBody()
a bit different (output there the modelobject)

If it was me i would do that by default for the link component, because i think a extra label inside a link isn't also my preffered way of doing things.
Maybe we could make it optional
Link.setRenderModelObjectAsBody(true)




On 9/14/05, Ingram Chen <[EMAIL PROTECTED] > wrote:
I have tried some custom components with Panel, and it works just fine.
The only thing that confuses me is I always need to write a
Panel to wrap my composite components, for example, a custom Link
component with a configurable link text:

LabeledLinkPanel.html

<wicket:panel>
<a href="" wicket:id="link">
    <span wicket:id="linkTextBody">link text body...</span>
</a>
</wicket:panel>


LabeledLinkPanel.java
public abstract class LabeledLinkPanel extends Panel {
     public LabeledLinkPanel(String id, String label) {
           super(id) ;
           Link link = new Link("link"){
                 protected void onClick(
                      LabeledLinkPanel.this.onClick() ;
                 )
           } ;
           link.add(new Label("linkTextBody", label)) ;
           add(link) ;
     }

     //subclass to implement onClick() of Panel
     protected abstract void onClick() ;
}

Well, this works but is complex and not intuitive. I hope we can simplify as:

LabeledLink.html

<a href="" wicket:ref="id" >
    <span wicket:id="linkTextBody">link text body...</span>
</a>

LabeledLink.java

public abstract class LabeledLink extends Link {
     public LabeledLink(String id, String label) {
           super(id) ;
           add(new Label("linkTextBody", label)) ;
     }
}


The usage of this custom component is almost identical with original Link
, except that it will replace the whole <a /> tag from the template LabeledLink.html

MyHomePage.html

<h3>My Home</h3>
<a href="" wicket:id="viewAlbum"> ... to be replace... </a>


MyHomePage.java

public MyHomePage() {
    add(new LabeledLink("viewAlbum", "fooLinkBody" ) {
          protected void onClick() {
               setResponsePage(ViewAlbumPage.class) ;
          }
    } );
}

After rendering, the html will be:

<h3>My Home</h3>
<a href="" wicket:id="viewAlbum">
    <span wicket:id="linkTextBody">fooLinkBody</span>
</a>


Is this possible ? Any idea ?

--
Ingram Chen
Java [EMAIL PROTECTED]
Institue of BioMedical Sciences Academia Sinica Taiwan
blog: http://www.javaworld.com.tw/roller/page/ingramchen




--
Ingram Chen
Java [EMAIL PROTECTED]
Institue of BioMedical Sciences Academia Sinica Taiwan
blog: http://www.javaworld.com.tw/roller/page/ingramchen

Reply via email to