Class JcmsFormHandler
- All Implemented Interfaces:
JcmsConstants,JaliosConstants
- Direct Known Subclasses:
AbstractAutocompleteHandler,AbstractCaddyHandler,AbstractChooserHandler,AbstractFullCalendarActionHandler,AbstractQueryHandler,AccessTokenManagerHandler,AddGroupMembersHandler,AddJPortalServiceHandler,AdminHandler,AdminSearchEnginesHandler,AdminStartAnalysisHandler,AlertHandler,ApplicationAppModalHandler,ApplicationDefaultAppHandler,ApplicationDeployHandler,ApplicationLauncherActionsHandler,ApplicationQueryHandler,AssociatedPDFUploadHandler,AsyncShortcutHandler,AuditApplicationLauncherModal,AvoidanceLinkAdminEditHandler,BackgroundProcessHandler,BackOfficeActionHandler,BackOfficeDisplayHandler,CacheManagerHandler,CategoryCleanerHandler,CategoryListHandler,CheckIntegrityHandler,CheckRightsHandler,ClassificationAdminHandler,CompositePropertiesHandler,ContentSecurityPolicyAdminHandler,DashboardAppHandler,DataReportHandler,DBPublicationCategoriesCheckerHandler,DelegateConfirmModalHandler,DemoHandler,DemoModalHandler,DemoModalStepHandler,DisplayPluginHandler,DuplicateThemeHandler,EditAlertRuleHandler,EditDataHandler,EditFontHandler,EditImageHandler,EditLocalFontHandler,EditMailProviderHandler,EditMemberProfilingHandler,EditPaletteHandler,EditPluginHandler,EditWFHandler,EditWFRoleHandler,EditWFStateHandler,ExportCategoriesHandler,FavoriteWorkspaceHandler,FileProcessorAdminHandler,FriendlyURLsHandler,GroupDisplayHandler,GroupListHandler,IconChooserModalHandler,ImportConflictHandler,ImportManagerHandler,JBlockEditorHandler,JcmsJsonActionHandler,JcmsUploadFormHandler,JPortalDisplayHandler,JPortalEditorHandler,JPortalEditPorletHandler,JPortalEditPortletUIHandler,JPortalHistoryHandler,JSyncManagerHandler,LegacyWitnessFileImportHandler,LoggingSetupHandler,MailEditHandler,MailPasswordHandler,MediaActionsHandler,MediaInfosHandler,MediaStockQueryHandler,MediaTracksHandler,MemberAlertSettingsHandler,MemberDisplayHandler,MemberListHandler,MemberPhotoGroupModalHandler,MergeCategoryHandler,MergeFileDocumentHandler,ModalPromptHandler,MonitoringChartHandler,PluginDataInfosHandler,PortletDisplayHandler,PortletIndicatorDisplayHandler,PortletWorkflowHandler,ProcessL10nHandler,ProfilerHandler,PropertiesEditorHandler,PropertiesHandler,PubBrowserHandler,PublicationDisplayHandler,PublicationFollowerHandler,PublicationUnifiedInsertQueryHandler,PublicDownloadHandler,PublicLinkAppHandler,ReadAckHandler,ReaderTrackerQueryHandler,RecommendApplicationHandler,RecommendationHandler,RecommendationReaderTrackerHandler,RemoveGroupMemberHandler,ReportHandler,ResetApplicationLauncherModal,ResetPasswordHandler,SelectSubGroupsHandler,SendAlertHandler,SidebarHandler,SiteLanguageHandler,StoreAnonymizerHandler,StoreCleanerHandler,SyncLdapHandler,TemplateInitialisationHandler,ThemingToolAppHandler,ThumbnailActionsHandler,TopbarApplicationMenuBadgeHandler,TopbarCaddyMenuHandler,TopbarHandler,TrackerAppHandler,TranstypingHandler,TypeEditorHandler,TypeListEditorHandler,UnifiedInsertHandler,UploadPluginHandler,VersionHandler,WFEditorHandler,WFListHandler,WorkReportHandler,WorkspaceRoleListHandler,WorkspaceWizardHandler,WysiwygInlineEditionHandler
To implement a custom form handler :
- Add setters to trigger custom operations,
- Add setters for receive optional parameters,
- Implement
processAction()to check for any operation, validate precondition and perform action, - Create a JSP :
- with the handler as a JavaBean
- for which you'll invoke the validate() method
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.jspf' %><%
%><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.jspf' %><%
%><%@ include file='/jcore/doMessageBox.jspf' %>
<div id='hello'>
<form action="sayHello.jsp" name="sayHelloForm" method="post">
<%-- Inputs --%>
<jalios:field name="firstname" formHandler="<%= formHandler %>">
<jalios:control />
</jalios:field>
<%-- Hidden Inputs --%>
<jalios:control settings='<%= new HiddenSettings().name("redirect").value(formHandler.getRedirect()) %>' />
<%-- Buttons --%>
<jalios:button name="opSayHello" label="jcmsplugin.btn.sayhello" buttonType="<%= ButtonType.BUTTON_SUBMIT %>" css="btn btn-primary" />
<jalios:button name="opCancel" label="ui.com.btn.cancel" buttonType="<%= ButtonType.BUTTON_SUBMIT %>" css="btn btn-default" />
</form>
</div>
<%@ include file='/jcore/doEmptyFooter.jspf' %>
Data Handlers (handlers inheriting from EditDataHandler) must perform
additionnal operation, see corresponding JavaDoc.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanBoolean indicating if CSRF validation should be performed (true, which is the default), or not (false).protected intprotected booleanprotected booleanprotected booleanprotected Stringprotected booleanprotected booleanprotected booleanprotected booleanprotected Stringprotected booleanprotected booleanFields inherited from class com.jalios.jcms.context.JcmsJspContext
AJAX_REQUEST_ATTRIBUTES, BODY_HEADER, CSS_FOOTER, CSS_HEADER, cssboMap, cssfoMap, CUSTOM_HEADER, editIcon, HTTPEQUIV_HEADER, httpequivMap, HTTPNAME_HEADER, httpnameMap, initEditIcon, JAVASCRIPT_CODE_SET_ATTRIBUTE, JAVASCRIPT_MODULE_SET_ATTRIBUTE, JAVASCRIPT_SET_ATTRIBUTE, jsboSet, jsfoSet, out, pageContext, SHOW_EDIT_ICON, STYLE_HEADERFields inherited from class com.jalios.jcms.context.JcmsContext
browser, caddy, channel, inFO, initDone, initWorkspace, isAdmin, isAjaxRequest, isDBMember, isDebug, isDebugTemplatePath, isLogged, loggedMember, request, response, userCountry, userLang, userLocale, userZoneId, workspaceFields inherited from interface com.jalios.util.JaliosConstants
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_YEARFields inherited from interface com.jalios.jcms.JcmsConstants
ADATE_SEARCH, ADVANCED_TAB, AJAX_MODE_ATTR, ARCHIVES_DIR, ASCII_WIDTH, CATEGORY_TAB, CDATE_SEARCH, CLASS_PROPERTY, COMMON_ALARM, CONTENT_TAB, COOKIE_MAX_AGE, COUNTRY_SPRITE, CS_TYPOLOGY_ROOT_CAT_VID, CTRL_TOPIC_INTERNAL, CTRL_TOPIC_REF, CTRL_TOPIC_VALUE, CTRL_TOPIC_WRITE, CUSTOM_PROP, DATA_DIRECTORY, DEFAULT_PHOTO_PROP, DOCCHOOSER_HEIGHT, DOCCHOOSER_WIDTH, DOCS_DIR, EDATE_SEARCH, EMAIL_REGEXP, ERROR_MSG, FORBIDDEN_FILE_ACCESS, FORBIDDEN_REDIRECT, FORCE_REDIRECT, GENERATIONAL_STORE_DIRECTORY, GLYPH_ICON_PREFIX, ICON_ARCHIVE, ICON_ICON_PREFIX, ICON_LOCK, ICON_LOCK_STRONG, ICON_PREFIX_PROP, ICON_WARN, ICON_WH_BOOK_CLOSED, ICON_WH_BOOK_OPEN, INFORMATION_MSG, IS_IN_FRONT_OFFICE, JALIOS_JUNIT_PROP, JCMS_CADDY, JCMS_MSG_LIST, JCMS_TOASTR_COLLECTION, JSYNC_DOWNLOAD_DIR, JSYNC_SYNC_ALARM, LANG_SPRITE, 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, ORGANIZATION_ROOT_GROUP_PROP, PDATE_SEARCH, PHOTO_DIR, PHOTO_ICON, PHOTO_ICON_HEIGHT, PHOTO_ICON_PROP_PREFIX, PHOTO_ICON_WIDTH, PHOTO_LARGE, PHOTO_LARGE_HEIGHT, PHOTO_LARGE_PROP_PREFIX, PHOTO_LARGE_WIDTH, PHOTO_MINI, PHOTO_MINI_HEIGHT, PHOTO_MINI_PROP_PREFIX, PHOTO_MINI_WIDTH, PHOTO_NORMAL, PHOTO_NORMAL_HEIGHT, PHOTO_NORMAL_PROP_PREFIX, PHOTO_NORMAL_WIDTH, PHOTO_SMALL, PHOTO_SMALL_HEIGHT, PHOTO_SMALL_PROP_PREFIX, PHOTO_SMALL_WIDTH, PHOTO_TINY, PHOTO_TINY_HEIGHT, PHOTO_TINY_PROP_PREFIX, PHOTO_TINY_WIDTH, PHOTO_XLARGE, PHOTO_XLARGE_HEIGHT, PHOTO_XLARGE_PROP_PREFIX, PHOTO_XLARGE_WIDTH, PREVIOUS_TAB, PRINT_VIEW, PRIVATE_FILE_ACCESS, PUBLIC_FILE_ACCESS, RAW_CONTENT_ICON_PREFIX, READ_RIGHT_TAB, SDATE_SEARCH, SEARCHENGINE_ALARM, SECURITY_LOG_FILE, SESSION_AUTHORIZED_FILENAMES_SET, SPRITE_ICON_PREFIX, STATS_REPORT_DIR, STATUS_PROP, STORE_XML, SUCCESS_MSG, SVG_ICON_PREFIX, SVGINLINE_ICON_PREFIX, SVGSPRITE_ICON_PREFIX, TEMPLATE_TAB, THEME_DIR, THUMBNAIL_LARGE_HEIGHT, THUMBNAIL_LARGE_WIDTH, THUMBNAIL_SMALL_HEIGHT, THUMBNAIL_SMALL_WIDTH, TTCARD_MEDIA_HEIGHT, TTCARD_MEDIA_WIDTH, TYPES_ICON_ALT_PROP, TYPES_ICON_SUFFIX_PROP, TYPES_ICON_TITLE_PROP, TYPES_PREFIX_PROP, TYPES_THUMB_SUFFIX_PROP, TYPES_UNKNOWN_CLASS_PROP, UDATE_SEARCH, UPDATE_RIGHT_TAB, UPLOAD_DIR, UPLOAD_PERMISSION_COUNT_PROP_PREFIX, UPLOAD_PERMISSION_SIZE_PROP_PREFIX, URL_REGEXP, VID_LOGGED_MEMBER, WARNING_MSG, WEBAPP_PROP, WFEXPRESS_ALARM, WFREMINDER_ALARM, WORKFLOW_TAB, WORKFLOW_XML -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanafterValidation(boolean result) protected ControllerStatuscanStartProcess(BackgroundProcess process) protected booleancheckMissingField(Object obj, String prop) protected StringBuild a controller context.intRetrieve the current step of edition when invoking this form handler.intRetrieve the total number of steps used for edition when invoking this form handler.String[]getFormStepLabels(String userLang) Returns the label array for the steps.getHiddenField(String name, boolean value) getHiddenField(String name, boolean[] array) getHiddenField(String name, double value) getHiddenField(String name, double[] array) getHiddenField(String name, int value) getHiddenField(String name, int[] array) getHiddenField(String name, long value) getHiddenField(String name, long[] array) getHiddenField(String name, Data value) getHiddenField(String name, Data[] array) getHiddenField(String name, String value) getHiddenField(String name, String[] array) getHiddenField(String name, Collection<String> coll) getHiddenField(String name, Date value) getHiddenField(String name, Date[] array) getHiddenField(String name, Set<T> set) getHiddenFieldML(String name, HashMap<String, String> map) protected StringgetMainLangValue(String[] array, boolean trim, boolean escape) Returns the first value (i.e.protected String[]getMainLangValueArray(String[] array, boolean trim, boolean escape) Deprecated.Returns the ML map (i.e.getMLMapArray(String[] array, boolean trim, boolean escape) Deprecated.Get the redirect value to be used in the modals with modalRedirect.jspf and the request attribute 'modal.redirect'.protected static StringgetMonolingualValue(TypeFieldEntry tfe, String[] array) Return the first value from the given array, properly sanitized for usage in the specified field.protected static String[]getMonolingualValueArray(TypeFieldEntry tfe, String[] array) Return the values from the given array, properly sanitized for usage in the specified field.static StringgetMultilingualMainValue(TypeFieldEntry tfe, String[] array) Return the main value (ie: value of main site language) from the given array, properly sanitized for usage in the specified multilingual field.protected static String[]getMultilingualMainValueArray(TypeFieldEntry tfe, String[] array) Return the main values (ie: values of main site language) from the given array, properly sanitized for usage in the specified multilingual field.getMultilingualMLMap(TypeFieldEntry tfe, String[] array) Return a language map (ISO-639 language code to value) of all values but the value corresponding main site language, extracted from the specified array, and properly sanitized for usage in the specified multilingual field.getMultilingualMLMapArray(TypeFieldEntry tfe, String[] array) Return a language map (ISO-639 language code to values) of all values but the value corresponding main site language, extracted from the specified array, and properly sanitized for usage in the specified multilingual field.Return the id of the tab to openGet the value of redirect.final booleanReturn the value indicating whether the redirect value should be applied to the opener when closing the popup edition.Retrieve the current Workspace variable for this context either from request if inFO or from session if in back office.protected voidinit()Method to implement if you need to initialize your handler from parameter received, prior to all security validation.booleanisFieldEdition(String field) protected booleanisFieldMissing(String field) Check if the given parameter is present in the query parametersbooleanReturns true if the form step are clickable.booleanReturns true if this is a partial field edition (i.e.booleanbooleanmapStringArrayToMapStringList(Map<String, String[]> map) Convert a map contaning Array of String, into to a map containg List of String.Convert a map contaning List of String, into to a map containg Array of String.protected booleanCheck behavior to apply on CSRF error.protected booleanprotected booleanprotected booleanprotected booleanMethod to be implemented to check/validate action to be performed and process them.protected booleanprocessStatus(ControllerStatus status) Process the ControllerStatus: do nothing if OK, or send on forbidden, or put a warning message in the request.static final Stringsanitize(TypeFieldEntry tfe, String unsafeInput) Sanitize the specified input string for the usage of the specified field.static final String[]sanitize(TypeFieldEntry tfe, String[] unsafeInput) Sanitize the specified input strings for the usage of the specified field.voidsendRedirect(String url) Redirect current request to given URL.
OverridesJcmsContext.sendRedirect(String)to use behavior provided bysendRedirect(String, boolean).voidsendRedirect(String url, boolean checkRedirect) Set the redirect in the response.voidsetEditField(String[] v) voidsetFormStep(int step) Set the current step of edition when invoking this form handler.voidsetNoRedirect(boolean noRedirect) Set the value of noRedirect.voidsetNoSendRedirect(boolean noSendRedirect) Set the value of noSendRedirect.voidsetOpenTabId(String openTabId) Set id of the opened tabvoidvoidvoidvoidsetPopupEdition(boolean v) Set where this form handler is being invoked in a popup.voidsetRedirect(String url) Set the value of redirect.final voidsetRedirectOnClosePopup(boolean redirectOnClosePopup) Set whether the redirect value should be applied to the opener when closing the popup edition.
The value set by this method will be used only when using popup edition (setPopupEdition(boolean)).voidsetWorkspace(Workspace wspc) voidbooleanCheck if the "Cancel" button should be displayed in step modal form.booleanCheck if the "Finish" button should be displayed in step modal form.booleanCheck if the "Next" button should be displayed in step modal form.booleanCheck if the "Previous" button should be displayed in step modal form.protected CompletableFuture<Void> startProcess(BackgroundProcess process) protected voidupdateUploadedFields(String fieldName, String[] values, FileUploadOptions options) Perform upload then, replace all values with value MultipartRequest.MULTIPART_UPLOAD with the real File realtive path.final booleanvalidate()Method invoked by JSP to validate all conditions (authorization, parameters, ...), and eventualy trigger the action that was requested to the handler.protected booleanprotected booleanprotected booleanprotected booleanMethods inherited from class com.jalios.jcms.context.JcmsJspContext
addAvoidanceLink, addBodyAttributes, addCSSHeader, addCSSHeader, addCSSHeader, addCSSHeader, addCustomHeader, addHandlebarTemplate, addHttpEquivHeader, addHttpNameHeader, addJavaScript, addJavaScript, addJavaScript, addJavaScriptCode, addJavaScriptModule, addPrefetchHeader, addStyleHeader, addStyleHeader, addSvgSpriteIcon, addWebAssets, canAccessAdminArea, checkAccess, checkAccess, checkCSRF, debugDisplayContext, disablePacker, forceEditIcon, forceUpdate, getAjaxRequestAttribute, getAjaxRequestId, getAllHeadersDiffMap, getAllHeadersMap, getAvoidanceLinks, getBackOfficeCSSHeader, getBackOfficeJavaScriptSet, getBodyAttributes, getContentForm, getCSSHeaders, getCtxCategories, getCurrentCategory, getCustomHeaders, getDocType, getFinalCSSFooterMap, getFinalCSSMap, getFinalJavaScriptModuleSet, getFinalJavaScriptSet, getFrontOfficeCSSHeader, getFrontOfficeJavaScriptSet, getHandlebarTemplates, getHttpEquivHeaders, getHttpNameHeaders, getJavaScriptCodeSet, getJavaScriptModuleSet, getJavaScriptSet, getPageContext, getPageTitle, getPageZone, getPortal, getPortalCategory, getPortlet, getPublication, getStyleHeaders, getSvgSprites, getSvgSpritesHtml, getTemplateUsage, internalSetupEmptyHeader, isEditIcon, isEditIcon, isEditIconForPublish, isEditIconForPublish, isPrintView, registerDisplayContext, removeAjaxRequestAttribute, setAjaxRequestAttribute, setAjaxRequestId, setAllHeadersDiffMap, setDocType, setEditIcon, setPageContext, setPageTitle, setPageZone, setShowEditIcon, setTemplateUsage, showEditIcon, showEditIcon, showEditIconMethods inherited from class com.jalios.jcms.context.JcmsContext
addMsg, addMsg, addMsgSession, addMsgSession, addToastr, addToastr, addToastrSession, addToastrSession, applySelector, canAccessAdminArea, copyMsgListToMsgSessionList, forceWorkspaceUpdate, getBaseUrl, getBrowser, getCaddy, getContextPath, getErrorMsg, getErrorMsgList, getErrorMsgSession, getErrorMsgSessionList, getInfoMsg, getInfoMsgList, getInfoMsgSession, getInfoMsgSessionList, getLoggedMember, getMsgList, getMsgSessionList, getRequest, getResponse, getSession, getSuccessMsg, getSuccessMsgList, getSuccessMsgSession, getSuccessMsgSessionList, getToastrCollection, getToastrSessionCollection, getUploadedFiles, getUploadedFiles, getUrlWithCommonUpdatedParams, getUserCountry, getUserLang, getUserLocale, getUserZoneId, getWarningMsg, getWarningMsgList, getWarningMsgSession, getWarningMsgSessionList, glp, isAdmin, isAdminZone, isAjaxRequest, isDBMember, isDebug, isDebugTemplate, isInFrontOffice, isLogged, isWorkZone, removeMessage, removeMessage, removeMsg, select, sendError, sendError, sendForbidden, sendForbidden, sendRedirect, sendRedirect, sendRedirect, setErrorMsg, setErrorMsg, setErrorMsgSession, setErrorMsgSession, setInfoMsg, setInfoMsg, setInfoMsgSession, setInfoMsgSession, setLoggedMember, setRequest, setResponse, setSuccessMsg, setSuccessMsg, setSuccessMsgSession, setSuccessMsgSession, setWarningMsg, setWarningMsg, setWarningMsgSession, setWarningMsgSession, updateWorkspace, validateRegexp, validateSchedule
-
Field Details
-
redirect
-
noRedirect
protected boolean noRedirect -
noSendRedirect
protected boolean noSendRedirect -
redirectOnClosePopup
protected boolean redirectOnClosePopup -
workspaceForced
protected boolean workspaceForced -
popupEdition
protected boolean popupEdition -
editFieldSet
-
contextMap
-
formStep
protected int formStep -
op
protected boolean op -
opPrevious
protected boolean opPrevious -
opNext
protected boolean opNext -
opFinish
protected boolean opFinish -
openTabId
-
csrfValidationEnabled
protected boolean csrfValidationEnabledBoolean indicating if CSRF validation should be performed (true, which is the default), or not (false).You can disable CSRF validation in your handler by setting this value to false in your own
init()implementation. Warning : changing this behavior IS NOT RECOMMENDED. Use wisely. You can invokevalidateCSRF()manually at another time.- Since:
- jcms-10.0.6 / JCMS-9049 / SEC-199
-
-
Constructor Details
-
JcmsFormHandler
public JcmsFormHandler()
-
-
Method Details
-
init
protected void init()Method to implement if you need to initialize your handler from parameter received, prior to all security validation.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.
-
validate
Method invoked by JSP to validate all conditions (authorization, parameters, ...), and eventualy trigger the action that was requested to the handler.Override
processAction()if you need to provide custom actions.- Returns:
- true if a redirect was done, false otherwise
- Throws:
IOException- if error occured during validate- Since:
- jcms-7.1 in JcmsFormHandler (was in EditDataHandler), final since JCMS-6004
-
validateCSRF
protected boolean validateCSRF()- Returns:
- false if CSRF is enabled and
JcmsJspContext.checkCSRF()failed, true otherwise. - Since:
- jcms-10.0.6
-
mustSendForbiddenOnCSRF
protected boolean mustSendForbiddenOnCSRF()Check behavior to apply on CSRF error.Default behavior is to send forbidden redirect, this method allows the redirection to be skipped and form to be displayed.
Override with extreme precaution, if you want to display form on CSRF error, make sure user is authorized to access data manipulated.
- Returns:
- true to send forbidden (default), false to display form with current user data. In both case processAction is not invoked.
- Since:
- jcms-10.0.7 / SEC-208
-
afterValidation
- Throws:
IOException
-
processAction
Method to be implemented to check/validate action to be performed and process them.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.
- Returns:
- false if no redirection is needed, true otherwise
- Throws:
IOException- IO Exception
-
getAvailableMainLanguage
-
showCancelButton
public boolean showCancelButton()Check if the "Cancel" button should be displayed in step modal form.The default implementation of this method is to always return true.
You can provide a custom FormHandler to override this behavior.
See jcore/doStepButtons.jspf for use of this method.
- Returns:
- true to display the "Cancel" button, false to hide it
- Since:
- jcms-7.1.2 jcms-7.2 as requested by issue JCMS-3057
-
showNextButton
public boolean showNextButton()Check if the "Next" button should be displayed in step modal form.The default implementation of this method is to return true unless the finish button is being displayed by method
showFinishButton().You can provide a custom FormHandler to override this behavior.
See jcore/doStepButtons.jspf for use of this method.
- Returns:
- true to display the "Next" button, false to hide it
-
showPreviousButton
public boolean showPreviousButton()Check if the "Previous" button should be displayed in step modal form.The default implementation of this method is to return true if the current step (as returned by
getFormStep()is higher than 0.You can provide a custom FormHandler to override this behavior.
See jcore/doStepButtons.jspf for use of this method.
- Returns:
- true to display the "Previous" button, false to hide it
-
showFinishButton
public boolean showFinishButton()Check if the "Finish" button should be displayed in step modal form.The default implementation of this method is to return true if the current step (as returned by
getFormStep()is the last one (as compared withgetFormStepCount().You can provide a custom FormHandler to override this behavior.
See jcore/doStepButtons.jspf for use of this method.
- Returns:
- true to display the "Finish" button, false to hide it
-
getFormStepCount
public int getFormStepCount()Retrieve the total number of steps used for edition when invoking this form handler.The default implementation of this method is to return 1, corresponding to one step (which means only 1 screen being displayed).
You can provide a custom FormHandler to override this behavior.
See jcore/doSteps.jspf for use of this method.
- Returns:
- the total number of steps in this formhandler
-
isFormStepClickable
public boolean isFormStepClickable()Returns true if the form step are clickable.- Returns:
- true if the form step are clickable.
- Since:
- jcms-10.0.5
-
getFormStepPrefixProp
- Returns:
- the prefix prop for the steps
- Since:
- jcms-9.0.0
-
getFormStepFinishLabel
- Returns:
- the label of the Finish button
- Since:
- jcms-9.0.0
-
getFormStepLabels
Returns the label array for the steps.- Parameters:
userLang- the language- Returns:
- the label array for the steps.
- Since:
- jcms-9.0.0
-
getFormStepHiddenFields
-
getFormStep
public int getFormStep()Retrieve the current step of edition when invoking this form handler.See jcore/doSteps.jspf for use of this method.
- Returns:
- the current steps in this formhandler (starting at 0 and ending at
)getFormStepCount()- 1
-
setFormStep
public void setFormStep(int step) Set the current step of edition when invoking this form handler.- Parameters:
step- the current step (0 being the first one andbeing the last one)getFormStepCount()- 1
-
getOpenTabId
Return the id of the tab to open- Returns:
- the open tab id if not null
- Since:
- 11.0.0 / JCMS-11630
-
setOpenTabId
Set id of the opened tab- Parameters:
openTabId- the DOM id of tab to open, value MUST only contains alphanumeric.- Since:
- 11.0.0 / JCMS-11333 / use of new tabs in publication edit form
-
validatePrevious
- Throws:
IOException
-
performPrevious
- Throws:
IOException
-
validateNext
- Throws:
IOException
-
performNext
- Throws:
IOException
-
validateFinish
- Throws:
IOException
-
performFinish
- Throws:
IOException
-
getWorkspace
Description copied from class:JcmsContextRetrieve the current Workspace variable for this context either from request if inFO or from session if in back office. Fast: this method is cached using initDone (it is recomputed only on forceUpdate() or setRequest()).- Overrides:
getWorkspacein classJcmsContext- Returns:
- the workspace (the one set by doInitPage.jsp)
-
isWorkspaceForced
public boolean isWorkspaceForced() -
setWorkspace
-
setWs
-
sendRedirect
Set the redirect in the response. If noRedirect has been set, this method set no redirection. If noSendRedirect has been set, put the request attribute "redirect" but do not call response.sendRedirect(). This may be useful when redirecting from a dynamically included JSP in the front-office (some AppServer throw an exception when setting/getting request attribute once the redirect has been put.)- Parameters:
url- the url to redirect to.checkRedirect- if true and if redirect attribute has been set, redirect on this url- Throws:
IOException- IO Exception- Since:
- jcms-4.0
-
getClosePopupUrl
-
sendRedirect
Redirect current request to given URL.
OverridesJcmsContext.sendRedirect(String)to use behavior provided bysendRedirect(String, boolean).- Overrides:
sendRedirectin classJcmsContext- Parameters:
url- the url to redirect to.- Throws:
IOException- if an error occured while writing in response headers- Since:
- jcms-4.0
- See Also:
-
getRedirect
Get the value of redirect.- Returns:
- Value of redirect.
-
setRedirect
Set the value of redirect.- Parameters:
url- Value to assign to redirect.
-
getModalRedirect
Get the redirect value to be used in the modals with modalRedirect.jspf and the request attribute 'modal.redirect'.- Returns:
- redirect value
- Since:
- jcms-9.0.4
-
setNoRedirect
public void setNoRedirect(boolean noRedirect) Set the value of noRedirect.- Parameters:
noRedirect- Value to assign to noRedirect.- Since:
- jcms-4.0
-
setNoSendRedirect
public void setNoSendRedirect(boolean noSendRedirect) Set the value of noSendRedirect.- Parameters:
noSendRedirect- Value to assign to noSendRedirect.- Since:
- jcms-4.0
-
setRedirectOnClosePopup
public final void setRedirectOnClosePopup(boolean redirectOnClosePopup) Set whether the redirect value should be applied to the opener when closing the popup edition.
The value set by this method will be used only when using popup edition (setPopupEdition(boolean)).- Parameters:
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.- Since:
- jcms-5.7
-
getRedirectOnClosePopup
public final boolean getRedirectOnClosePopup()Return the value indicating whether the redirect value should be applied to the opener when closing the popup edition.- Returns:
- true, when redirect value (
setRedirect(String)) will be provided to closePopup.jsp to redirect the opener. false, if the popup will simply be closed and the opener refreshed. - Since:
- jcms-5.7
-
processStatus
Process the ControllerStatus: do nothing if OK, or send on forbidden, or put a warning message in the request.- Parameters:
status- the ControllerStatus to be processed- Returns:
- true when status is OK, false if status was a failure (forbidden or anything else)
- Throws:
IOException- if an error occurs- Since:
- jcms-5.0.0
-
getControllerContext
Build a controller context. I.E. add request, response and loggedMember.- Returns:
- the HashMap which contains the context
- Since:
- jcms-5.0.0
-
isFieldMissing
Check if the given parameter is present in the query parameters- Parameters:
field- the field to be checked- Returns:
- true if this field is present in the query parameters
- Since:
- jcms-5.0.0
-
setPopupEdition
public void setPopupEdition(boolean v) Set where this form handler is being invoked in a popup.- Parameters:
v- true if handler is invoked in popup, false otherwise- Since:
- jcms-5.0.0
-
isPopupEdition
public boolean isPopupEdition()- Returns:
- true if this form handler is invoked through a popup
- Since:
- jcms-5.0.0
-
setEditField
- Parameters:
v- a set of field names to edit- Since:
- jcms-5.0.0
-
getEditFieldSet
- Returns:
- a set of field names being edited
- Since:
- jcms-5.0.0
-
isFieldEdition
- Parameters:
field- field name- Returns:
- true if this handler is invoked to edit only some fields of the data
- Since:
- jcms-5.0.0
- See Also:
-
isPartialFieldEdition
public boolean isPartialFieldEdition()Returns true if this is a partial field edition (i.e. front edition)- Returns:
- true if this is a partial field edition.
- Since:
- jcms-5.5.0
-
updateUploadedFields
Perform upload then, replace all values with value MultipartRequest.MULTIPART_UPLOAD with the real File realtive path.- Parameters:
fieldName- the field namevalues- the field fake valuesoptions- upload options- Since:
- jcms-10.0.6 / JCMS-8317
-
getMainLangValue
Returns the first value (i.e. the main language value) from the given array (monovalued ML fields).- Parameters:
array- the arraytrim- if true trim the valueescape- if true escape the value- Returns:
- the first value from the array.
- Since:
- jcms-6.0.0
-
getMLMap
Returns the ML map (i.e. the additionnal languages) filled with the values contained in the given array (monovalued ML fields).- Parameters:
array- the arraytrim- if true trim the valuesescape- if true escape the values- Returns:
- the ML map filled with the values contained in the given array.
- Since:
- jcms-6.0.0
-
getMainLangValueArray
Deprecated.Returns the first values (i.e. the main language value) from the given array (multivalued ML fields).- Parameters:
array- the arraytrim- if true trim the valuesescape- if true escape the values- Returns:
- the first values from the array (i.e. the main language value) from the given array.
- Since:
- jcms-6.0.0
-
getMLMapArray
Deprecated.Returns the ML map (i.e. the additionnal languages) filled with the values contained in the given array (multivalued ML fields).- Parameters:
array- the arraytrim- if true trim the valuesescape- if true escape the values- Returns:
- the ML map filled with the values contained in the given array.
- Since:
- jcms-6.0.0
-
sanitize
Sanitize the specified input strings for the usage of the specified field.Current implementation is as follow :
- content of wysiwyg fields is always cleaned through
- content of (legacy) wiki fields is either :
- cleaned using
WysiwygManager.cleanHtml(String, Map)if it contains HTML (as detected byJHTMLUtils.isJHTML(TypeFieldEntry, String) - escaped using
JcmsUtil.escapeHtml(String)othewise
- cleaned using
- content any other field are escaped using
JcmsUtil.escapeHtml(String)
- Parameters:
tfe- the TypeFieldEntry of the data field for which input is being read. Set to null when working with field of non generated type.unsafeInput- the unsafe input strings to be sanitized- Returns:
- an array of safe strings
- Since:
- jcms-10.0.0
-
sanitize
Sanitize the specified input string for the usage of the specified field.Current implementation is as follow :
- content of wysiwyg fields is always cleaned through
WysiwygManager.cleanHtml(String, Map) - content of (legacy) wiki fields and unknown field (null TypeFieldEntry) is either :
- cleaned using
WysiwygManager.cleanHtml(String, Map)if it contains HTML (as detected byJHTMLUtils.isJHTML(TypeFieldEntry, String) - escaped using
JcmsUtil.escapeHtml(String)othewise
- cleaned using
- content of other fields (with valid TypeFieldEntry) for which HTML has been authorized are left unmodified (not escaped and not cleaned)
- content any other field are escaped using
JcmsUtil.escapeHtml(String)
- Parameters:
tfe- the TypeFieldEntry of the data field for which input is being read. Set to null when working with field of non generated type.unsafeInput- the unsafe input string to be sanitized- Returns:
- a safe string
- Since:
- jcms-10.0.0
- content of wysiwyg fields is always cleaned through
-
getMonolingualValue
Return the first value from the given array, properly sanitized for usage in the specified field.This method must only be used for monolingual and monovalued field.
Example :
TypeFieldEntry myfieldTFE = channel.getTypeFieldEntry(MyType.class, "myfield", true); String myfield; public void setMyMonolingualAndMonovaluedField(String[] input) { myfield = getMonolingualValue(myfieldTFE, input); }- Parameters:
tfe- the TypeFieldEntry of the data field for which input is being read. Set to null when working with field of non generated type.array- the array- Returns:
- the first value from the array, properly sanitized. May return null if specified array was null.
- Since:
- jcms-10.0.0
- See Also:
-
getMonolingualValueArray
Return the values from the given array, properly sanitized for usage in the specified field.Traling empty or null values are removed from array.
This method must only be used for monolingual and monovalued field.
Example :
TypeFieldEntry myfieldTFE = channel.getTypeFieldEntry(MyType.class, "myfield", true); String[] myfield; public void setMyMonolingualAndMultivaluedField(String[] input) { myfield = getMonolingualValueArray(myfieldTFE, input); }- Parameters:
tfe- the TypeFieldEntry of the data field for which input is being read. Set to null when working with field of non generated type.array- the array- Returns:
- the values from the array, properly sanitized. May return null if specified array was null.
- Since:
- jcms-10.0.0
- See Also:
-
getMultilingualMainValue
Return the main value (ie: value of main site language) from the given array, properly sanitized for usage in the specified multilingual field.This method must only be used for multilingual and monovalued field.
It must be used along with
getMultilingualMLMap(TypeFieldEntry, String[]).Example :
TypeFieldEntry myfieldTFE = channel.getTypeFieldEntry(MyType.class, "myfield", true); String myfield; // main value Map<String,String> myfieldMLMap; // ISO-639 language code to value public void setMyMultilingualAndMonovaluedField(String[] input) { myfield = getMultilingualMainValue(myfieldTFE, input); myfieldMLMap = getMultilingualMLMap(myfieldTFE, input); }- Parameters:
tfe- the TypeFieldEntry of the data field for which input is being read. Set to null when working with field of non generated type.array- the string array input received from the end user- Returns:
- the first value from the array, properly sanitized. May return null if specified array was null.
- Since:
- jcms-10.0.0
- See Also:
-
getMultilingualMLMap
Return a language map (ISO-639 language code to value) of all values but the value corresponding main site language, extracted from the specified array, and properly sanitized for usage in the specified multilingual field.This method must only be used for multilingual and monovalued field.
See complete example in
getMultilingualMainValue(TypeFieldEntry, String[])- Parameters:
tfe- the TypeFieldEntry of the data field for which input is being read. Set to null when working with field of non generated type.array- the string array input received from the end user- Returns:
- a language map (ISO-639 language code to value).
- Since:
- jcms-10.0.0
- See Also:
-
getMultilingualMainValueArray
Return the main values (ie: values of main site language) from the given array, properly sanitized for usage in the specified multilingual field.This method must only be used for multilingual and multivalued field.
It must be used along with
getMultilingualMLMapArray(TypeFieldEntry, String[]).Example :
TypeFieldEntry myfieldTFE = channel.getTypeFieldEntry(MyType.class, "myfield", true); String[] myfield; // main values Map<String,String[]> myfieldMLMap; // ISO-639 language code to values public void setMyMultilingualAndMultivaluedField(String[] input) { myfield = getMultilingualMainValueArray(myfieldTFE, input); myfieldMLMap = getMultilingualMLMapArray(myfieldTFE, input); }- Parameters:
tfe- the TypeFieldEntry of the data field for which input is being read. Set to null when working with field of non generated type.array- the string array input received from the end user- Returns:
- the main values from the array, properly sanitized.
- Since:
- jcms-10.0.0
- See Also:
-
getMultilingualMLMapArray
protected static HashMap<String,String[]> getMultilingualMLMapArray(TypeFieldEntry tfe, String[] array) Return a language map (ISO-639 language code to values) of all values but the value corresponding main site language, extracted from the specified array, and properly sanitized for usage in the specified multilingual field.This method must only be used for multilingual and monovalued field.
See complete example in
getMultilingualMainValueArray(TypeFieldEntry, String[])- Parameters:
tfe- the TypeFieldEntry of the data field for which input is being read. Set to null when working with field of non generated type.array- the string array input received from the end user- Returns:
- a language map (ISO-639 language code to values).
- Since:
- jcms-10.0.0
- See Also:
-
mapStringArrayToMapStringList
protected static HashMap<String,List<String>> mapStringArrayToMapStringList(Map<String, String[]> map) Convert a map contaning Array of String, into to a map containg List of String.- Parameters:
map- to convert- Returns:
- the converted Map
- Since:
- jcms-10.0.0
-
mapStringListToMapStringArray
protected static HashMap<String,String[]> mapStringListToMapStringArray(Map<String, List<String>> map) Convert a map contaning List of String, into to a map containg Array of String.- Parameters:
map- to convert- Returns:
- the converted Map
- Since:
- jcms-10.0.0
-
getHiddenField
-
getHiddenFieldML
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
getHiddenField
-
checkMissingField
-
setOpPrevious
-
setOpNext
-
setOpFinish
-
canStartProcess
- Parameters:
process- the process to check if loggedMember can start it- Returns:
- true if loggedMember can starts this process
- Since:
- jcms-10.0.8 / JCMS-9179
-
startProcess
- Parameters:
process- the process to start- Returns:
- a CompletableFuture
- Since:
- jcms-10.0.8 / JCMS-9179
-
getBackgroundProcess
- Returns:
- the backgroundProcess in request attribute
- Since:
- jcms-10.0.8 / JCMS-9179
-
getMultilingualMainValueArray(TypeFieldEntry, String[])