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">
invalid input: '<'% cmsbean.init(pageContext, request, response); %>
</jsp:useBean>
- Since:
- 6.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the CmsObject from the wrapped request.protected CmsFlexControllerReturns the Flex controller derived from the request this bean was initialized with.javax.servlet.jsp.PageContextReturns the JSP page context this bean was initialized with.protected StringgetMessage(CmsMessageContainer container) Internally localizes the givenCmsMessageContainerto a String.javax.servlet.http.HttpServletRequestReturns the request this bean was initialized with.Returns the current users OpenCms request context.javax.servlet.http.HttpServletResponseReturns the response wrapped by this element.protected voidHandles any exception that might occur in the context of this element to ensure that templates are not disturbed.protected voidThis method is called when the flex controller can not be found during initialization.voidinit(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 booleanReturns true if this bean has not been initialized (i.e.booleanReturnstrueif Exceptions are handled by the class instance and suppressed on the output page, orfalseif they will be thrown and have to be handled by the calling class.voidsetContentType(String type) Sets the content type for the HTTP response.voidsetStatus(int status) Sets the status code for the HTTP response.voidsetSupressingExceptions(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
Returnstrueif Exceptions are handled by the class instance and suppressed on the output page, orfalseif they will be thrown and have to be handled by the calling class.The default is
true. If set tofalseExceptions that occur internally will be wrapped into a RuntimeException and thrown to the calling class instance.- Returns:
trueif Exceptions are suppressed, orfalseif 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.- Parameters:
type- the type to set- See Also:
-
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:
-
setSupressingExceptions
Controls if Exceptions that occur in methods of this class are suppressed (true) or not (false).The default is
true. If set tofalseall 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 givenCmsMessageContainerto 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
-