Java Code Examples for org.springframework.ui.Model#containsAttribute()

The following examples show how to use org.springframework.ui.Model#containsAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobListenersController.java    From spring-batch-lightmin with Apache License 2.0 6 votes vote down vote up
@GetMapping(value = "/job-listener", params = {"init-edit-listener"})
public void initSchedulerUpdate(
        final Model model,
        @RequestParam(name = "job-configuration-id") final Long jobConfigurationId,
        @RequestParam(name = "application-instance-id") final String applicationInstanceId) {

    final ListenerJobConfigurationModel listenerConfiguration;

    if (model.containsAttribute("listenerConfiguration")) {
        listenerConfiguration = (ListenerJobConfigurationModel) model.asMap().get("listenerConfiguration");
        final JobListenerModel listenerModel = listenerConfiguration.getConfig();
        final String listenerType = listenerModel.getType();
        listenerModel.setTypeRead(new ListenerTypeModel(ListenerTypeModel.JobListenerType.valueOf(listenerType)));
    } else {
        listenerConfiguration = this.jobListenerFeService.getJobConfigurationModel(jobConfigurationId, applicationInstanceId);
    }

    model.addAttribute("listenerConfiguration", listenerConfiguration);
    model.addAttribute("modificationType", new ModificationTypeModel(ModificationTypeModel.ModificationType.UPDATE));
    this.initApplicationContextModel(model, applicationInstanceId);
}
 
Example 2
Source File: ProfileController.java    From zhcet-web with Apache License 2.0 6 votes vote down vote up
@GetMapping("/settings")
public String profileSettings(Model model) {
    User user = userService.getLoggedInUser().orElseThrow(() -> new AccessDeniedException("403"));
    model.addAttribute("user", user);

    if (!model.containsAttribute("user_details"))
        model.addAttribute("user_details", user.getDetails());

    model.addAttribute("page_title", "Profile Settings");
    model.addAttribute("page_subtitle", "Profile Settings for " + user.getName());
    model.addAttribute("page_description", "Manage Profile Details and Account");
    model.addAttribute("genders", Gender.values());

    if (user.getType().equals(UserType.STUDENT)) {
        studentService.getLoggedInStudent().ifPresent(student -> model.addAttribute("student", student));
    } else {
        facultyService.getLoggedInMember().ifPresent(facultyMember -> model.addAttribute("faculty", facultyMember));
    }
    return "user/edit_profile";
}
 
Example 3
Source File: CourseCreationController.java    From zhcet-web with Apache License 2.0 6 votes vote down vote up
@GetMapping
public String addCourse(Model model, @PathVariable Department department) {
    ErrorUtils.requireNonNullDepartment(department);

    model.addAttribute("page_description", "Create new global course for the Department");
    model.addAttribute("department", department);
    model.addAttribute("page_title", "Add Course : " + department.getName() + " Department");
    model.addAttribute("page_subtitle", "Course Management");
    model.addAttribute("page_path", getPath(department));

    model.addAttribute("course_types", CourseType.values());

    if (!model.containsAttribute("course")) {
        Course course = new Course();
        course.setDepartment(department);
        model.addAttribute("course", course);
    }

    return "department/add_course";
}
 
Example 4
Source File: JobListenersController.java    From spring-batch-lightmin with Apache License 2.0 6 votes vote down vote up
@GetMapping(value = "/job-listener", params = {"init-add-listener"})
public void initListenerAdd(
        final Model model,
        @RequestParam(name = "listener-type") final String listenerType,
        @RequestParam(name = "application-instance-id") final String applicationInstanceId) {

    final ListenerJobConfigurationModel listenerConfiguration;
    final JobListenerModel listenerModel;
    if (model.containsAttribute("listenerConfiguration")) {
        listenerConfiguration = (ListenerJobConfigurationModel) model.asMap().get("listenerConfiguration");
        listenerModel = listenerConfiguration.getConfig();
    } else {
        listenerConfiguration = new ListenerJobConfigurationModel();
        listenerModel = new JobListenerModel();
        listenerModel.setType(listenerType);
        listenerConfiguration.setConfig(listenerModel);
    }
    listenerModel.setTypeRead(new ListenerTypeModel(ListenerTypeModel.JobListenerType.valueOf(listenerType)));

    model.addAttribute("listenerConfiguration", listenerConfiguration);
    model.addAttribute("modificationType", new ModificationTypeModel(ModificationTypeModel.ModificationType.ADD));
    this.initApplicationContextModel(model, applicationInstanceId);
}
 
