Example usage for org.springframework.ui Model containsAttribute

List of usage examples for org.springframework.ui Model containsAttribute

Introduction

In this page you can find the example usage for org.springframework.ui Model containsAttribute.

Prototype

boolean containsAttribute(String attributeName);

Source Link

Document

Does this model contain an attribute of the given name?

Usage

From source file:com.web.mavenproject6.controller.CameraController.java

@RequestMapping(value = { "/camera" }, method = RequestMethod.GET)
public String defaultPage(Model model, Locale locale) throws ArithmeticException {
    log.debug("we are here uuu");
    if (!model.containsAttribute("user")) {
        model.addAttribute("user", new UserForm());
    }/* w w  w  .j av  a  2s . com*/
    log.debug("Check: reCaptcha " + (reCaptcha != null));
    if (reCaptcha != null) {
        model.addAttribute("recaptcha", reCaptcha.createRecaptchaHtml(null, null));
    }
    log.debug("we are exit");
    return "thy/camera";

}

From source file:no.dusken.barweb.admin.InvoiceControllerTest.java

@Test
public void testListInvoicesGjeng() {
    List<Invoice> invoices = new LinkedList<Invoice>();
    when(invoiceService.getByGjeng(any(Gjeng.class))).thenReturn(invoices);
    Model m = new ExtendedModelMap();
    String view = controller.listInvoices(666L, m);
    assertEquals("Wrong view", "no/dusken/barweb/admin/invoice/list", view);
    assertNotNull(m.asMap().get("invoices"));
    assertTrue("Should contain gjeng", m.containsAttribute("gjeng"));
}

From source file:cn.guoyukun.spring.jpa.web.controller.BaseCRUDController.java

@RequestMapping(value = "create", method = RequestMethod.GET)
public String showCreateForm(Model model) {

    if (permissionList != null) {
        this.permissionList.assertHasCreatePermission();
    }/*from  ww w . j a  v a 2s . c  om*/

    setCommonData(model);
    model.addAttribute(Constants.OP_NAME, "");
    if (!model.containsAttribute("m")) {
        model.addAttribute("m", newModel());
    }
    return viewName("editForm");
}

From source file:es.ucm.fdi.dalgs.course.web.CourseController.java

/**
 * Methods for modify courses//from ww  w  .j  a  v a  2  s.c  om
 */

@RequestMapping(value = "/academicTerm/{academicId}/course/{courseId}/modify.htm", method = RequestMethod.GET)
public String modifyCourseGET(@PathVariable("academicId") Long id_academic, @PathVariable("courseId") Long id,
        Model model) throws ServletException {

    if (!model.containsAttribute("modifyCourse")) {
        Course p = serviceCourse.getCourse(id, id_academic).getSingleElement();

        AcademicTerm academic = serviceAcademic.getAcademicTerm(id_academic, false).getSingleElement();

        Collection<Subject> subjects = serviceSubject.getSubjectForDegree(academic.getDegree());
        model.addAttribute("idSubject", p.getSubject().getId());

        model.addAttribute("academicTerm", academic);
        model.addAttribute("subjects", subjects);
        model.addAttribute("professors", serviceUser.getAllByRole("ROLE_PROFESSOR"));
        if (p.getCoordinator() != null)
            model.addAttribute("idCoordinator", p.getCoordinator().getId());

        model.addAttribute("modifyCourse", p);
    }
    model.addAttribute("professors", serviceUser.getAllByRole("ROLE_PROFESSOR"));
    return "course/modify";

}

From source file:org.jasig.portlet.degreeprogress.mvc.portlet.DegreeProgressController.java

@RequestMapping(params = "action=getScenario")
public String showDegreeProgressForm(Model model, PortletRequest request) {
    try {//from www . jav  a  2 s  .c  o m
        String currentTerm = coursesDao.getTermList(request).getCurrentTerm().getCode();

        if (!model.containsAttribute("whatIfForm")) {
            WhatIfRequest whatIfRequest = degreeProgressDao.createWhatIfRequest(request);
            whatIfRequest.setCampus("1");
            whatIfRequest.setCurrentTerm(currentTerm);
            model.addAttribute("whatIfForm", whatIfRequest);
        }
        model.addAttribute("campuses", degreeProgramDao.getCampuses());
        model.addAttribute("colleges", degreeProgramDao.getColleges());
        model.addAttribute("concentrations", degreeProgramDao.getConcentrations());
        model.addAttribute("degrees", degreeProgramDao.getDegrees());
        model.addAttribute("departments", degreeProgramDao.getDepartments());
        model.addAttribute("entryTerms", degreeProgramDao.getEntryTerms());
        model.addAttribute("evaluationTerms", degreeProgramDao.getEvaluationTerms());
        model.addAttribute("levels", degreeProgramDao.getLevels());
        model.addAttribute("minors", degreeProgramDao.getMinors());

        model.addAttribute("programs", degreeProgramDao.getPrograms(currentTerm));
        return "whatIf";

    } catch (Exception e) {
        System.out.println(e);
        return "error";
    }
}

From source file:es.ucm.fdi.dalgs.academicTerm.web.AcademicTermController.java

/**
 * Modify academicTerm GET//from  www  . jav a  2  s .  com
 * 
 * @param id_academic
 * @param model
 * @return String
 * @throws ServletException
 */
