Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Igor Vaynberg in wicket-dev:

We are trying to consolidate the methods. We have a bunch of
internalOnAttach/internalAttach/attach/onattach methods. it's a big mess.
what this refactor does is give you one method you can override - onattach()
but forces the call to super.

Doing it like it has been done doesn't work. users assume onattach() is a
template method, they can override and not have to call super - but this
fails if you go more then one method deep!

if i create a custom component and do something in onattach(), then the user
subclasses it and they do something in onattach() and don't bother to call
super() they will break my functionality. My only choice of action is to
make onattach() final in my custom component and provide yet another
template for the user, onattach2() ? This just doesn't scale. Better to have
a simple and clear contract - onattach and ondetach always require the call
to super.

Unfortunately the only way to do that at this point and keep the same
method names is to do what i did.

OT there is a JSR for software defect annotations that includes something
like @MustCallSuper (forget what its called), that combined with an apt
builder in an ide will make these kinds of contracts very easy to enforce at
compile time. we are just not there just yet.

How can I use wicket to develop webapps that target mobile devices?

...

How do I add custom error pages?

see Error Pages and Feedback Messages

How can I have images/files uploaded to and downloaded from my wicket app?

In short, use the wicket.markup.html.form.upload.FileUploadField component in your form (set as multiPart) in order to allow file uploads. Use an implementation of the wicket.markup.html.DynamicWebResource to provide downloads of the content. For a longer description with examples see UploadDownload Uploading and Downloading Files

What is the difference between setResponsePage(new MyWebPage()) and setResponsePage(MyWebPage.class)

...

Yes. See Control where HTML files are loaded from

More on the view: AJAX

I get errors when I use Ajax in Opera Browser (before Version Beta 9 of Opera)

How can I render my templates to a String?

Code Block

public class PageRenderer extends BaseWicketTester
{
	private final Locale locale;

	public PageRenderer(Locale locale)
	{
		this.locale = locale;
	}

	public PageRenderer()
	{
		this.locale = null;
	}

	private String renderStartPage()
	{
		if (this.locale != null)
		{
			getWicketSession().setLocale(locale);
		}

		return getServletResponse().getDocument();
	}

	public synchronized String render(Class<? extends WebPage> pageClass)
	{
		startPage(pageClass);
		return renderStartPage();
	}

	public synchronized String render(Class<? extends WebPage> pageClass, PageParameters parameters)
	{
		startPage(pageClass, parameters);
		return renderStartPage();
	}

	public synchronized String render(WebPage page)
	{
		startPage(page);
		return renderStartPage();
	}

}

For different approach please check Use wicket as template engine.

How to add #-anchor (opaque) to page url?

I don't know universal solution, but for mounted pages you can override particular url coding strategy to encode a parameter in special way. Say, I named parameter "#" and my strategy:

Code Block

public CharSequence encode(IRequestTarget requestTarget) {
		if (!(requestTarget instanceof IBookmarkablePageRequestTarget))
		{
			throw new IllegalArgumentException("this encoder can only be used with instances of " +
					IBookmarkablePageRequestTarget.class.getName());
		}
		IBookmarkablePageRequestTarget target = (IBookmarkablePageRequestTarget)requestTarget;

		AppendingStringBuffer url = new AppendingStringBuffer(40);
		url.append(getMountPath());
		final String className = target.getPageClass().getSimpleName();
		PageParameters pageParameters = target.getPageParameters();
		if (target.getPageMapName() != null)
		{
			pageParameters.put(WebRequestCodingStrategy.PAGEMAP, WebRequestCodingStrategy
					.encodePageMapName(target.getPageMapName()));
		}
		final String fragment = pageParameters.getString("#");
		if(fragment != null)
			pageParameters.remove("#");

		url.append("/");
		url.append(className);

		if(!pageParameters.isEmpty())
		{
			url.append("?");
			appendParameters(url, pageParameters);
		}
		if(fragment != null)
			url.append("#").append(urlEncodePathComponent(fragment));
		return url;
	}

Now you can add parameter named "#" in PageParameters bookmarkable page link or so and it will be rendered as anchor.

More on the view: AJAX

I get errors when I use Ajax in Opera Browser (before Version Beta 9 of Opera)

If you want to use wicket's Ajax If you want to use wicket's Ajax implementation with Opera Browser you have to do

...

Which browsers have been tested with Wicket AJAX?

To test it use the AJAX examples and the AJAX request header test..

  • Google Chrome - latest two stable versions
  • Firefox - latest two stable versions
  • Safari 5.x and 6.x
  • Opera 12.x and 15.x
  • Internet Explorer 8+
  • Internet Explorer 6 and 7
  • Firefox 1.5
  • Firefox 2.0
  • Safari 2.0.1 - 2.0.4
  • Opera 8.54 (linux)
  • Opera 9 (linux)
  • Konqueror 3.5.2 (most of the examples works, but the Todo list example makes the browser crash)

Wicket.replaceOuterHtml gives weird result on Firefox

...

Add the following to your web.xml, inside your <servlet> mapping definition (or <filter> mapping definition if you're using 1.3.x):

Code Block
xml
xml
<init-param>
            <param-name>configuration</param-name>
            <param-value>deployment</param-value>
</init-param>

...