use of org.springframework.beans.propertyeditors.CustomDateEditor in project spring-framework by spring-projects.
the class ConcurrentBeanFactoryTests method setUp.
@Before
public void setUp() throws Exception {
Assume.group(TestGroup.PERFORMANCE);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CONTEXT);
factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
@Override
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Date.class, new CustomDateEditor((DateFormat) DATE_FORMAT.clone(), false));
}
});
this.factory = factory;
}
use of org.springframework.beans.propertyeditors.CustomDateEditor 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;
}
use of org.springframework.beans.propertyeditors.CustomDateEditor in project disconf by knightliao.
the class BaseController method dateBinder.
/**
* 绑定时间
*
* @param binder
*/
@InitBinder
protected void dateBinder(WebDataBinder binder) {
// The date format to parse or output your dates
SimpleDateFormat dateFormat = new SimpleDateFormat(WebConstants.TIME_FORMAT);
// Create a new CustomDateEditor
CustomDateEditor editor = new CustomDateEditor(dateFormat, true);
// Register it as custom editor for the Date type
binder.registerCustomEditor(Date.class, editor);
}
use of org.springframework.beans.propertyeditors.CustomDateEditor in project spring-framework by spring-projects.
the class BindTagTests method transformTagOutsideBindTag.
@Test
public void transformTagOutsideBindTag() throws JspException {
// first set up the pagecontext and the bean
PageContext pc = createPageContext();
TestBean tb = new TestBean();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "tb");
CustomDateEditor l = new CustomDateEditor(df, true);
binder.registerCustomEditor(Date.class, l);
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", binder.getBindingResult());
// now try to execute the tag outside a bindtag
TransformTag transform = new TransformTag();
transform.setPageContext(pc);
transform.setVar("var");
transform.setValue("bla");
try {
transform.doStartTag();
fail("Tag can be executed outside BindTag");
} catch (JspException e) {
// this is ok!
}
// now try to execute the tag outside a bindtag, but inside a messageTag
MessageTag message = new MessageTag();
message.setPageContext(pc);
transform = new TransformTag();
transform.setPageContext(pc);
transform.setVar("var");
transform.setValue("bla");
transform.setParent(message);
try {
transform.doStartTag();
fail("Tag can be executed outside BindTag and inside messagtag");
} catch (JspException e) {
// this is ok!
}
}
use of org.springframework.beans.propertyeditors.CustomDateEditor in project spring-framework by spring-projects.
the class BindTagTests method nestingInFormTag.
/**
* SPR-4022
*/
@SuppressWarnings("serial")
@Test
public void nestingInFormTag() throws JspException {
PageContext pc = createPageContext();
TestBean tb = new TestBean();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "tb");
CustomDateEditor l = new CustomDateEditor(df, true);
binder.registerCustomEditor(Date.class, l);
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", binder.getBindingResult());
FormTag formTag = new FormTag() {
@Override
protected TagWriter createTagWriter() {
return new TagWriter(new StringWriter());
}
};
String action = "/form.html";
String commandName = "tb";
String name = "formName";
String enctype = "my/enctype";
String method = "POST";
String onsubmit = "onsubmit";
String onreset = "onreset";
String cssClass = "myClass";
String cssStyle = "myStyle";
String acceptCharset = "iso-8859-1";
formTag.setName(name);
formTag.setCssClass(cssClass);
formTag.setCssStyle(cssStyle);
formTag.setAction(action);
formTag.setModelAttribute(commandName);
formTag.setEnctype(enctype);
formTag.setMethod(method);
formTag.setOnsubmit(onsubmit);
formTag.setOnreset(onreset);
formTag.setAcceptCharset(acceptCharset);
formTag.setPageContext(pc);
formTag.doStartTag();
BindTag bindTag1 = new BindTag();
bindTag1.setPageContext(pc);
bindTag1.setPath("date");
bindTag1.doStartTag();
bindTag1.doEndTag();
BindTag bindTag2 = new BindTag();
bindTag2.setPageContext(pc);
bindTag2.setPath("tb.date");
bindTag2.doStartTag();
bindTag2.doEndTag();
BindTag bindTag3 = new BindTag();
bindTag3.setPageContext(pc);
bindTag3.setPath("tb");
bindTag3.doStartTag();
bindTag3.doEndTag();
formTag.doEndTag();
}
Aggregations