Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added #-anchor solution

...

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();
	}

}

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)

...