Search in sources :

Example 6 with ServletRequestDataBinder

use of org.springframework.web.bind.ServletRequestDataBinder in project spring-framework by spring-projects.

the class BindTagTests method bindTagWithIndexedProperties.

@Test
public void bindTagWithIndexedProperties() throws JspException {
    PageContext pc = createPageContext();
    IndexedTestBean tb = new IndexedTestBean();
    Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
    errors.rejectValue("array[0]", "code1", "message1");
    errors.rejectValue("array[0]", "code2", "message2");
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
    BindTag tag = new BindTag();
    tag.setPageContext(pc);
    tag.setPath("tb.array[0]");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
    assertTrue("Has status variable", status != null);
    assertTrue("Correct expression", "array[0]".equals(status.getExpression()));
    assertTrue("Value is TestBean", status.getValue() instanceof TestBean);
    assertTrue("Correct value", "name0".equals(((TestBean) status.getValue()).getName()));
    assertTrue("Correct isError", status.isError());
    assertTrue("Correct errorCodes", status.getErrorCodes().length == 2);
    assertTrue("Correct errorMessages", status.getErrorMessages().length == 2);
    assertTrue("Correct errorCode", "code1".equals(status.getErrorCodes()[0]));
    assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[1]));
    assertTrue("Correct errorMessage", "message1".equals(status.getErrorMessages()[0]));
    assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[1]));
}
Also used : IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) Errors(org.springframework.validation.Errors) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) ServletRequestDataBinder(org.springframework.web.bind.ServletRequestDataBinder) PageContext(javax.servlet.jsp.PageContext) BindStatus(org.springframework.web.servlet.support.BindStatus) Test(org.junit.Test)

Example 7 with ServletRequestDataBinder

use of org.springframework.web.bind.ServletRequestDataBinder in project spring-framework by spring-projects.

the class BindTagTests method nestedPathWithBindTagWithIgnoreNestedPath.

@Test
public void nestedPathWithBindTagWithIgnoreNestedPath() throws JspException {
    PageContext pc = createPageContext();
    Errors errors = new ServletRequestDataBinder(new TestBean(), "tb2").getBindingResult();
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb2", errors);
    NestedPathTag tag = new NestedPathTag();
    tag.setPath("tb");
    tag.setPageContext(pc);
    tag.doStartTag();
    BindTag bindTag = new BindTag();
    bindTag.setPageContext(pc);
    bindTag.setIgnoreNestedPath(true);
    bindTag.setPath("tb2.name");
    assertTrue("Correct doStartTag return value", bindTag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
    assertTrue("Has status variable", status != null);
    assertEquals("tb2.name", status.getPath());
}
Also used : Errors(org.springframework.validation.Errors) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) ServletRequestDataBinder(org.springframework.web.bind.ServletRequestDataBinder) PageContext(javax.servlet.jsp.PageContext) BindStatus(org.springframework.web.servlet.support.BindStatus) Test(org.junit.Test)

Example 8 with ServletRequestDataBinder

use of org.springframework.web.bind.ServletRequestDataBinder in project spring-framework by spring-projects.

the class BindTagTests method bindErrorsTagWithErrors.

@Test
public void bindErrorsTagWithErrors() throws JspException {
    PageContext pc = createPageContext();
    Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
    errors.reject("test", null, "test");
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
    BindErrorsTag tag = new BindErrorsTag();
    tag.setPageContext(pc);
    tag.setName("tb");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    assertTrue("Has errors variable", pc.getAttribute(BindErrorsTag.ERRORS_VARIABLE_NAME, PageContext.REQUEST_SCOPE) == errors);
}
Also used : Errors(org.springframework.validation.Errors) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) ServletRequestDataBinder(org.springframework.web.bind.ServletRequestDataBinder) PageContext(javax.servlet.jsp.PageContext) Test(org.junit.Test)

Example 9 with ServletRequestDataBinder

use of org.springframework.web.bind.ServletRequestDataBinder in project spring-framework by spring-projects.

the class BindTagTests method bindTagWithoutErrors.

@Test
public void bindTagWithoutErrors() throws JspException {
    PageContext pc = createPageContext();
    Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
    BindTag tag = new BindTag();
    tag.setPageContext(pc);
    tag.setPath("tb");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
    assertTrue("Has status variable", status != null);
    assertTrue("Correct expression", status.getExpression() == null);
    assertTrue("Correct value", status.getValue() == null);
    assertTrue("Correct displayValue", "".equals(status.getDisplayValue()));
    assertTrue("Correct isError", !status.isError());
    assertTrue("Correct errorCodes", status.getErrorCodes().length == 0);
    assertTrue("Correct errorMessages", status.getErrorMessages().length == 0);
    assertTrue("Correct errorCode", "".equals(status.getErrorCode()));
    assertTrue("Correct errorMessage", "".equals(status.getErrorMessage()));
    assertTrue("Correct errorMessagesAsString", "".equals(status.getErrorMessagesAsString(",")));
}
Also used : Errors(org.springframework.validation.Errors) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) ServletRequestDataBinder(org.springframework.web.bind.ServletRequestDataBinder) PageContext(javax.servlet.jsp.PageContext) BindStatus(org.springframework.web.servlet.support.BindStatus) Test(org.junit.Test)

