SpringFramework_3005

Last modified by superadmin on 2018-01-12 20:19

Back to Item Set

<p/>
<!-- START TestItem -->
<p/>
<div class="TestItem">
<div class="TestItemQuestion">3005 Question:\

What is a correct way to define a conversion of a form field value into <tt>java.util.Date</tt> object for a form backing bean?

</div>

Select 1 correct answer(s)!

<p/>
<ol class="MTestItemChoices" type='A'>
<li>

Add the following method to a controller:
{code}
@InitBinder
public void initBinder(WebDataBinder binder) {
    DateBinder dateBinder = new DateBinder("yyyy-MM-dd");
    binder.registerEditor(Date.class, new DateEditor(dateBinder, false));
}
{code}

</li>
<li>

Set a general property in Spring MVC context configuration file:
{code}
<context:date-binder enabled="true" class="java.util.Date" format="yyyy-MM-dd"/>
{code}

</li>
<li>

Add the following method to a controller:
{code}
@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
{code}

</li>
<li>

Set a general property in Spring MVC context configuration file:
{code}
<context:binding convert-date="true" format="yyyy-MM-dd"/>
{code}

</li>
</ol>
<p/>
<div class="TestItemSkill"><!--$skillid>Skill: $skilltitle</div>
<p/>
</div>
<!-- END MTestItem -->
<p/>
<p/>


{{/velocity}}

Tags:
Created by Alina Vasiljeva on 2013-01-13 11:11
    
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 6.4 - Documentation