Pages Navigation Menu

Coding is much easier than you think

How to change Wicket to deployment mode

How to change Wicket to deployment mode

 
By default, Wicket is running in development mode. In this post we will see how to change that to Deployment mode ( commonly called as production mode ).
 
There is two method to change wicket to run in deployment (production) mode :
 

1. web.xml


 
The first st way is add a ‘€œconfiguration’€ context-param in web.xml.
 
File : web.xml
 

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app ... >

  ...

  <filter>
    <filter-name>wicket.app</filter-name>
    <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
    <init-param>
      <param-name>applicationClassName</param-name>
      <param-value>org.starobjects.wicket.viewer.app.WicketObjectsApplication</param-value>
    </init-param>
    <init-param>
      <param-name>configuration</param-name>
      <param-value>deployment</param-value>
    </init-param>
  </filter>

</web-app>

 
The system property is checked first, allowing you to add a web.xml param for deployment, and a command-line override when you want to run in development mode during development.
 

2. Wicket getConfigurationType()

 
The 2nd way is override the Wicket application getConfigurationType() method.
 
File : Wicket Application class
 

import org.apache.wicket.Application;
import org.apache.wicket.protocol.http.WebApplication;
 
public class WicketApplication extends WebApplication 
{ 
	@Override
	public String getConfigurationType() 
        {
 
		return Application.DEPLOYMENT;
	}
}

 

Note The Wicket application always has the highest priority. For example, if web.xml is “development” and Wicket application is ‘€œdeployment’œ, Wicket will run in ‘€œdeployment’ mode.

 

How do I know in what mode (DEVELOPMENT/DEPLOYMENT) my application runs?


 
As of Wicket 1.3.0, you can call Application.getConfigurationType(). Prior to that, there is no flag telling you in which mode you are. If you want a flag subclass Application.configure() store the “configurationType” parameter in a variable.
 

if (DEVELOPMENT.equalsIgnoreCase(configurationType))
{
    log.info("You are in DEVELOPMENT mode");
    getResourceSettings().setResourcePollFrequency(Duration.ONE_SECOND);
    getDebugSettings().setComponentUseCheck(true);
    getDebugSettings().setSerializeSessionAttributes(true);
    getMarkupSettings().setStripWicketTags(false);
    getExceptionSettings().setUnexpectedExceptionDisplay(
                    UnexpectedExceptionDisplay.SHOW_EXCEPTION_PAGE);
    getAjaxSettings().setAjaxDebugModeEnabled(true);
}
else if (DEPLOYMENT.equalsIgnoreCase(configurationType))
{
    getResourceSettings().setResourcePollFrequency(null);
    getDebugSettings().setComponentUseCheck(false);
    getDebugSettings().setSerializeSessionAttributes(false);
    getMarkupSettings().setStripWicketTags(true);
    getExceptionSettings().setUnexpectedExceptionDisplay(
                    UnexpectedExceptionDisplay.SHOW_INTERNAL_ERROR_PAGE);
    getAjaxSettings().setAjaxDebugModeEnabled(false);
}

 

About Gokul


I am very much interested in android and Wicket framework. A core android developer and working in android native app development and responsive web mobile design. I have also worked in wicket fame work and java web development. I will keep on updating you about android and wicket framework and answer your query.

  • Haripriya

    Have been visiting your site for a few days. really love your posts.