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]));
}
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());
}
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);
}
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(",")));
}
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;
}
Aggregations