List of usage examples for com.liferay.portal.kernel.servlet SessionMessages KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE
String KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE
To view the source code for com.liferay.portal.kernel.servlet SessionMessages KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE.
Click Source Link
From source file:com.fmdp.webform.portlet.WebFormPortlet.java
License:Open Source License
public void saveData(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); String portletId = PortalUtil.getPortletId(actionRequest); PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletId); boolean requireCaptcha = GetterUtil.getBoolean(preferences.getValue("requireCaptcha", StringPool.BLANK)); String successURL = GetterUtil.getString(preferences.getValue("successURL", StringPool.BLANK)); boolean sendAsEmail = GetterUtil.getBoolean(preferences.getValue("sendAsEmail", StringPool.BLANK)); boolean sendThanksEmail = GetterUtil.getBoolean(preferences.getValue("sendThanksEmail", StringPool.BLANK)); boolean saveToDatabase = GetterUtil.getBoolean(preferences.getValue("saveToDatabase", StringPool.BLANK)); String databaseTableName = GetterUtil .getString(preferences.getValue("databaseTableName", StringPool.BLANK)); boolean saveToFile = GetterUtil.getBoolean(preferences.getValue("saveToFile", StringPool.BLANK)); boolean uploadToDisk = GetterUtil.getBoolean(preferences.getValue("uploadToDisk", StringPool.BLANK)); boolean uploadToDM = GetterUtil.getBoolean(preferences.getValue("uploadToDM", StringPool.BLANK)); long newFolderId = GetterUtil.getLong(preferences.getValue("newFolderId", StringPool.BLANK)); String fileName = GetterUtil.getString(preferences.getValue("fileName", StringPool.BLANK)); String uploadDiskDir = GetterUtil.getString(preferences.getValue("uploadDiskDir", StringPool.BLANK)); if (requireCaptcha) { try {//from w w w. jav a2 s . c o m CaptchaUtil.check(actionRequest); } catch (CaptchaTextException cte) { SessionErrors.add(actionRequest, CaptchaTextException.class.getName()); return; } } UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest); Map<String, String> fieldsMap = new LinkedHashMap<String, String>(); String fileAttachment = ""; for (int i = 1; true; i++) { String fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK); String fieldType = preferences.getValue("fieldType" + i, StringPool.BLANK); if (Validator.isNull(fieldLabel)) { break; } if (StringUtil.equalsIgnoreCase(fieldType, "paragraph")) { continue; } if (StringUtil.equalsIgnoreCase(fieldType, "file")) { if (_log.isDebugEnabled()) { _log.debug("Field name for file: " + fieldLabel); } File file = uploadRequest.getFile("field" + i); String sourceFileName = uploadRequest.getFileName("field" + i); if (_log.isDebugEnabled()) { _log.debug("File attachment: " + sourceFileName); } JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); if (Validator.isNotNull(sourceFileName) && !"".equals(sourceFileName)) { if (uploadRequest.getSize("field" + i) == 0) { SessionErrors.add(actionRequest, "uploadToDiskError", "Uploaded file size is 0"); if (_log.isDebugEnabled()) { _log.debug("Uploaded file size is 0"); } return; } // List<String> uploadResults = new ArrayList<String>(); String uploadResult = ""; if (uploadToDisk) { uploadResult = uploadFile(file, sourceFileName, uploadDiskDir); if (uploadResult.equalsIgnoreCase("File Upload Error")) { SessionErrors.add(actionRequest, "uploadToDiskError", uploadResult); return; } fileAttachment = uploadDiskDir + File.separator + uploadResult; //uploadResults.add(uploadResult); jsonObject.put("fsOriginalName", sourceFileName); jsonObject.put("fsName", uploadResult); } if (uploadToDM) { uploadResult = ""; String contentType = MimeTypesUtil.getContentType(file); Folder folderName = DLAppLocalServiceUtil.getFolder(newFolderId); if (_log.isDebugEnabled()) { _log.debug("DM Folder: " + folderName.getName()); } InputStream inputStream = new FileInputStream(file); long repositoryId = folderName.getRepositoryId(); try { String selectedFileName = sourceFileName; while (true) { try { DLAppLocalServiceUtil.getFileEntry(themeDisplay.getScopeGroupId(), newFolderId, selectedFileName); StringBundler sb = new StringBundler(5); sb.append(FileUtil.stripExtension(selectedFileName)); sb.append(StringPool.DASH); sb.append(StringUtil.randomString()); sb.append(StringPool.PERIOD); sb.append(FileUtil.getExtension(selectedFileName)); selectedFileName = sb.toString(); } catch (Exception e) { break; } } FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(themeDisplay.getUserId(), repositoryId, newFolderId, selectedFileName, //file.getName(), contentType, selectedFileName, "", "", inputStream, file.length(), serviceContext); if (_log.isDebugEnabled()) { _log.debug("DM file uploade: " + fileEntry.getTitle()); } //Map<String, Serializable> workflowContext = new HashMap<String, Serializable>(); //workflowContext.put("event",DLSyncConstants.EVENT_UPDATE); //DLFileEntryLocalServiceUtil.updateStatus(themeDisplay.getUserId(), fileEntry.getFileVersion().getFileVersionId(), WorkflowConstants.STATUS_APPROVED, workflowContext, serviceContext); uploadResult = String.valueOf(fileEntry.getFileEntryId()); //uploadResults.add(uploadResult); String docUrl = themeDisplay.getPortalURL() + "/c/document_library/get_file?uuid=" + fileEntry.getUuid() + "&groupId=" + themeDisplay.getScopeGroupId(); jsonObject.put("fe", uploadResult); jsonObject.put("feOriginalName", sourceFileName); jsonObject.put("feName", fileEntry.getTitle()); jsonObject.put("feUrl", docUrl); } catch (PortalException pe) { SessionErrors.add(actionRequest, "uploadToDmError"); _log.error("The upload to DM failed", pe); return; } catch (Exception e) { _log.error("The upload to DM failed", e); return; } } jsonObject.put("Status", "With Attachment"); } else { jsonObject.put("Status", "No Attachment"); } fieldsMap.put(fieldLabel, jsonObject.toString()); } else { fieldsMap.put(fieldLabel, uploadRequest.getParameter("field" + i)); } } Set<String> validationErrors = null; try { validationErrors = validate(fieldsMap, preferences); } catch (Exception e) { SessionErrors.add(actionRequest, "validationScriptError", e.getMessage().trim()); return; } User currentUser = PortalUtil.getUser(actionRequest); String userEmail = ""; if (!Validator.isNull(currentUser)) { userEmail = currentUser.getEmailAddress(); if (_log.isDebugEnabled()) { _log.debug("User email for the form author: " + userEmail); } fieldsMap.put("email-from", userEmail); } else { fieldsMap.put("email-from", "guest"); } DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone(themeDisplay.getTimeZone().getID())); Date dateobj = new Date(); fieldsMap.put("email-sent-on", df.format(dateobj)); if (validationErrors.isEmpty()) { boolean emailSuccess = true; boolean databaseSuccess = true; boolean fileSuccess = true; boolean emailThanksSuccess = true; if (sendAsEmail) { emailSuccess = WebFormUtil.sendEmail(themeDisplay.getCompanyId(), fieldsMap, preferences, fileAttachment); } if (sendThanksEmail && !Validator.isNull(currentUser)) { emailThanksSuccess = WebFormUtil.sendThanksEmail(themeDisplay.getCompanyId(), fieldsMap, preferences, userEmail); } if (saveToDatabase) { if (Validator.isNull(databaseTableName)) { databaseTableName = WebFormUtil.getNewDatabaseTableName(portletId); preferences.setValue("databaseTableName", databaseTableName); preferences.store(); } databaseSuccess = saveDatabase(themeDisplay.getCompanyId(), fieldsMap, preferences, databaseTableName); } if (saveToFile) { fileSuccess = saveFile(fieldsMap, fileName); } if (emailSuccess && emailThanksSuccess && databaseSuccess && fileSuccess) { if (Validator.isNull(successURL)) { SessionMessages.add(actionRequest, "success"); } else { SessionMessages.add(actionRequest, portletId + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE); } } else { SessionErrors.add(actionRequest, "error"); } } else { for (String badField : validationErrors) { SessionErrors.add(actionRequest, "error" + badField); } } if (SessionErrors.isEmpty(actionRequest) && Validator.isNotNull(successURL)) { actionResponse.sendRedirect(successURL); } }
From source file:com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand.java
License:Open Source License
protected void deleteEntries(ActionRequest actionRequest, boolean moveToTrash) throws Exception { long[] deleteEntryIds = null; long entryId = ParamUtil.getLong(actionRequest, "entryId"); if (entryId > 0) { deleteEntryIds = new long[] { entryId }; } else {//from w ww. j a v a2 s . c o m deleteEntryIds = StringUtil.split(ParamUtil.getString(actionRequest, "deleteEntryIds"), 0L); } List<TrashedModel> trashedModels = new ArrayList<>(); for (long deleteEntryId : deleteEntryIds) { if (moveToTrash) { BlogsEntry entry = _blogsEntryService.moveEntryToTrash(deleteEntryId); trashedModels.add(entry); } else { _blogsEntryService.deleteEntry(deleteEntryId); } } if (moveToTrash && !trashedModels.isEmpty()) { TrashUtil.addTrashSessionMessages(actionRequest, trashedModels); SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE); } }
From source file:com.liferay.dynamic.data.lists.form.web.internal.portlet.action.AddRecordMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { long groupId = ParamUtil.getLong(actionRequest, "groupId"); long recordSetId = ParamUtil.getLong(actionRequest, "recordSetId"); DDLRecordSet recordSet = _ddlRecordSetService.getRecordSet(recordSetId); validateCaptcha(actionRequest, recordSet); DDMForm ddmForm = getDDMForm(recordSet); DDMFormValues ddmFormValues = _ddmFormValuesFactory.create(actionRequest, ddmForm); ServiceContext serviceContext = ServiceContextFactory.getInstance(DDLRecord.class.getName(), actionRequest); DDLRecord ddlRecord = _ddlRecordService.addRecord(groupId, recordSetId, DDLRecordConstants.DISPLAY_INDEX_DEFAULT, ddmFormValues, serviceContext); if (isEmailNotificationEnabled(recordSet)) { _ddlFormEmailNotificationSender.sendEmailNotification(actionRequest, ddlRecord); }/* www. ja va2 s .c o m*/ DDLRecordSetSettings recordSetSettings = recordSet.getSettingsModel(); String redirectURL = recordSetSettings.redirectURL(); if (SessionErrors.isEmpty(actionRequest) && Validator.isNotNull(redirectURL)) { String portletId = _portal.getPortletId(actionRequest); SessionMessages.add(actionRequest, portletId, SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE); actionResponse.sendRedirect(redirectURL); } }
From source file:com.liferay.dynamic.data.mapping.form.web.internal.portlet.action.AddFormInstanceRecordMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { PortletSession portletSession = actionRequest.getPortletSession(); long groupId = ParamUtil.getLong(actionRequest, "groupId"); if (groupId == 0) { groupId = GetterUtil.getLong(portletSession.getAttribute(DDMFormWebKeys.GROUP_ID)); }/* w ww . java 2 s . c om*/ long formInstanceId = ParamUtil.getLong(actionRequest, "formInstanceId"); if (formInstanceId == 0) { formInstanceId = GetterUtil .getLong(portletSession.getAttribute(DDMFormWebKeys.DYNAMIC_DATA_MAPPING_FORM_INSTANCE_ID)); } DDMFormInstance ddmFormInstance = _ddmFormInstanceService.getFormInstance(formInstanceId); validateCaptcha(actionRequest, ddmFormInstance); DDMForm ddmForm = getDDMForm(ddmFormInstance); DDMFormValues ddmFormValues = _ddmFormValuesFactory.create(actionRequest, ddmForm); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); _addFormInstanceMVCCommandHelper.updateRequiredFieldsAccordingToVisibility(actionRequest, ddmForm, ddmFormValues, themeDisplay.getLocale()); ServiceContext serviceContext = ServiceContextFactory.getInstance(DDMFormInstanceRecord.class.getName(), actionRequest); DDMFormInstanceRecordVersion ddmFormInstanceRecordVersion = _ddmFormInstanceRecordVersionLocalService .fetchLatestFormInstanceRecordVersion(themeDisplay.getUserId(), formInstanceId, ddmFormInstance.getVersion(), WorkflowConstants.STATUS_DRAFT); DDMFormInstanceRecord ddmFormInstanceRecord; if (ddmFormInstanceRecordVersion == null) { ddmFormInstanceRecord = _ddmFormInstanceRecordService.addFormInstanceRecord(groupId, formInstanceId, ddmFormValues, serviceContext); } else { ddmFormInstanceRecord = _ddmFormInstanceRecordService.updateFormInstanceRecord( ddmFormInstanceRecordVersion.getFormInstanceRecordId(), false, ddmFormValues, serviceContext); } if (isEmailNotificationEnabled(ddmFormInstance)) { _ddmFormEmailNotificationSender.sendEmailNotification(actionRequest, ddmFormInstanceRecord); } if (SessionErrors.isEmpty(actionRequest)) { DDMFormInstanceSettings formInstanceSettings = ddmFormInstance.getSettingsModel(); String redirectURL = formInstanceSettings.redirectURL(); if (Validator.isNotNull(redirectURL)) { portletSession.setAttribute(DDMFormWebKeys.DYNAMIC_DATA_MAPPING_FORM_INSTANCE_ID, formInstanceId); portletSession.setAttribute(DDMFormWebKeys.GROUP_ID, groupId); sendRedirect(actionRequest, actionResponse, redirectURL); } else { DDMFormSuccessPageSettings ddmFormSuccessPageSettings = ddmForm.getDDMFormSuccessPageSettings(); if (ddmFormSuccessPageSettings.isEnabled()) { String portletId = _portal.getPortletId(actionRequest); SessionMessages.add(actionRequest, portletId.concat(SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE)); } } } }
From source file:com.liferay.dynamic.data.mapping.web.internal.portlet.action.RefreshTemplateMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { SessionMessages.add(actionRequest,/* w ww . ja va 2s .com*/ _portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE); }
From source file:com.liferay.exportimport.web.internal.portlet.action.PublishPortletMVCRenderCommand.java
License:Open Source License
@Override public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException { Portlet portlet = null;//from w w w . jav a 2 s . c o m try { portlet = ActionUtil.getPortlet(renderRequest); } catch (PrincipalException pe) { SessionErrors.add(renderRequest, pe.getClass()); return "/error.jsp"; } catch (Exception e) { throw new PortletException(e); } try { renderResponse.setTitle(ActionUtil.getTitle(portlet, renderRequest)); renderRequest = ActionUtil.getWrappedRenderRequest(renderRequest, null); String portletId = _portal.getPortletId(renderRequest); SessionMessages.add(renderRequest, portletId + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE); return "/publish_portlet.jsp"; } catch (Exception e) { SessionErrors.add(renderRequest, e.getClass()); return "/error.jsp"; } }
From source file:com.liferay.extension.mvc.MVCPortletExtended.java
License:Open Source License
protected void hideDefaultSuccessMessage(PortletRequest portletRequest) { SessionMessages.add(portletRequest,/*from w w w. j av a2 s . c o m*/ PortalUtil.getPortletId(portletRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE); }
From source file:com.liferay.webform.portlet.WebFormPortlet.java
License:Open Source License
public void saveData(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); String portletId = PortalUtil.getPortletId(actionRequest); PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletId); boolean requireCaptcha = GetterUtil.getBoolean(preferences.getValue("requireCaptcha", StringPool.BLANK)); String successURL = GetterUtil.getString(preferences.getValue("successURL", StringPool.BLANK)); boolean sendAsEmail = GetterUtil.getBoolean(preferences.getValue("sendAsEmail", StringPool.BLANK)); boolean saveToDatabase = GetterUtil.getBoolean(preferences.getValue("saveToDatabase", StringPool.BLANK)); String databaseTableName = GetterUtil .getString(preferences.getValue("databaseTableName", StringPool.BLANK)); boolean saveToFile = GetterUtil.getBoolean(preferences.getValue("saveToFile", StringPool.BLANK)); String fileName = GetterUtil.getString(preferences.getValue("fileName", StringPool.BLANK)); if (requireCaptcha) { try {/*from w w w . j av a 2 s.c o m*/ CaptchaUtil.check(actionRequest); } catch (CaptchaTextException cte) { SessionErrors.add(actionRequest, CaptchaTextException.class.getName()); return; } } Map<String, String> fieldsMap = new LinkedHashMap<String, String>(); for (int i = 1; true; i++) { String fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK); String fieldType = preferences.getValue("fieldType" + i, StringPool.BLANK); if (Validator.isNull(fieldLabel)) { break; } if (StringUtil.equalsIgnoreCase(fieldType, "paragraph")) { continue; } fieldsMap.put(fieldLabel, actionRequest.getParameter("field" + i)); } Set<String> validationErrors = null; try { validationErrors = validate(fieldsMap, preferences); } catch (Exception e) { SessionErrors.add(actionRequest, "validationScriptError", e.getMessage().trim()); return; } if (validationErrors.isEmpty()) { boolean emailSuccess = true; boolean databaseSuccess = true; boolean fileSuccess = true; if (sendAsEmail) { emailSuccess = sendEmail(themeDisplay.getCompanyId(), fieldsMap, preferences); } if (saveToDatabase) { if (Validator.isNull(databaseTableName)) { databaseTableName = WebFormUtil.getNewDatabaseTableName(portletId); preferences.setValue("databaseTableName", databaseTableName); preferences.store(); } databaseSuccess = saveDatabase(themeDisplay.getCompanyId(), fieldsMap, preferences, databaseTableName); } if (saveToFile) { fileSuccess = saveFile(fieldsMap, fileName); } if (emailSuccess && databaseSuccess && fileSuccess) { if (Validator.isNull(successURL)) { SessionMessages.add(actionRequest, "success"); } else { SessionMessages.add(actionRequest, portletId + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE); } } else { SessionErrors.add(actionRequest, "error"); } } else { for (String badField : validationErrors) { SessionErrors.add(actionRequest, "error" + badField); } } if (SessionErrors.isEmpty(actionRequest) && Validator.isNotNull(successURL)) { actionResponse.sendRedirect(successURL); } }
From source file:com.platts.portlet.documentlibrary.DLSetSeoUrl.java
License:Open Source License
protected void hideDefaultSuccessMessage(PortletRequest portletRequest) { SessionMessages.add(portletRequest,//from ww w. j a v a 2 s.co m PortalUtil.getPortletId(portletRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE); }
From source file:com.rivetlogic.ecommerce.portlet.ShoppingCartPortlet.java
License:Open Source License
public void checkout(ActionRequest request, ActionResponse response) throws IOException { SessionMessages.add(request,//w w w .j a va 2s . co m PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE); SessionMessages.add(request, PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE); String redirect = ParamUtil.getString(request, WebKeys.REDIRECT); if (!validateCheckoutInfo(request)) { SessionErrors.add(request, ShoppingCartPortletConstants.MESSAGE_MISSING_REQUIRED_CHECKOUT_INFO); response.sendRedirect(redirect); } if (!(new ShoppingCartPrefsBean(request).isCartPrefsValidForCheckout())) { SessionErrors.add(request, ShoppingCartPortletConstants.ERROR_MESSAGE_CHECKOUT); logger.error(ERROR_CHECKOUT_MISSING_PORTLET_CONFIG); response.sendRedirect(redirect); } try { doCheckout(request, response); } catch (Exception e) { SessionErrors.add(request, ShoppingCartPortletConstants.ERROR_MESSAGE_CHECKOUT); logger.error(e.getMessage()); } response.sendRedirect(redirect); }