Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: extract request parameters

...

Code Block
formComponent.visitChildren(Radio.class, new IVisitor<Component, Void>()
{
	public void /*[1]*/ component(final Component component, final IVisit<Void> visit /*[2]*/)
	{
		if (value.equals(component.getDefaultModelObject()))
		{
			addFormComponentValue(formComponent,((Radio<?>)component).getValue());
			visit.stop(); /*[3]*/
		}
		else
		{
			visit.dontGoDeeper(); /*[4]*/
		}
	}
});

Wiki Markup
\[1\] The new style visitor no longer returns a value, instead the value can be returned using visit.stop(value)
\[2\] The new visit object is introduced to control the visitor traversal
\[3\] Instead of relying on magic return values the traversal is stopped by using the new visit object
\[4\] Same as \[3\] but a different method on IVisit is used

...

Before this method was introduced the developer had to rely on using onBeforeRender() method with some kind of "has-already-been-called-or-not" check to make sure the initialization code has only been run a single time. onInitialize() has this guarantee baked in - it will only be called once during the lifetime of the component.

Request parameters

To get the current request parameters (for example in Ajax behavior processing) in Apache Wicket 1.4:

Code Block

    String parameterValue = RequestCycle.get().getRequest().getParameter(parameterName);

In 1.5 you have a better control where the parameter comes from:

Code Block

   // GET request
   StringValue parameterValue = RequestCycle.get().getRequest().getQueryParameters().getParameterValue(parameterName);

   // POST request
   StringValue parameterValue = RequestCycle.get().getRequest().getPostParameters().getParameterValue(parameterName);

Or if you don't care about the method:

Code Block

   StringValue parameterValue = RequestCycle.get().getRequest().getRequestParameters().getParameterValue(parameterName);