4

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
3
  • I'd probably trry using / instead of . as directory separator, and you can use relative dirs as well, i.e. "../main/HelloWorld.html"
    – biziclop
    Jan 15, 2011 at 16:02
  • Thanks, the relative url using ../main/... worked. using / as dir seperator did not work. If you could put it as an answer, i can accept it
    – user373201
    Jan 15, 2011 at 17:05
  • The / separator should work too but you probably need a leading /, otherwise wicket will think it's a relative link.
    – biziclop
    Jan 15, 2011 at 19:57

3 Answers 3

10

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.

5

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>
0

The above answer is perfect.It need not only to be in the different folder in the project,but also it can be anywhere in the folder in the system.Still it possible to refer that file,if the configuation is done correctly in WicketApplication file.

1
  • 4
    The answers might be reordered. So if you want to comment an answer, the comment function would be more helpful.
    – Nicktar
    Nov 6, 2012 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.