Example usage for org.springframework.web.servlet ModelAndView getViewName

List of usage examples for org.springframework.web.servlet ModelAndView getViewName

Introduction

In this page you can find the example usage for org.springframework.web.servlet ModelAndView getViewName.

Prototype

@Nullable
public String getViewName() 

Source Link

Document

Return the view name to be resolved by the DispatcherServlet via a ViewResolver, or null if we are using a View object.

Usage

From source file:controller.book.java

@Override
public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {

    ModelAndView m = new ModelAndView("book");
    String docid = hsr.getParameter("search4");

    int subjectid = 0;
    if (docid != null && !docid.isEmpty())
        subjectid = Integer.parseInt(docid.trim());

    //String city = hsr.getParameter("doctordepartment");

    Session sessionx = HibernateUtil.getSessionFactory().getCurrentSession();
    sessionx.beginTransaction();//from  w  w w.java 2 s  .c  o m
    Query query = sessionx.createQuery("from Timings where id = :docid");
    //query.setParameter("doctordepartment", dep);
    //query.setParameter("city", city);
    query.setParameter("docid", subjectid);
    List list = query.list();
    //  if (list.size()==0){
    //     return new ModelAndView(new RedirectView("home.htm"));

    //  }
    m.addObject("book", list);
    m.getViewName();
    sessionx.getTransaction().commit();
    //return new ModelAndView(new RedirectView("home.htm"));

    return m;

}

From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java

/**
 * @see RadiologyObsFormController#unvoidObs(HttpServletRequest, HttpServletResponse, Obs, String)
 * @verifies unvoid voided obs for given request, response and obs
 *///  ww  w.  j  a v  a 2s.com
@Test
public void unvoidObs_shouldUnvoidVoidedObsForGivenRequestResponseAndObs() {
    //given
    mockObs.setVoided(true);
    mockRequest.addParameter("unvoidObs", "unvoidObs");

    ModelAndView modelAndView = radiologyObsFormController.unvoidObs(mockRequest, null, mockObs);
    assertThat(modelAndView.getViewName(), is("redirect:" + RADIOLOGY_OBS_FORM_URL + "orderId="
            + mockRadiologyOrder.getId() + "&obsId=" + mockObs.getId()));
    assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR),
            is("Obs.unvoidedSuccessfully"));
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java

/**
 * @see RadiologyObsFormController#getNewObs(RadiologyOrder)
 * @verifies populate model and view with new obs given a valid radiology order
 *//*from www  . j a va2 s.co  m*/
