Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wicket wicket:link

Tags:

wicket

I am trying out the following example. ChangeTextOnClick.html works fine as it is in the same dir as the file that contains the following snippet (WicketLink.html). But HelloWorld.html does not work as it is in another package. How do i refer to page on a different package.

 <wicket:link>
        <ul>
            <li>
                <a href="ChangeTextOnClick.html">Change Text On Click</a>
                <a href="com.merc.wicket.main/HelloWorld.html">Back</a>
            </li>
        </ul>
    </wicket:link>

my pages are in the follow dir structure

com.merc.wicket.link.WicketLink.java and .html
com.merc.wicket.link.ChangeTextOnClick.java and .html
com.merc.wicket.main.HelloWorld.java and .html
like image 512
user373201 Avatar asked Dec 06 '22 23:12

user373201


2 Answers

In Wicket, you would normally reference another html file using a Link in Java to let Wicket generate the href for you. You can mount a Page under a fix URL (called Bookmarkable Link, as they are independent from the user session) or just use a Link.

For a Bookmarkable Link, you would do the following in the init() of your Wicket application class:

public class WicketApplication extends WebApplication{

    protected void init() {
        super.init();
        mountBookmarkablePage("/ChangeTextOnClick", ChangeTextOnClick.class);
        mountBookmarkablePage("/HelloWorld", HelloWorld.class);
    }
}

With this, you can always reach those 2 Pages under the the URL given.

You can create a link pointing there using this in a MyPage.java:

add(new BookmarkablePageLink<ChangeTextOnClick>("myExampleLink"
                   ,ChangeTextOnClick.class)

and in the corresponding MyPage.html:

<a href="thisGetsReplacedAtRuntime" 
                  wicket:id="myExampleLink">Change Text On Click</a>

If you don 't want the Links to be bookmarkable, you don 't need the mountBookmarkablePage stuff in the init() and use a a Link instead of a BookmarkablePageLink.

Have a look at the Wicket wicki, you will find lots of helpful information there.

like image 114
bert Avatar answered Mar 28 '23 07:03

bert


It turns out my guess was correct so here it is as an answer:

Wicket uses / as path separator, not ..

<wicket:link>
    <ul>
        <li>
            <a href="ChangeTextOnClick.html">Change Text On Click</a>
            <a href="/com/merc/wicket/main/HelloWorld.html">Back</a>
        </li>
    </ul>
</wicket:link>

is one solution, or using relative paths:

<wicket:link>
    <ul>
        <li>
            <a href="ChangeTextOnClick.html">Change Text On Click</a>
            <a href="../main/HelloWorld.html">Back</a>
        </li>
    </ul>
</wicket:link>
like image 22
biziclop Avatar answered Mar 28 '23 08:03

biziclop