Example 5
Source File: JobSchedulersController.java    From spring-batch-lightmin with Apache License 2.0 6 votes vote down vote up
@GetMapping(value = "/job-scheduler", params = {"init-edit-scheduler"})
public void initSchedulerUpdate(
        final Model model,
        @RequestParam(name = "job-configuration-id") final Long jobConfigurationId,
        @RequestParam(name = "application-instance-id") final String applicationInstanceId) {

    final SchedulerJobConfigurationModel schedulerConfiguration;

    if (model.containsAttribute("schedulerConfiguration")) {
        schedulerConfiguration = (SchedulerJobConfigurationModel) model.asMap().get("schedulerConfiguration");
        final JobSchedulerModel schedulerModel = schedulerConfiguration.getConfig();
        final String schedulerType = schedulerModel.getType();
        schedulerModel.setTypeRead(new SchedulerTypeModel(SchedulerTypeModel.JobSchedulerType.valueOf(schedulerType)));
    } else {
        schedulerConfiguration = this.jobSchedulerFeService.getJobConfigurationModel(jobConfigurationId, applicationInstanceId);
    }

    model.addAttribute("schedulerConfiguration", schedulerConfiguration);
    model.addAttribute("modificationType", new ModificationTypeModel(ModificationTypeModel.ModificationType.UPDATE));
    this.initApplicationContextModel(model, applicationInstanceId);
}
 
Example 6
Source File: HomeController.java    From Spring with Apache License 2.0 5 votes vote down vote up
@RequestMapping(method = RequestMethod.GET)
public ModelAndView showForm(Model model) {
    ModelAndView mav = new ModelAndView("register");
    log.info("Registration");
    if (!model.containsAttribute("user")) {
        mav.addObject("user", user);
    } else
        mav.addObject(model);
    return mav;
}
 
Example 7
Source File: LoginController.java    From Spring with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView showLogin(Model model) {
    ModelAndView mav = new ModelAndView("login");
    log.info("Login");
    if (!model.containsAttribute("user")) {
        mav.addObject("user", user);
    } else
        mav.addObject(model);
    return mav;
}
 
Example 8
Source File: FrontendController.java    From spring-cloud-gcp-guestbook with Apache License 2.0 5 votes vote down vote up
@GetMapping("/")
public String index(Model model) {
	if (model.containsAttribute("name")) {
		String name = (String) model.asMap().get("name");
		model.addAttribute("greeting", String.format("%s %s", greeting, name));
	}
	model.addAttribute("messages", client.getMessages().getContent());
	return "index";
}
 
Example 9
Source File: UserGroupController.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@RequestMapping("/{id:-?[0-9]\\d*}/view.action")
  public String view(ComAdmin admin, @PathVariable("id") int userGroupId, Model model) {
      if(userGroupId == NEW_USER_GROUP_ID) {
          return "redirect:/administration/usergroup/create.action";
      }

      UserGroupForm form = null;
if(model.containsAttribute("userGroupForm")) {
	form = (UserGroupForm) model.asMap().get("userGroupForm");
} else {
          UserGroupDto userGroup = userGroupService.getUserGroup(admin, userGroupId);
          if (Objects.nonNull(userGroup)) {
              form = conversionService.convert(userGroup, UserGroupForm.class);
          }
      }

      if(form == null) {
          return "redirect:/administration/usergroup/create.action";
      }

      logger.info("loadAdmin: admin " + userGroupId + " loaded");
      userActivityLogService.writeUserActivityLog(admin, "admin group view", getDescription(form), logger);

      model.addAttribute("userGroupForm", form);
      model.addAttribute("currentCompanyId", admin.getCompanyID());
      loadPermissionsSettings(admin, form.getId(), form.getCompanyId(), model);

      return "settings_usergroup_view";
  }
 
