public abstract class WebApplication extends Application
Application settings are given defaults by the WebApplication() constructor and internalInit method, such as error page classes appropriate for HTML. WebApplication subclasses can override these values and/or modify other application settings by overriding the init() method and then by calling getXXXSettings() to retrieve an interface to a mutable Settings object. Do not do this in the constructor itself because the defaults will then override your settings.
If you want to use a filter specific configuration, e.g. using init parameters from the
FilterConfig
object, you should override the init() method. For example:
public void init() { String webXMLParameter = getInitParameter("myWebXMLParameter"); URL schedulersConfig = getServletContext().getResource("/WEB-INF/schedulers.xml"); ...
WicketFilter
,
ApplicationSettings
,
DebugSettings
,
ExceptionSettings
,
MarkupSettings
,
PageSettings
,
RequestCycleSettings
,
ResourceSettings
,
SecuritySettings
,
Filter
,
FilterConfig
,
ServletContext
Modifier and Type | Field and Description |
---|---|
static String |
META_INF_RESOURCES |
CONFIGURATION
Constructor and Description |
---|
WebApplication()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addResourceReplacement(CssResourceReference base,
ResourceReference replacement)
Registers a replacement resource for the given CSS resource.
|
void |
addResourceReplacement(JavaScriptResourceReference base,
ResourceReference replacement)
Registers a replacement resource for the given javascript resource.
|
static WebApplication |
get()
Covariant override for easy getting the current
WebApplication without having to cast
it. |
AjaxRequestTargetListenerCollection |
getAjaxRequestTargetListeners()
Returns the registered
AjaxRequestTarget.IListener objects. |
Function<Page,AjaxRequestTarget> |
getAjaxRequestTargetProvider()
Returns the provider for
AjaxRequestTarget objects. |
BufferedWebResponse |
getAndRemoveBufferedResponse(String sessionId,
Url url)
Retrieves a stored buffered response for a given sessionId and url.
|
String |
getApplicationKey()
Gets the unique key of this application within a given context (like a web application).
|
RuntimeConfigurationType |
getConfigurationType()
Gets the configuration mode to use for configuring the app, either
RuntimeConfigurationType.DEVELOPMENT or RuntimeConfigurationType.DEPLOYMENT . |
FilterFactoryManager |
getFilterFactoryManager() |
String |
getInitParameter(String key)
Gets an init parameter of the filter, or null if the parameter does not exist.
|
String |
getMimeType(String fileName)
Returns the mime type for given filename.
|
javax.servlet.ServletContext |
getServletContext()
Gets the servlet context for this application.
|
String |
getSessionAttributePrefix(WebRequest request,
String filterName)
Gets the prefix for storing variables in the actual session (typically
HttpSession
for this application instance. |
boolean |
getUpdateAutoLabelsOnAjaxRequests()
If true, auto label css classes such as
error and required will be updated
after form component processing during an ajax request. |
WicketFilter |
getWicketFilter() |
boolean |
hasBufferedResponse(String sessionId,
Url url) |
boolean |
hasFilterFactoryManager() |
protected void |
init()
Initialize; if you need the wicket servlet/filter for initialization, e.g.
|
void |
internalDestroy()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
protected void |
internalInit()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
void |
logEventTarget(IRequestHandler target)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
void |
logResponseTarget(IRequestHandler target)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
void |
mount(IRequestMapper mapper)
Mounts an encoder at the given path.
|
<P extends Page> |
mountPackage(String path,
Class<P> pageClass)
Mounts mounts all bookmarkable pages in a the pageClass's package to the given path.
|
<T extends Page> |
mountPage(String path,
Class<T> pageClass)
Mounts a page class to the given path.
|
ResourceMapper |
mountResource(String path,
ResourceReference reference)
Mounts a shared resource to the given path.
|
AjaxRequestTarget |
newAjaxRequestTarget(Page page)
Creates a new ajax request target used to control ajax responses
|
Session |
newSession(Request request,
Response response)
Creates a new session.
|
WebRequest |
newWebRequest(javax.servlet.http.HttpServletRequest servletRequest,
String filterPath)
Create a new WebRequest.
|
protected WebResponse |
newWebResponse(WebRequest webRequest,
javax.servlet.http.HttpServletResponse httpServletResponse)
Creates a WebResponse.
|
protected void |
outputDevelopmentModeWarning()
This method prints a warning to stderr that we are starting in development mode.
|
void |
renderXmlDecl(WebPage page,
boolean insert)
The rules if and when to insert an xml decl in the response are a bit tricky.
|
void |
sessionUnbound(String sessionId)
Informs the listener that session with specific id has been unbound.
|
Application |
setAjaxRequestTargetProvider(Function<Page,AjaxRequestTarget> ajaxRequestTargetProvider)
Sets the provider for
AjaxRequestTarget objects. |
Application |
setConfigurationType(RuntimeConfigurationType configurationType)
set runtime configuration type
this is a write-once property: once configured it can not be changed later on.
|
void |
setServletContext(javax.servlet.ServletContext servletContext)
Sets servlet context this application runs after.
|
void |
setWicketFilter(WicketFilter wicketFilter)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
void |
storeBufferedResponse(String sessionId,
Url url,
BufferedWebResponse response)
Store the buffered response at application level to use it at a later time.
|
void |
unmount(String path)
Unregisters all
IRequestMapper s which would match on a this path. |
configure, createRequestCycle, decorateHeaderResponse, exists, fetchCreateAndSetSession, get, getApplicationKeys, getApplicationListeners, getApplicationSettings, getBehaviorInstantiationListeners, getComponentInitializationListeners, getComponentInstantiationListeners, getComponentOnAfterRenderListeners, getComponentOnConfigureListeners, getComponentPostOnBeforeRenderListeners, getComponentPreOnBeforeRenderListeners, getConverterLocator, getDebugSettings, getExceptionMapperProvider, getExceptionSettings, getFrameworkSettings, getHeaderContributorListeners, getHomePage, getInitializers, getJavaScriptLibrarySettings, getMapperContext, getMarkupSettings, getMetaData, getName, getOnComponentTagListeners, getPageFactory, getPageManagerContext, getPageManagerProvider, getPageRendererProvider, getPageSettings, getRequestCycleListeners, getRequestCycleProvider, getRequestCycleSettings, getRequestLogger, getRequestLoggerSettings, getResourceBundles, getResourceReferenceRegistry, getResourceSettings, getRootRequestMapper, getRootRequestMapperAsCompound, getSecuritySettings, getSessionListeners, getSessionStore, getSessionStoreProvider, getSharedResources, getStoreSettings, initApplication, newConverterLocator, newMapperContext, newPageFactory, newRequestLogger, newResourceBundles, newResourceReferenceRegistry, newSharedResources, onDestroy, onEvent, setApplicationSettings, setDebugSettings, setExceptionSettings, setFrameworkSettings, setHeaderResponseDecorator, setJavaScriptLibrarySettings, setMarkupSettings, setMetaData, setName, setPageManagerProvider, setPageRendererProvider, setPageSettings, setRequestCycleProvider, setRequestCycleSettings, setRequestLoggerSettings, setResourceSettings, setRootRequestMapper, setSecuritySettings, setSessionStoreProvider, setStoreSettings, usesDeploymentConfig, usesDevelopmentConfig, validateInit
public static final String META_INF_RESOURCES
public WebApplication()
init()
for any configuration of your application instead of
overriding the constructor.public static WebApplication get()
WebApplication
without having to cast
it.public final String getApplicationKey()
Application
getApplicationKey
in class Application
Application.getApplicationKey()
public String getInitParameter(String key)
key
- the key to search forpublic void setServletContext(javax.servlet.ServletContext servletContext)
WicketFilter
servletContext
- public javax.servlet.ServletContext getServletContext()
public String getSessionAttributePrefix(WebRequest request, String filterName)
HttpSession
for this application instance.request
- the requestfilterName
- If null, than it defaults to the WicketFilter filter name. However according to
the ServletSpec the Filter is not guaranteed to be initialized e.g. when
WicketSessionFilter gets initialized. Thus, though you (and WicketSessionFilter)
can provide a filter name, you must make sure it is the same as WicketFilter will
provide once initialized.public final WicketFilter getWicketFilter()
public void logEventTarget(IRequestHandler target)
Application
logEventTarget
in class Application
Application.logEventTarget(org.apache.wicket.request.IRequestHandler)
public void logResponseTarget(IRequestHandler target)
Application
logResponseTarget
in class Application
Application.logResponseTarget(org.apache.wicket.request.IRequestHandler)
public void mount(IRequestMapper mapper)
mapper
- the encoder that will be used for this mountpublic <T extends Page> MountedMapper mountPage(String path, Class<T> pageClass)
NOTE: mount path must not start with reserved URL segments! See IMapperContext
to know
which segments are reserved for internal use.
T
- type of pagepath
- the path to mount the page class onpageClass
- the page class to be mountedpublic ResourceMapper mountResource(String path, ResourceReference reference)
NOTE: mount path must not start with reserved URL segments! See IMapperContext
to know
which segments are reserved for internal use.
path
- the path to mount the resource reference onreference
- resource reference to be mountedpublic <P extends Page> PackageMapper mountPackage(String path, Class<P> pageClass)
NOTE: mount path must not start with reserved URL segments! See IMapperContext
to know
which segments are reserved for internal use.
P
- type of pagepath
- the path to mount the page class onpageClass
- the page class to be mountedpublic void unmount(String path)
IRequestMapper
s which would match on a this path.
Useful in OSGi environments where a bundle may want to update the mount point.
path
- the path to unmountpublic final void addResourceReplacement(JavaScriptResourceReference base, ResourceReference replacement)
JavaScriptResourceReference
for a packaged resource, but it can also be an
UrlResourceReference
to replace the resource by a
resource hosted on a CDN. Registering a replacement will cause the resource to replaced by
the given resource throughout the application: if base
is added, replacement
will be added instead.base
- The resource to replacereplacement
- The replacementpublic final void addResourceReplacement(CssResourceReference base, ResourceReference replacement)
CssResourceReference
for a packaged resource, but it can also be an
UrlResourceReference
to replace the resource by a
resource hosted on a CDN. Registering a replacement will cause the resource to replaced by
the given resource throughout the application: if base
is added, replacement
will be added instead.base
- The resource to replacereplacement
- The replacementpublic WebRequest newWebRequest(javax.servlet.http.HttpServletRequest servletRequest, String filterPath)
servletRequest
- the current HTTP Servlet requestfilterPath
- the filter mapping read from web.xmlprotected WebResponse newWebResponse(WebRequest webRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
webRequest
- the WebRequest
that will handle the current HTTP Servlet requesthttpServletResponse
- the current HTTP Servlet responsepublic Session newSession(Request request, Response response)
Application
newSession
in class Application
request
- The request that will create this session.response
- The response to initialize, for example with cookies. This is important to use
cases involving unit testing because those use cases might want to be able to sign
a user in automatically when the session is created.Application.newSession(org.apache.wicket.request.Request,
org.apache.wicket.request.Response)
public void sessionUnbound(String sessionId)
ISessionStore.UnboundListener
sessionUnbound
in interface ISessionStore.UnboundListener
sessionUnbound
in class Application
Application.sessionUnbound(java.lang.String)
public final void setWicketFilter(WicketFilter wicketFilter)
wicketFilter
- The wicket filter instance for this applicationprotected void init()
init
in class Application
public void internalDestroy()
internalDestroy
in class Application
protected void internalInit()
<init-param><param-name>configuration</param-name>
). If not
found check the servlet context init parameter
<context-param><param-name6gt;configuration</param-name>
). If the
parameter is "development" (which is default), settings appropriate for development are set.
If it's "deployment" , deployment settings are used. If development is specified and a
"sourceFolder" init parameter is also set, then resources in that folder will be polled for
changes.internalInit
in class Application
public Application setConfigurationType(RuntimeConfigurationType configurationType)
configurationType
- public RuntimeConfigurationType getConfigurationType()
RuntimeConfigurationType.DEVELOPMENT
or RuntimeConfigurationType.DEPLOYMENT
.
The configuration type. Must currently be either DEVELOPMENT or DEPLOYMENT. Currently, if the configuration type is DEVELOPMENT, resources are polled for changes, component usage is checked, wicket tags are not stripped from output and a detailed exception page is used. If the type is DEPLOYMENT, component usage is not checked, wicket tags are stripped from output and a non-detailed exception page is used to display errors.
Note that you should not run Wicket in DEVELOPMENT mode on production servers - the various debugging checks and resource polling is inefficient and may leak resources, particularly on webapp redeploy.
To change the deployment mode, add the following to your web.xml, inside your
You can alternatively set this as a <context-param> on the whole context.
Another option is to set the "wicket.configuration" system property to either "deployment" or
"development". The value is not case-sensitive.
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.
You may also override Application.getConfigurationType() to provide your own custom switch,
in which case none of the above logic is used.
<init-param>
<param-name>configuration</param-name>
<param-value>deployment</param-value>
</init-param>
IMPORTANT NOTE
THIS METHOD IS CALLED OFTEN FROM MANY DIFFERENT POINTS IN CODE, INCLUDING DURING THE RENDER PROCESS, THEREFORE THE IMPLEMENTATION SHOULD BE FAST - PREFERRABLY USING A FAST-TO-RETRIEVE CACHED VALUEgetConfigurationType
in class Application
public void renderXmlDecl(WebPage page, boolean insert)
Default implementation: the page mime type must be "application/xhtml+xml" and request HTTP_ACCEPT header must include "application/xhtml+xml" to automatically include the xml decl. Please see Writing JavaScript for XHTML for details.
Please note that xml decls in Wicket's markup are only used for reading the markup. The markup's xml decl will always be removed and never be used to configure the response.
page
- The page currently being renderedinsert
- If false, than the rules are applied. If true, it'll always be written. In order
to never insert it, than subclass renderXmlDecl() with an empty implementation.public final AjaxRequestTarget newAjaxRequestTarget(Page page)
page
- page on which ajax response is madeprotected void outputDevelopmentModeWarning()
If you really need to test Wicket in development mode on a staging server somewhere and are annoying the sysadmin for it with stderr messages, you can override this to make it do something else.
public boolean hasBufferedResponse(String sessionId, Url url)
sessionId
- url
- public BufferedWebResponse getAndRemoveBufferedResponse(String sessionId, Url url)
url
- The url used as a keynull
if there is no stored response for the given urlRequestCycleSettings.RenderStrategy.REDIRECT_TO_BUFFER
public void storeBufferedResponse(String sessionId, Url url, BufferedWebResponse response)
sessionId
- url
- response
- public String getMimeType(String fileName)
Application
getMimeType
in class Application
public Function<Page,AjaxRequestTarget> getAjaxRequestTargetProvider()
AjaxRequestTarget
objects.AjaxRequestTarget
objects.public Application setAjaxRequestTargetProvider(Function<Page,AjaxRequestTarget> ajaxRequestTargetProvider)
AjaxRequestTarget
objects.ajaxRequestTargetProvider
- the new providerpublic AjaxRequestTargetListenerCollection getAjaxRequestTargetListeners()
AjaxRequestTarget.IListener
objects.AjaxRequestTarget.IListener
objects.public final boolean hasFilterFactoryManager()
public final FilterFactoryManager getFilterFactoryManager()
public boolean getUpdateAutoLabelsOnAjaxRequests()
error
and required
will be updated
after form component processing during an ajax request. This allows auto labels to correctly
reflect the state of the form component even if they are not part of the ajax markup update.
TODO in wicket-7 this should move into a settings object. cannot move in 6.x because it
requires a change to a setting interface.true
iff enabledCopyright © 2006–2022 Apache Software Foundation. All rights reserved.