@RequestMapping(value = "/academicTerm/{academicId}/modify.htm", method = RequestMethod.GET)
public String modifyAcademictermGET(@PathVariable("academicId") Long id_academic, Model model)
        throws ServletException {

    if (!model.containsAttribute("academicTerm")) {
        AcademicTerm aT = serviceAcademicTerm.getAcademicTerm(id_academic, false).getSingleElement();

        model.addAttribute("academicTerm", aT);

    }

    return "academicTerm/modify";
}

From source file:org.openmrs.module.metadatasharing.web.controller.ExportController.java

@RequestMapping(value = CREATE_PATH, method = RequestMethod.GET)
public void create(Model model) {
    if (!model.containsAttribute(EXPORTER)) {
        model.addAttribute(EXPORTER, MetadataSharing.getInstance().newPackageExporter());
    }/*from  ww  w  . j  ava 2s . co m*/
    model.addAttribute("publishConfigured", MetadataSharing.getInstance().isPublishConfigured());
}

From source file:org.jasig.portlet.announcements.controller.AdminAnnouncementController.java

/**
 * Does all the prep work before showing the form
 *//*from  ww  w .  ja  va 2 s .co  m*/
@RequestMapping(params = "action=addAnnouncement")
public String showAddAnnouncementForm(@RequestParam(value = "editId", required = false) Long editId,
        @RequestParam(value = "topicId", required = false) Long topicId, RenderRequest request, Model model)
        throws PortletException {

    PortletPreferences prefs = request.getPreferences();

    if (!model.containsAttribute("announcement")) {
        Announcement ann = new Announcement();
        Topic topic = null;

        if (editId != null) {
            try {
                log.debug("editId found. This is an edit request for announcement Id " + editId.toString());
                ann = announcementService.getAnnouncement(editId);
                // return immediately when we have our announcement

            } catch (NumberFormatException e) {
                log.debug("No editId found. This is not an edit request");
            }
        }

        if (ann != null && ann.getParent() == null) {
            try {
                topic = announcementService.getTopic(topicId);
                ann.setParent(topic);
            } catch (NumberFormatException e) {
                log.error("Unable to get topicId from request");
            }
        }

        model.addAttribute("announcement", ann);
    }

    model.addAttribute("datePickerFormat", datePickerFormat);
    model.addAttribute("abstractMaxLength",
            prefs.getValue(PREFERENCE_ABSTRACT_MAX_LENGTH, DEFAULT_ABSTRACT_MAX_LENGTH));
    model.addAttribute("tinyMceInitializationOptions", prefs
            .getValue(PREFERENCE_TINY_MCE_INITIALIZATION_OPTIONS, DEFAULT_TINY_MCE_INITIALIZATION_OPTIONS));
    model.addAttribute("useAttachments",
            Boolean.valueOf(prefs.getValue(PREFERENCE_USE_ATTACHMENTS, DEFAULT_USE_ATTACHMENTS)));
    return "addAnnouncement";
}

From source file:com.google.code.trapo.controller.TopicControllerTests.java

@Test
public void when_there_are_validation_errors_forum_object_must_be_available() {

    final Topic topic = topic();
    final Model model = model();

    TopicsController controller = topicController(topicRepository());

    BindingResult errors = errors();/*w w  w.  j  a v a2s  .  c o  m*/
    when(errors.hasErrors()).thenReturn(true);

    controller.save(topic, errors, model);
    assertThat(model.containsAttribute("forum"), is(true));

}

From source file:org.iti.agrimarket.view.AddOfferController.java

@RequestMapping(value = { "/addoffer.htm" }, method = RequestMethod.GET)
public ModelAndView drawAddOfferPage(Locale locale, Model model) {
    locale = LocaleContextHolder.getLocale();
    List<Unit> units;/*from   w w w.  jav a  2  s  .  c  o  m*/
    units = unitService.getAllUnits();
    System.out.println(units.get(1).getNameEn());
    model.addAttribute("units", units);

    if (!model.containsAttribute("user")) {
        //model.addAttribute("user", user);
        System.out.println("------------------------");
        System.out.println("-----!model view ----------");
        return new ModelAndView("/signup");

    }
    // model.addAttribute("user",user);
    List<Product> products = productService.getAllProducts();
    System.out.println(products.get(1).getNameEn());

    model.addAttribute("products", products);
    model.addAttribute("lang", locale);

    String[] countryArr = { "Ad Daqahliyah", "Al Bahr al Ahmar", "Al Buhayrah", "Al Fayyum", "Al Gharbiyah",
            "Al Iskandariyah", "Al Isma'iliyah", "Al Jizah", "Al Minufiyah", "Al Minya", "Al Qahirah",
            "Al Qalyubiyah", "Al Wadi al Jadid", "As Suways", "Ash Sharqiyah", "Aswan", "Asyut", "Bani Suwayf",
            "Bur Sa'id", "Dumyat", "Janub Sina", "Kafr ash Shaykh", "Matruh", "Qina", "Shamal Sina", "Suhaj" };
    String[] countryArrAr = { "", "", "", "?",
            "", "", "", "",
            "?", "", "", " ",
            "", "", "", "", " ?", "",
            "", " ", "? ", "", "",
            " ", "" };

    model.addAttribute("states_ar", countryArrAr);
    model.addAttribute("states_us", countryArr);

    System.out.println("hello################  new offer");
    return new ModelAndView("addoffer");
}