Example 10
Source File: ApiController.java    From scoold with Apache License 2.0 5 votes vote down vote up
private void checkForErrorsAndThrow(Model model) {
	if (model != null && model.containsAttribute("error")) {
		Object err = model.getAttribute("error");
		if (err instanceof String) {
			badReq((String) err);
		} else if (err instanceof Map) {
			Map<String, String> error = (Map<String, String>) err;
			badReq(error.entrySet().stream().map(e -> "'" + e.getKey() + "' " +
					e.getValue()).collect(Collectors.joining("; ")));
		}
	}
}
 
Example 11
Source File: HelloworldUiController.java    From docker-kubernetes-by-example-java with Apache License 2.0 5 votes vote down vote up
@GetMapping("/")
public String index(HttpSession session, Model model) {
  if (model.containsAttribute("name")) {
    String name = (String) model.asMap().get("name");
    Map<String, String> greeting = helloworldService.greeting(name);
    model.addAttribute("greeting", greeting);
  }

  model.addAttribute("messages", guestbookService.all());

  return "index";
}
 
Example 12
Source File: MessageController.java    From es with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/{parent}/reply", method = RequestMethod.GET)
public String showReplyForm(@PathVariable("parent") Message parent, Model model) {
    if (!model.containsAttribute("m")) {
        Message m = newModel();
        m.setParentId(parent.getId());
        m.setParentIds(parent.getParentIds());
        m.setReceiverId(parent.getSenderId());
        m.setTitle(MessageApi.REPLY_PREFIX + parent.getTitle());
        model.addAttribute("m", m);
    }
    model.addAttribute(Constants.OP_NAME, "回复消息");
    return viewName("sendForm");
}
 
Example 13
Source File: BaseCRUDController.java    From es with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "create", method = RequestMethod.GET)
public String showCreateForm(Model model) {

    if (permissionList != null) {
        this.permissionList.assertHasCreatePermission();
    }

    setCommonData(model);
    model.addAttribute(Constants.OP_NAME, "新增");
    if (!model.containsAttribute("m")) {
        model.addAttribute("m", newModel());
    }
    return viewName("editForm");
}
 
Example 14
Source File: FrontendController.java    From spring-cloud-gcp-guestbook with Apache License 2.0 5 votes vote down vote up
@GetMapping("/")
public String index(Model model) {
	if (model.containsAttribute("name")) {
		String name = (String) model.asMap().get("name");
		model.addAttribute("greeting", String.format("%s %s", greeting, name));
	}
	model.addAttribute("messages", client.getMessages().getContent());
	return "index";
}
 
Example 15
Source File: LogonControllerBasic.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Anonymous
@GetMapping("/logon/change-password.action")
public String changePassword(Logon logon, @ModelAttribute("form") LogonPasswordChangeForm form, Model model, HttpServletRequest request) {
    model.addAttribute("layoutdir", logonService.getLayoutDirectory(request.getServerName()));

    if (model.containsAttribute(PASSWORD_CHANGED_KEY)) {
        logon.require(LogonState.COMPLETE);
        return "logon_password_changed";
    } else {
        logon.require(LogonState.CHANGE_ADMIN_PASSWORD, LogonState.CHANGE_SUPERVISOR_PASSWORD);

        ComAdmin admin = logon.getAdmin();
        PasswordState state = logonService.getPasswordState(admin);

        // Expiration date is only required if password is already expired or a "deadline" is coming.
        if (state == PasswordState.EXPIRING || state == PasswordState.EXPIRED || state == PasswordState.EXPIRED_LOCKED) {
            Date expirationDate = logonService.getPasswordExpirationDate(admin);

            if (expirationDate != null) {
                model.addAttribute("expirationDate", admin.getDateFormat().format(expirationDate));
            }
        }

        model.addAttribute("helplanguage", logonService.getHelpLanguage(admin));
        model.addAttribute("isSupervisor", admin.isSupervisor());
        model.addAttribute("supportMailAddress", configService.getValue(ConfigValue.Mailaddress_Support));

        if (state == PasswordState.EXPIRED_LOCKED) {
            return "logon_password_expired_locked";
        } else {
            model.addAttribute("isExpiring", state == PasswordState.EXPIRING);
            model.addAttribute("isExpired", state == PasswordState.EXPIRED || state == PasswordState.ONE_TIME);

            return "logon_password_change";
        }
    }
}
 
