Search in sources :

Example 1 with CustomDateEditor

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;
}
Also used : PropertyEditorRegistry(org.springframework.beans.PropertyEditorRegistry) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) CustomDateEditor(org.springframework.beans.propertyeditors.CustomDateEditor) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) PropertyEditorRegistrar(org.springframework.beans.PropertyEditorRegistrar) Date(java.util.Date) Before(org.junit.Before)

Example 2 with CustomDateEditor

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;
}
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)

Example 3 with CustomDateEditor

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);
}
Also used : CustomDateEditor(org.springframework.beans.propertyeditors.CustomDateEditor) SimpleDateFormat(java.text.SimpleDateFormat) InitBinder(org.springframework.web.bind.annotation.InitBinder)

Example 4 with CustomDateEditor

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!
    }
}
Also used : JspException(javax.servlet.jsp.JspException) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) CustomDateEditor(org.springframework.beans.propertyeditors.CustomDateEditor) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ServletRequestDataBinder(org.springframework.web.bind.ServletRequestDataBinder) PageContext(javax.servlet.jsp.PageContext) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 5 with CustomDateEditor

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();
}
Also used : FormTag(org.springframework.web.servlet.tags.form.FormTag) StringWriter(java.io.StringWriter) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) CustomDateEditor(org.springframework.beans.propertyeditors.CustomDateEditor) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ServletRequestDataBinder(org.springframework.web.bind.ServletRequestDataBinder) TagWriter(org.springframework.web.servlet.tags.form.TagWriter) PageContext(javax.servlet.jsp.PageContext) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

CustomDateEditor (org.springframework.beans.propertyeditors.CustomDateEditor)12 SimpleDateFormat (java.text.SimpleDateFormat)10 DateFormat (java.text.DateFormat)7 Test (org.junit.Test)7 TestBean (org.springframework.tests.sample.beans.TestBean)7 ServletRequestDataBinder (org.springframework.web.bind.ServletRequestDataBinder)7 PageContext (javax.servlet.jsp.PageContext)6 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)6 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)6 InitBinder (org.springframework.web.bind.annotation.InitBinder)3 Date (java.util.Date)2 PropertyEditorRegistrar (org.springframework.beans.PropertyEditorRegistrar)2 PropertyEditorRegistry (org.springframework.beans.PropertyEditorRegistry)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 TodoPriorityPropertyEditor (com.in28minutes.springmvc.web.util.TodoPriorityPropertyEditor)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 JspException (javax.servlet.jsp.JspException)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 SdvFilterDataBean (org.akaza.openclinica.controller.helper.SdvFilterDataBean)1