Example 10 with ServletRequestDataBinder

use of org.springframework.web.bind.ServletRequestDataBinder in project OpenClinica by OpenClinica.

the class SDVController method viewAllSubjectFormHandler.

@RequestMapping("/viewAllSubjectSDVform")
public ModelMap viewAllSubjectFormHandler(HttpServletRequest request, HttpServletResponse response, @RequestParam("studyId") int studyId) {
    ModelMap gridMap = new ModelMap();
    StudyDAO studyDAO = new StudyDAO(dataSource);
    // StudyEventDAO studyEventDAO = new StudyEventDAO(dataSource);
    StudyBean studyBean = (StudyBean) studyDAO.findByPK(studyId);
    String pattern = "MM/dd/yyyy";
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    //  List<StudyEventBean> studyEventBeans = studyEventDAO.findAllByStudy(studyBean);
    //  List<EventCRFBean> eventCRFBeans = sdvUtil.getAllEventCRFs(studyEventBeans);
    //set up the parameters to take part in filtering
    ServletRequestDataBinder dataBinder = new ServletRequestDataBinder(new SdvFilterDataBean());
    dataBinder.setAllowedFields(new String[] { "study_subject_id", "studyEventDefinition", "studyEventStatus", "eventCRFStatus", "sdvRequirement", "eventcrfSDVStatus", "startUpdatedDate", "endDate", "eventCRFName" });
    dataBinder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(sdf, true));
    dataBinder.bind(request);
    BindingResult bindingResult = dataBinder.getBindingResult();
    //  eventCRFBeans = sdvUtil.filterEventCRFs(eventCRFBeans,bindingResult);
    //set up request attributes for sidebar
    //Not necessary when using old page design...
    // setUpSidebar(request);
    request.setAttribute("studyId", studyId);
    //We need a study subject id for the first tab; take it somewhat arbitrarily from the first study event bean
    /* int studySubjectId = 0;

        StudyEventBean studyBeanUrl = studyEventBeans.get(0);
        if(studyBeanUrl != null) {
            studySubjectId= studyBeanUrl.getStudySubjectId();
        }
        request.setAttribute("studySubjectId",studySubjectId);*/
    //set up the elements for the view's filter box
    /*sdvUtil.prepareSDVSelectElements(request,studyBean);*/
    ArrayList<String> pageMessages = (ArrayList<String>) request.getAttribute("pageMessages");
    if (pageMessages == null) {
        pageMessages = new ArrayList<String>();
    }
    request.setAttribute("pageMessages", pageMessages);
    String sdvMatrix = sdvUtil.renderEventCRFTableWithLimit(request, studyId, "");
    gridMap.addAttribute(SUBJECT_SDV_TABLE_ATTRIBUTE, sdvMatrix);
    return gridMap;
}
Also used : BindingResult(org.springframework.validation.BindingResult) CustomDateEditor(org.springframework.beans.propertyeditors.CustomDateEditor) ModelMap(org.springframework.ui.ModelMap) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ServletRequestDataBinder(org.springframework.web.bind.ServletRequestDataBinder) ArrayList(java.util.ArrayList) SdvFilterDataBean(org.akaza.openclinica.controller.helper.SdvFilterDataBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ServletRequestDataBinder (org.springframework.web.bind.ServletRequestDataBinder)29 Test (org.junit.Test)25 TestBean (org.springframework.tests.sample.beans.TestBean)24 PageContext (javax.servlet.jsp.PageContext)22 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)22 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)21 Errors (org.springframework.validation.Errors)16 BindStatus (org.springframework.web.servlet.support.BindStatus)14 SimpleDateFormat (java.text.SimpleDateFormat)7 CustomDateEditor (org.springframework.beans.propertyeditors.CustomDateEditor)7 DateFormat (java.text.DateFormat)6 WebDataBinder (org.springframework.web.bind.WebDataBinder)3 HashMap (java.util.HashMap)2 PropertyEditorSupport (java.beans.PropertyEditorSupport)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 ServletRequest (javax.servlet.ServletRequest)1 JspException (javax.servlet.jsp.JspException)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 SdvFilterDataBean (org.akaza.openclinica.controller.helper.SdvFilterDataBean)1