Example 16
Source File: AjaxUploadFormController.java    From es with Apache License 2.0 5 votes vote down vote up
@RequiresPermissions("showcase:upload:create")
@RequestMapping(value = "create", method = RequestMethod.GET)
public String showCreateForm(Model model) {
    model.addAttribute(Constants.OP_NAME, "新增");
    if (!model.containsAttribute("upload")) {
        model.addAttribute("upload", new Upload());
    }
    return "showcase/upload/ajax/editForm";
}
 
Example 17
Source File: FrontendController.java    From spring-cloud-gcp-guestbook with Apache License 2.0 5 votes vote down vote up
@GetMapping("/")
public String index(Model model) {
	if (model.containsAttribute("name")) {
		String name = (String) model.asMap().get("name");
		model.addAttribute("greeting", String.format("%s %s", greeting, name));
	}
	model.addAttribute("messages", client.getMessages().getContent());
	return "index";
}
 
Example 18
Source File: ControllerHelper.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void addErrorMessage(String message, Model model) {
    if (!model.containsAttribute(ERROR_MESSAGES)) {
        model.addAttribute(ERROR_MESSAGES, new ArrayList<String>());
    }
    ((List<String>) model.asMap().get(ERROR_MESSAGES)).add(message);
}
 
Example 19
Source File: ViewConfigController.java    From kafka-webview with MIT License 4 votes vote down vote up
/**
 * GET Displays create view form.
 */
@RequestMapping(path = "/create", method = RequestMethod.GET)
public String createViewForm(final ViewForm viewForm, final Model model) {
    // Setup breadcrumbs
    if (!model.containsAttribute("BreadCrumbs")) {
        setupBreadCrumbs(model, "Create", null);
    }

    // Retrieve all clusters
    model.addAttribute("clusters", clusterRepository.findAllByOrderByNameAsc());

    // Retrieve all message formats
    model.addAttribute("defaultMessageFormats", messageFormatRepository.findByIsDefaultFormatOrderByNameAsc(true));
    model.addAttribute("customMessageFormats", messageFormatRepository.findByIsDefaultFormatOrderByNameAsc(false));

    // If we have a cluster Id
    model.addAttribute("topics", new ArrayList<>());
    model.addAttribute("partitions", new ArrayList<>());

    // Retrieve all filters
    model.addAttribute("filterList", filterRepository.findAllByOrderByNameAsc());
    model.addAttribute("filterParameters", new HashMap<Long, Map<String, String>>());

    if (viewForm.getClusterId() != null) {
        // Lets load the topics now
        // Retrieve cluster
        clusterRepository.findById(viewForm.getClusterId()).ifPresent((cluster) -> {
            try (final KafkaOperations operations = kafkaOperationsFactory.create(cluster, getLoggedInUserId())) {
                final TopicList topics = operations.getAvailableTopics();
                model.addAttribute("topics", topics.getTopics());

                // If we have a selected topic
                if (viewForm.getTopic() != null && !"!".equals(viewForm.getTopic())) {
                    final TopicDetails topicDetails = operations.getTopicDetails(viewForm.getTopic());
                    model.addAttribute("partitions", topicDetails.getPartitions());
                }
            }
        });
    }

    return "configuration/view/create";
}
 
Example 20
Source File: ControllerHelper.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void addWarningMessage(String message, Model model) {
    if (!model.containsAttribute(WARNING_MESSAGES)) {
        model.addAttribute(WARNING_MESSAGES, new ArrayList<String>());
    }
    ((List<String>) model.asMap().get(WARNING_MESSAGES)).add(message);
}