下面列出了javax.validation.executable.ExecutableType#NONE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@CsrfProtected
@ServeResourceMethod(portletNames = { "portlet1" }, resourceID = "deleteFile")
@ValidateOnExecution(type = ExecutableType.NONE)
public void deleteFile(ResourceRequest resourceRequest, ResourceResponse resourceResponse) {
PortletSession portletSession = resourceRequest.getPortletSession();
List<Attachment> attachments = attachmentManager.getAttachments(portletSession.getId());
ResourceParameters resourceParameters = resourceRequest.getResourceParameters();
String attachmentIndex = resourceParameters.getValue(resourceResponse.getNamespace() + "attachmentIndex");
if (attachmentIndex != null) {
Attachment attachment = attachments.remove(Integer.valueOf(attachmentIndex).intValue());
try {
File file = attachment.getFile();
file.delete();
_writeTabularJSON(resourceResponse.getWriter(), attachments);
}
catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
@CsrfProtected
@ServeResourceMethod(portletNames = { "portlet1" }, resourceID = "deleteFile")
@ValidateOnExecution(type = ExecutableType.NONE)
public void deleteFile(ResourceRequest resourceRequest, ResourceResponse resourceResponse) {
PortletSession portletSession = resourceRequest.getPortletSession();
List<Attachment> attachments = attachmentManager.getAttachments(portletSession.getId());
ResourceParameters resourceParameters = resourceRequest.getResourceParameters();
String attachmentIndex = resourceParameters.getValue(resourceResponse.getNamespace() + "attachmentIndex");
if (attachmentIndex != null) {
Attachment attachment = attachments.remove(Integer.valueOf(attachmentIndex).intValue());
try {
File file = attachment.getFile();
file.delete();
_writeTabularJSON(resourceResponse.getWriter(), attachments);
}
catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
@Override
public void handleMessage(Message message) {
final Object theServiceObject = getServiceObject(message);
if (theServiceObject == null) {
return;
}
final Method method = getServiceMethod(message);
if (method == null) {
return;
}
ValidateOnExecution validateOnExec = method.getAnnotation(ValidateOnExecution.class);
if (validateOnExec != null) {
ExecutableType[] execTypes = validateOnExec.type();
if (execTypes.length == 1 && execTypes[0] == ExecutableType.NONE) {
return;
}
}
final List< Object > arguments = MessageContentsList.getContentsList(message);
handleValidation(message, theServiceObject, method, arguments);
}
@POST
@Path("add")
@ValidateOnExecution(type = ExecutableType.NONE)
public String add(@Valid @BeanParam Person person) {
if (bindingResult.isFailed()) {
this.getErros();
this.models.put("countries", getCountries());
this.models.put("person", person);
return "insert.jsp";
}
repository.save(person);
message.setMessageRedirect("The " + person.getName() + " was successfully registered ! ");
return "redirect:mvc/show";
}
@POST
@Path("update")
@ValidateOnExecution(type = ExecutableType.NONE)
public String update(@Valid @BeanParam Person person) {
if (bindingResult.isFailed()) {
this.getErros();
this.models.put("countries", getCountries());
this.models.put("person", person);
return "change.jsp";
}
repository.save(person);
message.setMessageRedirect("The " + person.getName() + " was changed successfully ! ");
return "redirect:mvc/show";
}
@POST
@Path("add")
@ValidateOnExecution(type = ExecutableType.NONE)
public String add(@Valid @BeanParam Person person) {
if (bindingResult.isFailed()) {
this.getErros();
this.models.put("countries", getCountries());
this.models.put("person", person);
return "insert.jsp";
}
repository.save(person);
message.setMessageRedirect("The " + person.getName() + " was successfully registered ! ");
return "redirect:mvc/show";
}
@POST
@Path("update")
@ValidateOnExecution(type = ExecutableType.NONE)
public String update(@Valid @BeanParam Person person) {
if (bindingResult.isFailed()) {
this.getErros();
this.models.put("countries", getCountries());
this.models.put("person", person);
return "change.jsp";
}
repository.save(person);
message.setMessageRedirect("The " + person.getName() + " was changed successfully ! ");
return "redirect:mvc/show";
}
@POST
@CsrfProtected
@ValidateOnExecution(type = ExecutableType.NONE)
public Response save(@Valid @BeanParam TaskForm form) {
log.log(Level.INFO, "saving new task @{0}", form);
if (validationResult.isFailed()) {
AlertMessage alert = AlertMessage.danger("Validation voilations!");
validationResult.getAllErrors()
.stream()
.forEach((ParamError t) -> {
alert.addError(t.getParamName(), "", t.getMessage());
});
models.put("errors", alert);
return Response.status(BAD_REQUEST).entity("add.jspx").build();
}
Task task = new Task();
task.setName(form.getName());
task.setDescription(form.getDescription());
task.setDueDate(form.getDueDate());
taskRepository.save(task);
flashMessage.notify(Type.success, "Task was created successfully!");
//models.put("flashMessage", flashMessage);
return Response.ok("redirect:tasks").build();
}
@POST
//@CsrfValid
@ValidateOnExecution(type = ExecutableType.NONE)
public Response save(@Valid @BeanParam TaskForm form) {
log.log(Level.INFO, "saving new task @{0}", form);
if (validationResult.isFailed()) {
AlertMessage alert = AlertMessage.danger("Validation voilations!");
validationResult.getAllErrors()
.stream()
.forEach((ParamError t) -> {
alert.addError(t.getParamName(), "", t.getMessage());
});
models.put("errors", alert);
return Response.status(BAD_REQUEST).entity("add.xhtml").build();
}
Task task = new Task();
task.setName(form.getName());
task.setDescription(form.getDescription());
taskRepository.save(task);
flashMessage.notify(Type.success, "Task was created successfully!");
//models.put("flashMessage", flashMessage);
return Response.ok("redirect:tasks").build();
}
@RenderMethod(portletNames = { "portlet1" }, portletMode = "edit")
@ValidateOnExecution(type = ExecutableType.NONE)
@View("preferences.html")
public void prepareView(RenderRequest renderRequest, RenderResponse renderResponse) {
Map<String, Object> modelsMap = models.asMap();
if (!modelsMap.containsKey("preferences")) {
models.put("preferences", new Preferences(portletPreferences.getValue("datePattern", null)));
}
// Thymeleaf
models.put("mainFormActionURL", renderResponse.createActionURL());
}
@ActionMethod(portletName = "portlet1", actionName = "reset")
@ValidateOnExecution(type = ExecutableType.NONE)
@CsrfProtected
public void resetPreferences(ActionRequest actionRequest, ActionResponse actionResponse) {
ResourceBundle resourceBundle = portletConfig.getResourceBundle(actionRequest.getLocale());
try {
Enumeration<String> preferenceNames = portletPreferences.getNames();
while (preferenceNames.hasMoreElements()) {
String preferenceName = preferenceNames.nextElement();
if (!portletPreferences.isReadOnly(preferenceName)) {
portletPreferences.reset(preferenceName);
}
}
portletPreferences.store();
actionResponse.setPortletMode(PortletMode.VIEW);
actionResponse.setWindowState(WindowState.NORMAL);
models.put("globalInfoMessage", resourceBundle.getString("your-request-processed-successfully"));
}
catch (Exception e) {
models.put("globalErrorMessage", resourceBundle.getString("an-unexpected-error-occurred"));
logger.error(e.getMessage(), e);
}
}
@CsrfProtected
@ServeResourceMethod(portletNames = { "portlet1" }, resourceID = "uploadFiles")
@ValidateOnExecution(type = ExecutableType.NONE)
public void uploadFiles(ResourceRequest resourceRequest, ResourceResponse resourceResponse) {
PortletSession portletSession = resourceRequest.getPortletSession(true);
List<Attachment> attachments = attachmentManager.getAttachments(portletSession.getId());
try {
Collection<Part> transientMultipartFiles = resourceRequest.getParts();
if (!transientMultipartFiles.isEmpty()) {
File attachmentDir = attachmentManager.getAttachmentDir(portletSession.getId());
if (!attachmentDir.exists()) {
attachmentDir.mkdir();
}
for (Part transientMultipartFile : transientMultipartFiles) {
String submittedFileName = transientMultipartFile.getSubmittedFileName();
if (submittedFileName != null) {
File copiedFile = new File(attachmentDir, submittedFileName);
transientMultipartFile.write(copiedFile.getAbsolutePath());
attachments.add(new Attachment(copiedFile));
}
}
_writeTabularJSON(resourceResponse.getWriter(), attachments);
}
}
catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
@RenderMethod(portletNames = { "portlet1" }, portletMode = "edit")
@ValidateOnExecution(type = ExecutableType.NONE)
@View("preferences.jspx")
public void prepareView() {
Map<String, Object> modelsMap = models.asMap();
if (!modelsMap.containsKey("preferences")) {
models.put("preferences", new Preferences(portletPreferences.getValue("datePattern", null)));
}
}
@RenderMethod(portletNames = { "portlet1" })
@ValidateOnExecution(type = ExecutableType.NONE)
public String prepareView(RenderRequest renderRequest, RenderResponse renderResponse) {
String viewName = viewEngineContext.getView();
if (viewName == null) {
viewName = "applicant.jspx";
Applicant applicant = (Applicant) models.get("applicant");
if (applicant == null) {
applicant = new Applicant();
models.put("applicant", applicant);
}
PortletSession portletSession = renderRequest.getPortletSession();
List<Attachment> attachments = attachmentManager.getAttachments(portletSession.getId());
applicant.setAttachments(attachments);
String datePattern = portletPreferences.getValue("datePattern", null);
models.put("jQueryDatePattern", _getJQueryDatePattern(datePattern));
models.put("provinces", provinceService.getAllProvinces());
CDI<Object> currentCDI = CDI.current();
BeanManager beanManager = currentCDI.getBeanManager();
Class<? extends BeanManager> beanManagerClass = beanManager.getClass();
Package beanManagerPackage = beanManagerClass.getPackage();
models.put("weldVersion", beanManagerPackage.getImplementationVersion());
}
return viewName;
}
@ActionMethod(portletName = "portlet1", actionName = "reset")
@ValidateOnExecution(type = ExecutableType.NONE)
@CsrfProtected
public void resetPreferences(ActionRequest actionRequest, ActionResponse actionResponse) {
ResourceBundle resourceBundle = portletConfig.getResourceBundle(actionRequest.getLocale());
try {
Enumeration<String> preferenceNames = portletPreferences.getNames();
while (preferenceNames.hasMoreElements()) {
String preferenceName = preferenceNames.nextElement();
if (!portletPreferences.isReadOnly(preferenceName)) {
portletPreferences.reset(preferenceName);
}
}
portletPreferences.store();
actionResponse.setPortletMode(PortletMode.VIEW);
actionResponse.setWindowState(WindowState.NORMAL);
models.put("globalInfoMessage", resourceBundle.getString("your-request-processed-successfully"));
}
catch (Exception e) {
models.put("globalErrorMessage", resourceBundle.getString("an-unexpected-error-occurred"));
logger.error(e.getMessage(), e);
}
}
@CsrfProtected
@ServeResourceMethod(portletNames = { "portlet1" }, resourceID = "uploadFiles")
@ValidateOnExecution(type = ExecutableType.NONE)
public void uploadFiles(ResourceRequest resourceRequest, ResourceResponse resourceResponse) {
PortletSession portletSession = resourceRequest.getPortletSession(true);
List<Attachment> attachments = attachmentManager.getAttachments(portletSession.getId());
try {
Collection<Part> transientMultipartFiles = resourceRequest.getParts();
if (!transientMultipartFiles.isEmpty()) {
File attachmentDir = attachmentManager.getAttachmentDir(portletSession.getId());
if (!attachmentDir.exists()) {
attachmentDir.mkdir();
}
for (Part transientMultipartFile : transientMultipartFiles) {
String submittedFileName = transientMultipartFile.getSubmittedFileName();
if (submittedFileName != null) {
File copiedFile = new File(attachmentDir, submittedFileName);
transientMultipartFile.write(copiedFile.getAbsolutePath());
attachments.add(new Attachment(copiedFile));
}
}
_writeTabularJSON(resourceResponse.getWriter(), attachments);
}
}
catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
@RenderMethod(portletNames = { "portlet1" })
@ValidateOnExecution(type = ExecutableType.NONE)
public String prepareView(RenderRequest renderRequest, RenderResponse renderResponse) {
String viewName = viewEngineContext.getView();
if (viewName == null) {
viewName = "applicant.html";
Applicant applicant = (Applicant) models.get("applicant");
if (applicant == null) {
applicant = new Applicant();
models.put("applicant", applicant);
}
PortletSession portletSession = renderRequest.getPortletSession();
List<Attachment> attachments = attachmentManager.getAttachments(portletSession.getId());
applicant.setAttachments(attachments);
String datePattern = portletPreferences.getValue("datePattern", null);
models.put("jQueryDatePattern", _getJQueryDatePattern(datePattern));
models.put("provinces", provinceService.getAllProvinces());
CDI<Object> currentCDI = CDI.current();
BeanManager beanManager = currentCDI.getBeanManager();
Class<? extends BeanManager> beanManagerClass = beanManager.getClass();
Package beanManagerPackage = beanManagerClass.getPackage();
models.put("weldVersion", beanManagerPackage.getImplementationVersion());
// Thymeleaf
models.put("autoFillResourceURL", ControllerUtil.createResourceURL(renderResponse, "autoFill"));
models.put("deleteFileResourceURL", ControllerUtil.createResourceURL(renderResponse, "deleteFile"));
models.put("mainFormActionURL", renderResponse.createActionURL());
models.put("viewTermsResourceURL", ControllerUtil.createResourceURL(renderResponse, "viewTerms"));
models.put("uploadFilesResourceURL", ControllerUtil.createResourceURL(renderResponse, "uploadFiles"));
}
return viewName;
}
@POST
@Path("/booksNoValidate")
@ValidateOnExecution(type = ExecutableType.NONE)
public Response addBookNoValidation(@NotNull @FormParam("id") String id) {
return Response.ok().build();
}
@RenderMethod(portletNames = {"portlet1"})
@ValidateOnExecution(type = ExecutableType.NONE)
public String prepareView(RenderRequest renderRequest, RenderResponse renderResponse) {
String viewName = viewEngineContext.getView();
if (viewName == null) {
viewName = "user.html";
User user = (User) models.get("user");
if (user == null) {
user = new User();
models.put("user", user);
}
ActionURL actionURL = renderResponse.createActionURL();
MutableActionParameters actionParameters = actionURL.getActionParameters();
actionParameters.setValue(ActionRequest.ACTION_NAME, "submitUser");
models.put("submitUserActionURL", actionURL.toString());
}
logger.debug("[RENDER_PHASE] prepared model for viewName: {}", viewName);
return viewName;
}
@RenderMethod(portletNames = {"portlet1"})
@ValidateOnExecution(type = ExecutableType.NONE)
public String prepareView(RenderRequest renderRequest, RenderResponse renderResponse) {
String viewName = viewEngineContext.getView();
if (viewName == null) {
viewName = "user.jspx";
User user = (User) models.get("user");
if (user == null) {
user = new User();
models.put("user", user);
}
ActionURL actionURL = renderResponse.createActionURL();
MutableActionParameters actionParameters = actionURL.getActionParameters();
actionParameters.setValue(ActionRequest.ACTION_NAME, "submitUser");
models.put("submitUserActionURL", actionURL.toString());
}
logger.debug("[RENDER_PHASE] prepared model for viewName: {}", viewName);
return viewName;
}