Class CmsJspBean
- Direct Known Subclasses:
CmsJspActionElement
,CmsUploadBean
If you have large chunks of code on your JSP that you want to move to a Class file, consider creating a subclass of this bean. Initialize this bean at the beginning of your JSP like this:
<jsp:useBean id="cmsbean" class="org.opencms.jsp.CmsJspBean"> <% cmsbean.init(pageContext, request, response); %> </jsp:useBean>
- Since:
- 6.0.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the CmsObject from the wrapped request.protected CmsFlexController
Returns the Flex controller derived from the request this bean was initialized with.javax.servlet.jsp.PageContext
Returns the JSP page context this bean was initialized with.protected String
getMessage
(CmsMessageContainer container) Internally localizes the givenCmsMessageContainer
to a String.javax.servlet.http.HttpServletRequest
Returns the request this bean was initialized with.Returns the current users OpenCms request context.javax.servlet.http.HttpServletResponse
Returns the response wrapped by this element.protected void
Handles any exception that might occur in the context of this element to ensure that templates are not disturbed.protected void
This method is called when the flex controller can not be found during initialization.void
init
(javax.servlet.jsp.PageContext context, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) Initialize this bean with the current page context, request and response.protected boolean
Returns true if this bean has not been initialized (i.e.boolean
Returnstrue
if Exceptions are handled by the class instance and suppressed on the output page, orfalse
if they will be thrown and have to be handled by the calling class.void
setContentType
(String type) Sets the content type for the HTTP response.void
setStatus
(int status) Sets the status code for the HTTP response.void
setSupressingExceptions
(boolean value) Controls if Exceptions that occur in methods of this class are suppressed (true) or not (false).
-
Constructor Details
-
CmsJspBean
public CmsJspBean()Empty constructor, required for every JavaBean.
-
-
Method Details
-
getCmsObject
Returns the CmsObject from the wrapped request.This is a convenience method in case you need access to the CmsObject in your JSP scriplets.
- Returns:
- the CmsObject from the wrapped request
-
getJspContext
Returns the JSP page context this bean was initialized with.- Returns:
- the JSP page context this bean was initialized with
-
getRequest
Returns the request this bean was initialized with.- Returns:
- the request this bean was initialized with
-
getRequestContext
Returns the current users OpenCms request context.- Returns:
- the current users OpenCms request context
-
getResponse
Returns the response wrapped by this element.- Returns:
- the response wrapped by this element
-
init
public void init(javax.servlet.jsp.PageContext context, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) Initialize this bean with the current page context, request and response.It is required to call one of the init() methods before you can use the instance of this bean.
- Parameters:
context
- the JSP page context objectreq
- the JSP requestres
- the JSP response
-
isSupressingExceptions
Returnstrue
if Exceptions are handled by the class instance and suppressed on the output page, orfalse
if they will be thrown and have to be handled by the calling class.The default is
true
. If set tofalse
Exceptions that occur internally will be wrapped into a RuntimeException and thrown to the calling class instance.- Returns:
true
if Exceptions are suppressed, orfalse
if they will be thrown and have to be handled by the calling class
-
setContentType
Sets the content type for the HTTP response.This method is required since JSP's are handled in a special way for included template elements, so
ServletResponse.setContentType(java.lang.String)
won't work.Please note that the content type set this way is never cached in the Flex cache, so you must make sure to not cache the element when you use this method.
- Parameters:
type
- the type to set- See Also:
-
ServletResponse.setContentType(java.lang.String)
-
setStatus
Sets the status code for the HTTP response.This method is required since JSP's are handled in a special way for included template elements, so
HttpServletResponseWrapper.setStatus(int)
won't work.Please note that the status code set this way is never cached in the Flex cache, so you must make sure to not cache the element when you use this method.
- Parameters:
status
- the status code to set- See Also:
-
HttpServletResponseWrapper.setStatus(int)
-
setSupressingExceptions
Controls if Exceptions that occur in methods of this class are suppressed (true) or not (false).The default is
true
. If set tofalse
all Exceptions that occur internally will be wrapped into a RuntimeException and thrown to the calling class instance.- Parameters:
value
- the value to set the Exception handing to
-
getController
Returns the Flex controller derived from the request this bean was initialized with.This is protected since the CmsFlexController this is really an internal OpenCms helper function, not part of the public OpenCms API. It must not be used on JSP pages, only from subclasses of this bean.
- Returns:
- the Flex controller derived from the request this bean was initialized with
-
getMessage
Internally localizes the givenCmsMessageContainer
to a String.If the user request context is at hand, the user's locale will be chosen. If no user request context is available, the default locale is used.
- Parameters:
container
- the message container that allows localization of the represented message.- Returns:
- the message String of the container argument localized to the user's locale (if available) or to the default locale.
-
handleException
Handles any exception that might occur in the context of this element to ensure that templates are not disturbed.- Parameters:
t
- the Throwable that was caught
-
handleMissingFlexController
This method is called when the flex controller can not be found during initialization.Override this if you are reusing old workplace classes in a context where no flex controller is available.
-
isNotInitialized
Returns true if this bean has not been initialized (i.e. init() has not been called so far), false otherwise.- Returns:
- true if this bean has not been initialized
-