@Test
public void getNewObs_shouldPopulateModelAndViewWithNewObsGivenAValidRadiologyOrder() throws Exception {

    ModelAndView modelAndView = radiologyObsFormController.getNewObs(mockRadiologyOrder);

    assertThat(modelAndView, is(notNullValue()));
    assertThat(modelAndView.getViewName(), is("module/radiology/radiologyObsForm"));

    assertThat(modelAndView.getModelMap(), hasKey("obs"));
    Obs obs = (Obs) modelAndView.getModelMap().get("obs");

    assertThat(obs.getOrder(), is(notNullValue()));
    assertThat((RadiologyOrder) obs.getOrder(), is(mockRadiologyOrder));
    assertThat(obs.getPerson(), is((Person) mockRadiologyOrder.getPatient()));
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java

/**
 * @see RadiologyObsFormController#saveObs(HttpServletRequest,HttpServletResponse,String,RadiologyOrder,Obs,BindingResult)
 * @verifies return redirecting model and view for not authenticated user
 *//*from w w  w.jav  a  2  s.com*/
@Test
public void saveObs_shouldReturnRedirectingModelAndViewForNotAuthenticatedUser() throws Exception {
    //given
    mockRequest.addParameter("saveObs", "saveObs");

    when(Context.getAuthenticatedUser()).thenReturn(null);

    ModelAndView modelAndView = radiologyObsFormController.saveObs(mockRequest, null, "", mockRadiologyOrder,
            mockObs, obsErrors);

    assertThat(modelAndView.getViewName(), is("redirect:" + RADIOLOGY_OBS_FORM_URL + "orderId="
            + mockRadiologyOrder.getId() + "&obsId=" + mockObs.getId()));
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java

/**
 * @see RadiologyObsFormController#getObs(RadiologyOrder,Obs)
 * @verifies populate model and view with obs for given obs and given valid radiology order
 *//*from w  ww  .ja va 2  s .  c  o m*/
@Test
public void getObs_shouldPopulateModelAndViewWithObsForGivenObsAndGivenValidRadiologyOrder() throws Exception {

    ModelAndView modelAndView = radiologyObsFormController.getObs(mockRadiologyOrder, mockObs);

    assertThat(modelAndView, is(notNullValue()));
    assertThat(modelAndView.getViewName(), is("module/radiology/radiologyObsForm"));

    assertThat(modelAndView.getModelMap(), hasKey("obs"));
    Obs obs = (Obs) modelAndView.getModelMap().get("obs");
    assertThat(obs, is(mockObs));
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java

/**
 * @see RadiologyObsFormController#saveObs(HttpServletRequest,HttpServletResponse,String,RadiologyOrder,Obs,BindingResult)
 * @verifies return populated model and view for invalid obs
 *//*from w ww  .ja  va 2  s. c om*/
@Test
public void saveObs_shouldReturnPopulatedModelAndViewForInvalidObs() throws Exception {
    //given
    mockRequest.addParameter("saveObs", "saveObs");

    when(obsErrors.hasErrors()).thenReturn(true);
    when(obsService.saveObs(mockObs, "Test Edit Reason")).thenReturn(RadiologyTestData.getEditedMockObs());

    ModelAndView modelAndView = radiologyObsFormController.saveObs(mockRequest, null, "Test Edit Reason",
            mockRadiologyOrder, mockObs, obsErrors);

    assertThat(modelAndView.getViewName(), is("module/radiology/radiologyObsForm"));
    assertThat(modelAndView, is(notNullValue()));

    assertThat(modelAndView.getModelMap(), hasKey("obs"));
    Obs obs = (Obs) modelAndView.getModelMap().get("obs");
    assertThat(obs, is(mockObs));
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java

/**
 * @see RadiologyObsFormController#saveComplexObs(MultipartHttpServletRequest,HttpServletResponse,String,RadiologyOrder,Obs,BindingResult)
 * @verifies return redirecting model and view for not authenticated user
 *///  w  ww  . ja  v a 2s  .  com
@Test
public void saveComplexObs_shouldReturnRedirectingModelAndViewForNotAuthenticatedUser() throws Exception {

    when(Context.getAuthenticatedUser()).thenReturn(null);

    ModelAndView modelAndView = radiologyObsFormController.saveComplexObs(
            mockMultipartHttpServletRequestRequest, null, "", mockRadiologyOrder, mockObs, obsErrors);

    assertThat(modelAndView.getViewName(), is("redirect:" + RADIOLOGY_OBS_FORM_URL + "orderId="
            + mockRadiologyOrder.getId() + "&obsId=" + mockObs.getId()));
}

From source file:org.dspace.webmvc.theme.ThemeChangeInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request);
    if (themeResolver == null) {
        throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?");
    }//w w w . ja  v  a 2 s . c om

    String newTheme = request.getParameter(this.paramName);
    if (newTheme != null) {
        themeResolver.setThemeName(request, response, newTheme);
        response.addCookie(new Cookie("themeName", newTheme));
    } else {
        ThemeMapEntry bestMatch = null;

        for (ThemeMapEntry entry : themeMappings) {

            if (entry.mapType == MapType.VIEW || entry.mapType == MapType.ANY) {
                if (modelAndView != null && pathMatcher.match(entry.path, modelAndView.getViewName())) {
                    if (entry.isBestMatch(bestMatch)) {
                        bestMatch = entry;
                    }
                }
            }

            if (entry.mapType == MapType.URL || entry.mapType == MapType.ANY) {
                String path = urlPathHelper.getLookupPathForRequest(request);
                if (pathMatcher.match(entry.path, path)) {
                    if (entry.isBestMatch(bestMatch)) {
                        bestMatch = entry;
                    }
                }
            }

            if (entry.mapType == MapType.CONTROLLER || entry.mapType == MapType.ANY) {

            }
        }

        if (bestMatch != null) {
            themeResolver.setThemeName(request, response, bestMatch.themeName);
        } else if (request.getCookies() != null) {
            for (Cookie cookie : request.getCookies()) {
                if ("themeName".equals(cookie.getName())) {
                    themeResolver.setThemeName(request, response, cookie.getValue());
                }
            }
        }
    }

    super.postHandle(request, response, handler, modelAndView);
}

From source file:com.formkiq.core.service.workflow.WorkflowEditorServiceImplTest.java

/**
 * testStartEdit02()./*from   w  w  w.j  av  a 2  s  .  c o  m*/
 * start on new entry, IE: UUID is null
 * @throws IOException IOException
 *
 */
@Test
public void testStartEdit02() throws IOException {
    // given
    String uuidNull = null;
    MockHttpServletRequest req = new MockHttpServletRequest();

    // when
    replayAll();

    Pair<ModelAndView, WebFlow> result = this.ws.startEdit(req, this.folder, uuidNull);

    // then
    verifyAll();

    final int states = 4;

    ModelAndView mav = result.getLeft();
    assertEquals("redirect:/user/designer/edit?execution=s1e1", mav.getViewName());

    WebFlow wf = result.getRight();
    assertEquals(states, wf.getStates().size());
}

From source file:com.formkiq.core.service.workflow.WorkflowEditorServiceImplTest.java

/**
 * testStartEdit01()./*  w w  w . j ava2 s  .co  m*/
 * @throws IOException IOException
 *
 */
@Test
public void testStartEdit01() throws IOException {
    // given
    MockHttpServletRequest req = new MockHttpServletRequest();
    FormJSON form = TestDataBuilder.createAllFields();
    String sha1hash = UUID.randomUUID().toString();
    String step = UUID.randomUUID().toString();
    List<String> steps = Arrays.asList(step);

    // when
    expect(this.archiveService.get(this.folder, this.uuid, false))
            .andReturn(Pair.of(this.mockarchive, sha1hash));

    expect(this.mockarchive.getWorkflow()).andReturn(this.mockworkflow).times(2);

    expect(this.mockworkflow.getSteps()).andReturn(steps);
    expect(this.mockarchive.getForm(step)).andReturn(form);

    replayAll();

    Pair<ModelAndView, WebFlow> result = this.ws.startEdit(req, this.folder, this.uuid);

    // then
    verifyAll();

    final int states = 5;

    ModelAndView mav = result.getLeft();
    assertEquals("redirect:/user/designer/edit?execution=s1e1", mav.getViewName());

    WebFlow wf = result.getRight();
    assertEquals(states, wf.getStates().size());
}