Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It took me a few reads to fully grasp what the problem was, but it sounds like you know how to do the formatting with Spring but are having issues with the fact that jquery uses different patterns than Java when formatting a Date? I believe your best recourse may be to simply store two patterns in your properties:</p> <pre><code>java.date.format=yyyy-MM-dd... jquery.date.format=yyyy-mm-dd... </code></pre> <p>Obviously that means configuration would require making sure you used the equivalent format for each property so that they were always converted properly, but the only alternative I can see is creating an automatic format converter from jquery to java (or vice versa.)</p> <p>Alternatively, have you considered simply converting the date to milliseconds before submitting and then using that to recreate the Date on the java end? Would be much simpler, I imagine.</p> <p><strong>EDIT AFTER COMMENTS</strong></p> <p>Sounds like the goal is ultimately to have a single configurable property:</p> <pre><code>date.format=yyyy-mm-dd... </code></pre> <p>In order to avoid a complex mapping from jquery's date formatting tokens to Java's date formatting tokens, it might be best to simply create your own custom date format in the form of:</p> <pre><code>[millis],[timeZoneOffset] </code></pre> <p>Your properties file should contain the jquery format string so that your Datepicker will render the format you wish the client to see. Then, when a date is picked, you should convert it to your <code>[millis],[timeZoneOffset]</code> custom format before submitting to your controller. On the Spring/Java side, you should create and register a custom <code>Date</code> converter that accepts this <code>[millis],[timeZoneOffset]</code> format and creates the corresponding <code>Date</code> object.</p> <p>Personally, I don't see anything wrong with creating your own custom date format to solve this problem. You are going to save yourself a lot of headache that would come from trying to map jquery to Java, and, ultimately, it's what Spring's custom converters are there to help with.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload