public abstract class JcmsFormHandler extends JcmsJspContext implements JcmsConstants
To implement a custom form handler :
processAction()
to check for any operation, validate precondition and perform action,The following example demonstrate uses of a form handler to receive a firstname as an input and when validated display a Hello World message to the user
Java filecom.example.jcmsplugin.hello.HelloWorldHandler.java
:
package com.example.jcmsplugin.hello; import java.io.IOException; import com.jalios.jcms.HttpUtil; import com.jalios.jcms.context.JcmsMessage; import com.jalios.jcms.context.JcmsMessage.Level; import com.jalios.jcms.handler.JcmsFormHandler; import com.jalios.util.Util; public class HelloWorldHandler extends JcmsFormHandler { // Possible operations private boolean opSayHello = false; private boolean opCancel = false; // Member variables private String firstname = null; @Override public boolean processAction() throws IOException { if (validateSayHello()) { return performSayHello(); } if (validateCancel()) { return performCancel(); } return false; } // --------------------------------------------------------------- // Say Hello // --------------------------------------------------------------- public boolean validateSayHello() { if (!opSayHello) { return false; } if (Util.isEmpty(this.firstname)) { addMsg(new JcmsMessage(Level.WARN, glp("jcmsplugin.myplugin.myhandler.missing-firsname"))); return false; } return true; } public boolean performSayHello() throws IOException { // In I18N properties : // jcmsplugin.myplugin.myhandler.say-hello: Hello {0} ! // addMsgSession(request, new JcmsMessage(Level.INFO, glp("jcmsplugin.myplugin.myhandler.say-hello", HttpUtil.encodeForHTML(firstname)))); return false; } // --------------------------------------------------------------- // Cancel // --------------------------------------------------------------- public boolean validateCancel() { return opCancel; } public boolean performCancel() throws IOException { sendRedirect(Util.notEmpty(redirect) ? redirect : "index.jsp"); return true; } // --------------------------------------------------------------- // Setters // --------------------------------------------------------------- public void setOpSayHello(String opSayHello) { this.opSayHello = true; } public void setOpCancel(String opCancel) { this.opCancel = true; } public String getFirstname() { return this.firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } }JSP
sayHello.jsp
:
<%@ include file='/jcore/doInitPage.jsp' %><% %><jsp:useBean id="formHandler" scope="page" class="com.example.jcmsplugin.hello.HelloWorldHandler"><% %><jsp:setProperty name="formHandler" property="request" value="<%= request %>" /><% %><jsp:setProperty name="formHandler" property="response" value="<%= response %>" /><% %><jsp:setProperty name="formHandler" property="*" /><% %></jsp:useBean><% if (formHandler.validate()) { return; } %><%@ include file='/jcore/doEmptyHeader.jsp' %><% %><%@ include file='/jcore/doMessageBox.jsp' %> <div id='hello'> <form action="sayHello.jsp" name="sayHelloForm" method="post"> <%-- Inputs --%> <jalios:widget editor ='<%= AbstractWidget.UI_EDITOR_TEXTFIELD %>' widgetName ='<%= "firstname" %>' formName ='<%= "sayHelloForm" %>' value ='<%= formHandler.getFirstname() %>' label ='<%= glp("ui.adm.mbr-edit.lbl.f-name") %>' printLabel ='<%= true %>' /> <%-- Hidden Inputs --%> <% if (Util.notEmpty(formHandler.getRedirect())) { %> <input type="hidden" name="redirect" value="<%= encodeForHTMLAttribute(formHandler.getRedirect()) %>" /> <% } %> <%-- Buttons --%> <%= WidgetUtil.printHtmlButton("opSayHello", glp("jcmsplugin.btn.sayhello"), true, null, true) %> <%= WidgetUtil.printHtmlButton("opCancel", glp("ui.com.btn.cancel"), true, null, false) %> </form> </div>Data Handlers (handlers inheriting from
EditDataHandler
) must perform
additionnal operation, see corresponding JavaDoc.Modifier and Type | Field and Description |
---|---|
protected java.util.HashMap<java.lang.String,java.lang.Object> |
contextMap |
protected java.util.HashSet |
editFieldSet |
protected boolean |
noRedirect |
protected boolean |
noSendRedirect |
protected boolean |
popupEdition |
protected java.lang.String |
redirect |
protected boolean |
redirectOnClosePopup |
static java.lang.String |
REVISION |
protected boolean |
workspaceForced |
AJAX_REQUEST_ATTRIBUTES, BODY_HEADER, CSS_HEADER, cssboMap, cssfoMap, CUSTOM_HEADER, editIcon, HTTPEQUIV_HEADER, httpequivMap, HTTPNAME_HEADER, httpnameMap, initEditIcon, JAVASCRIPT_CODE_SET_ATTRIBUTE, JAVASCRIPT_SET_ATTRIBUTE, jsboSet, jsfoSet, out, pageContext, SHOW_EDIT_ICON, STYLE_HEADER
browser, caddy, channel, inFO, initDone, initWorkspace, isAdmin, isAjaxRequest, isDBMember, isDebug, isLogged, loggedMember, request, response, userCountry, userLang, userLocale, workspace
ADATE_SEARCH, ADMIN_NOTES_PROP, ADVANCED_TAB, ARCHIVES_DIR, ASCII_WIDTH, CATEGORY_TAB, CDATE_SEARCH, COMMON_ALARM, CONTENT_TAB, COOKIE_MAX_AGE, CTRL_TOPIC_INTERNAL, CTRL_TOPIC_REF, CTRL_TOPIC_VALUE, CTRL_TOPIC_WRITE, CUSTOM_PROP, DOCCHOOSER_HEIGHT, DOCCHOOSER_WIDTH, DOCS_DIR, EDATE_SEARCH, EMAIL_REGEXP, ERROR_MSG, FORBIDDEN_FILE_ACCESS, FORBIDDEN_REDIRECT, FORCE_REDIRECT, ICON_ARCHIVE, ICON_LOCK, ICON_LOCK_STRONG, ICON_WARN, ICON_WH_BOOK_CLOSED, ICON_WH_BOOK_OPEN, INFORMATION_MSG, JALIOS_JUNIT_PROP, JCMS_CADDY, JCMS_MSG_LIST, JSYNC_DOWNLOAD_DIR, JSYNC_SYNC_ALARM, LOG_FILE, LOG_TOPIC_SECURITY, LOGGER_PROP, LOGGER_XMLPROP, MBR_PHOTO_DIR, MDATE_SEARCH, MONITOR_XML, OP_CREATE, OP_CREATE_STR, OP_DEEP_COPY, OP_DEEP_COPY_STR, OP_DEEP_DELETE, OP_DEEP_DELETE_STR, OP_DELETE, OP_DELETE_STR, OP_MERGE, OP_MERGE_STR, OP_UPDATE, OP_UPDATE_STR, PDATE_SEARCH, PHOTO_DIR, PHOTO_ICON, PHOTO_ICON_HEIGHT, PHOTO_ICON_WIDTH, PHOTO_LARGE, PHOTO_LARGE_HEIGHT, PHOTO_LARGE_WIDTH, PHOTO_NORMAL, PHOTO_NORMAL_HEIGHT, PHOTO_NORMAL_WIDTH, PHOTO_SMALL, PHOTO_SMALL_HEIGHT, PHOTO_SMALL_WIDTH, PHOTO_TINY, PHOTO_TINY_HEIGHT, PHOTO_TINY_WIDTH, PREVIOUS_TAB, PRINT_VIEW, PRIVATE_FILE_ACCESS, PUBLIC_FILE_ACCESS, READ_RIGHT_TAB, SDATE_SEARCH, SEARCHENGINE_ALARM, SESSION_AUTHORIZED_FILENAMES_SET, STATS_REPORT_DIR, STATUS_PROP, STORE_XML, TEMPLATE_TAB, THUMBNAIL_LARGE_HEIGHT, THUMBNAIL_LARGE_WIDTH, THUMBNAIL_SMALL_HEIGHT, THUMBNAIL_SMALL_WIDTH, TYPES_ICON_ALT_PROP, TYPES_ICON_SUFFIX_PROP, TYPES_ICON_TITLE_PROP, TYPES_PREFIX_PROP, TYPES_THUMB_SUFFIX_PROP, UDATE_SEARCH, UPDATE_RIGHT_TAB, UPLOAD_DIR, URL_REGEXP, WARNING_MSG, WEBAPP_PROP, WFEXPRESS_ALARM, WFREMINDER_ALARM, WORKFLOW_TAB, WORKFLOW_XML
CRLF, MILLIS_IN_ONE_DAY, MILLIS_IN_ONE_HOUR, MILLIS_IN_ONE_MINUTE, MILLIS_IN_ONE_MONTH, MILLIS_IN_ONE_SECOND, MILLIS_IN_ONE_WEEK, MILLIS_IN_ONE_YEAR
Constructor and Description |
---|
JcmsFormHandler() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
afterValidation(boolean result) |
protected boolean |
checkMissingField(java.lang.Object obj,
java.lang.String prop) |
protected java.util.HashMap<java.lang.String,java.lang.Object> |
getControllerContext()
Build a controller context.
|
java.util.HashSet |
getEditFieldSet() |
java.lang.String |
getHiddenField(java.lang.String name,
boolean value) |
java.lang.String |
getHiddenField(java.lang.String name,
boolean[] array) |
java.lang.String |
getHiddenField(java.lang.String name,
Data value) |
java.lang.String |
getHiddenField(java.lang.String name,
Data[] datas) |
java.lang.String |
getHiddenField(java.lang.String name,
java.util.Date value) |
java.lang.String |
getHiddenField(java.lang.String name,
java.util.Date[] array) |
java.lang.String |
getHiddenField(java.lang.String name,
double value) |
java.lang.String |
getHiddenField(java.lang.String name,
double[] array) |
java.lang.String |
getHiddenField(java.lang.String name,
int value) |
java.lang.String |
getHiddenField(java.lang.String name,
int[] array) |
java.lang.String |
getHiddenField(java.lang.String name,
long value) |
java.lang.String |
getHiddenField(java.lang.String name,
long[] array) |
<T extends Data> |
getHiddenField(java.lang.String name,
java.util.Set<T> set) |
java.lang.String |
getHiddenField(java.lang.String name,
java.lang.String value) |
java.lang.String |
getHiddenField(java.lang.String name,
java.lang.String[] array) |
java.lang.String |
getHiddenFieldML(java.lang.String name,
java.util.HashMap<java.lang.String,java.lang.String> map) |
protected java.lang.String |
getMainLangValue(java.lang.String[] array,
boolean trim,
boolean escape)
Returns the first value (i.e. the main language value) from the given array (monovalued ML fields).
|
protected java.lang.String[] |
getMainLangValueArray(java.lang.String[] array,
boolean trim,
boolean escape)
Returns the first values (i.e. the main language value) from the given array (multivalued ML fields).
|
protected java.util.HashMap<java.lang.String,java.lang.String> |
getMLMap(java.lang.String[] array,
boolean trim,
boolean escape)
Returns the ML map (i.e. the additionnal languages) filled with the values contained in the given array (monovalued ML fields).
|
protected java.util.HashMap<java.lang.String,java.lang.String[]> |
getMLMapArray(java.lang.String[] array,
boolean trim,
boolean escape)
Returns the ML map (i.e. the additionnal languages) filled with the values contained in the given array (multivalued ML fields).
|
java.lang.String |
getRedirect()
Get the value of redirect.
|
boolean |
getRedirectOnClosePopup()
Return the value indicating whether the redirect value should be
applied to the opener when closing the popup edition.
|
Workspace |
getWorkspace()
Retrieve the current Workspace variable for this context either from
request if inFO or from session if in back office.
|
protected void |
init()
Method to implement if you need to initialize your handler from parameter received,
prior to all security validation.
|
boolean |
isFieldEdition(java.lang.String field) |
protected boolean |
isFieldMissing(java.lang.String field)
Check if the given parameter is present in the query parameters
|
boolean |
isPartialFieldEdition()
Returns true if this is a partial field edition (i.e. front edition)
|
boolean |
isPopupEdition() |
boolean |
isWorkspaceForced() |
boolean |
processAction()
Method to be implemented to check/validate action to be performed and process them.
|
protected boolean |
processStatus(ControllerStatus status)
Process the ControllerStatus: do nothing if OK, or send on
forbidden, or put a warning message in the request.
|
void |
sendRedirect(java.lang.String url)
Redirect current request to given URL.
|
void |
sendRedirect(java.lang.String url,
boolean checkRedirect)
Set the redirect in the response.
|
void |
setEditField(java.lang.String[] v) |
void |
setNoRedirect(boolean noRedirect)
Set the value of noRedirect.
|
void |
setNoSendRedirect(boolean noSendRedirect)
Set the value of noSendRedirect.
|
void |
setPopupEdition(boolean v)
Set where this form handler is being invoked in a popup.
|
void |
setRedirect(java.lang.String url)
Set the value of redirect.
|
void |
setRedirectOnClosePopup(boolean redirectOnClosePopup)
Set whether the redirect value should be applied to the opener when
closing the popup edition.
|
void |
setWorkspace(Workspace wspc) |
void |
setWs(java.lang.String v) |
protected java.lang.String |
updateUploadedField(java.lang.String fieldName,
java.lang.String value,
boolean isFileDocument,
boolean override)
Perform upload then, return value of the real File realtive path.
|
protected void |
updateUploadedFields(java.lang.String fieldName,
java.lang.String[] values,
boolean isFileDocument,
boolean override)
Perform upload then, replace all values with value MultipartRequest.MULTIPART_UPLOAD
with the real File realtive path.
|
boolean |
validate()
Method invoked by JSP to validate all conditions (authorization, parameters, ...),
and eventualy trigger the action that was requested to the handler.
|
addBodyAttributes, addCSSHeader, addCSSHeader, addCSSHeader, addCSSHeader, addCustomHeader, addHttpEquivHeader, addHttpNameHeader, addJavaScript, addJavaScript, addJavaScript, addJavaScriptCode, addPrefetchHeader, addStyleHeader, addStyleHeader, checkAccess, checkAccess, checkCSRF, debugDisplayContext, disablePacker, forceEditIcon, forceUpdate, getAjaxRequestAttribute, getAjaxRequestId, getAllHeadersDiffMap, getAllHeadersMap, getBackOfficeCSSHeader, getBackOfficeJavaScriptSet, getBodyAttributes, getContentForm, getCSSHeaders, getCtxCategories, getCurrentCategory, getCustomHeaders, getDocType, getFinalCSSMap, getFinalJavaScriptSet, getFormElementCount, getFrontOfficeCSSHeader, getFrontOfficeJavaScriptSet, getHttpEquivHeaders, getHttpNameHeaders, getJavaScriptCodeSet, getJavaScriptSet, getJSONBridge, getPackVersion, getPageContext, getPageTitle, getPageZone, getPortal, getPortalCategory, getPortlet, getPublication, getStyleHeaders, getTemplateUsage, internalSetupEmptyHeader, isEditIcon, isEditIcon, isPrintView, registerDisplayContext, removeAjaxRequestAttribute, setAjaxRequestAttribute, setAjaxRequestId, setAllHeadersDiffMap, setDocType, setEditIcon, setFormElementCount, setPageContext, setPageTitle, setPageZone, setShowEditIcon, setTemplateUsage, showEditIcon, showEditIcon, workaroundBrowserBaseHrefBug
addCookie, addMsg, addMsg, addMsgSession, addMsgSession, applySelector, forceWorkspaceUpdate, getBaseUrl, getBrowser, getCaddy, getContextPath, getErrorMsg, getErrorMsgList, getErrorMsgSession, getErrorMsgSessionList, getInfoMsg, getInfoMsgList, getInfoMsgSession, getInfoMsgSessionList, getLoggedMember, getMsgList, getMsgSessionList, getRequest, getResponse, getSession, getUploadedFile, getUploadedFileList, getUrlWithCommonUpdatedParams, getUserCountry, getUserLang, getUserLocale, getWarningMsg, getWarningMsgList, getWarningMsgSession, getWarningMsgSessionList, glp, isAdmin, isAjaxRequest, isDBMember, isDebug, isInFrontOffice, isLogged, isWebdavAccess, removeMessage, removeMessage, retrieveUploadedFile, select, sendForbidden, sendForbidden, sendRedirect, sendRedirect, sendRedirect, setErrorMsg, setErrorMsg, setErrorMsgSession, setErrorMsgSession, setInfoMsg, setInfoMsg, setInfoMsgSession, setInfoMsgSession, setLoggedMember, setRequest, setResponse, setWarningMsg, setWarningMsg, setWarningMsgSession, setWarningMsgSession, validateRegexp, validateSchedule
public static final java.lang.String REVISION
protected java.lang.String redirect
protected boolean noRedirect
protected boolean noSendRedirect
protected boolean redirectOnClosePopup
protected boolean workspaceForced
protected boolean popupEdition
protected java.util.HashSet editFieldSet
protected java.util.HashMap<java.lang.String,java.lang.Object> contextMap
protected void init()
You must absolutely not perform any action which modify data or site configuration.
Therefore it is strongly recommend NOT TO implement this method, or use very wisely.
public boolean validate() throws java.io.IOException
You MUST not override this method to validate and perform your action, instead
implement processAction()
if you need to provide custom actions.
As of current implementation, this method is NOT final to ensure backward compatibility with older handler which may have had a validate() method. But it WILL end as a final method.
java.io.IOException
- if error occured during validateprotected boolean afterValidation(boolean result) throws java.io.IOException
java.io.IOException
public boolean processAction() throws java.io.IOException
Default implementation is to return false. No need to call super method.
This method may NOT be invoked at all if security validation are not met.
You must ensure your handler and JSP can work properly without any code invoked
in this method.
java.io.IOException
public Workspace getWorkspace()
JcmsContext
getWorkspace
in class JcmsContext
public boolean isWorkspaceForced()
public void setWorkspace(Workspace wspc)
public void setWs(java.lang.String v)
public void sendRedirect(java.lang.String url, boolean checkRedirect) throws java.io.IOException
url
- the url to redirect to.checkRedirect
- if true and if redirect attribute has been set, redirect on this urljava.io.IOException
public void sendRedirect(java.lang.String url) throws java.io.IOException
JcmsContext.sendRedirect(String)
to use behavior
provided by sendRedirect(String, boolean)
.sendRedirect
in class JcmsContext
url
- the url to redirect to.java.io.IOException
- if an error occured while writing in response headersJcmsContext.sendRedirect(String, HttpServletRequest, HttpServletResponse)
public java.lang.String getRedirect()
public void setRedirect(java.lang.String url)
url
- Value to assign to redirect.public void setNoRedirect(boolean noRedirect)
noRedirect
- Value to assign to noRedirect.public void setNoSendRedirect(boolean noSendRedirect)
noSendRedirect
- Value to assign to noSendRedirect.public final void setRedirectOnClosePopup(boolean redirectOnClosePopup)
setPopupEdition(boolean)
).redirectOnClosePopup
- if true, the redirect value (setRedirect(String)
)
will be provided to closePopup.jsp to redirect the opener. if false,
the popup will simply be closed and the opener refreshed.public final boolean getRedirectOnClosePopup()
setRedirect(String)
)
will be provided to closePopup.jsp to redirect the opener. false,
if the popup will simply be closed and the opener refreshed.protected boolean processStatus(ControllerStatus status) throws java.io.IOException
status
- the ControllerStatus to be processedjava.io.IOException
protected java.util.HashMap<java.lang.String,java.lang.Object> getControllerContext()
protected boolean isFieldMissing(java.lang.String field)
field
- the field to be checkedpublic void setPopupEdition(boolean v)
v
- true if handler is invoked in popup, false otherwisepublic boolean isPopupEdition()
public void setEditField(java.lang.String[] v)
v
- a set of field names to editepublic java.util.HashSet getEditFieldSet()
public boolean isFieldEdition(java.lang.String field)
field
- getEditFieldSet()
public boolean isPartialFieldEdition()
protected java.lang.String updateUploadedField(java.lang.String fieldName, java.lang.String value, boolean isFileDocument, boolean override)
fieldName
- the field namevalue
- the field fake valueprotected void updateUploadedFields(java.lang.String fieldName, java.lang.String[] values, boolean isFileDocument, boolean override)
fieldName
- the field namevalues
- the field fake valuesprotected java.lang.String getMainLangValue(java.lang.String[] array, boolean trim, boolean escape)
array
- the arraytrim
- if true trim the valueescape
- if true escape the valueprotected java.util.HashMap<java.lang.String,java.lang.String> getMLMap(java.lang.String[] array, boolean trim, boolean escape)
array
- the arraytrim
- if true trim the valuesescape
- if true escape the valuesprotected java.lang.String[] getMainLangValueArray(java.lang.String[] array, boolean trim, boolean escape)
array
- the arraytrim
- if true trim the valuesescape
- if true escape the valuesprotected java.util.HashMap<java.lang.String,java.lang.String[]> getMLMapArray(java.lang.String[] array, boolean trim, boolean escape)
array
- the arraytrim
- if true trim the valuesescape
- if true escape the valuespublic java.lang.String getHiddenField(java.lang.String name, java.lang.String value)
public java.lang.String getHiddenFieldML(java.lang.String name, java.util.HashMap<java.lang.String,java.lang.String> map)
public java.lang.String getHiddenField(java.lang.String name, Data value)
public java.lang.String getHiddenField(java.lang.String name, boolean value)
public java.lang.String getHiddenField(java.lang.String name, int value)
public java.lang.String getHiddenField(java.lang.String name, double value)
public java.lang.String getHiddenField(java.lang.String name, long value)
public java.lang.String getHiddenField(java.lang.String name, java.util.Date value)
public java.lang.String getHiddenField(java.lang.String name, Data[] datas)
public java.lang.String getHiddenField(java.lang.String name, boolean[] array)
public java.lang.String getHiddenField(java.lang.String name, int[] array)
public java.lang.String getHiddenField(java.lang.String name, long[] array)
public java.lang.String getHiddenField(java.lang.String name, double[] array)
public java.lang.String getHiddenField(java.lang.String name, java.lang.String[] array)
public java.lang.String getHiddenField(java.lang.String name, java.util.Date[] array)
public <T extends Data> java.lang.String getHiddenField(java.lang.String name, java.util.Set<T> set)
protected boolean checkMissingField(java.lang.Object obj, java.lang.String prop)
Copyright © 2001-2010 Jalios SA. All Rights Reserved.