Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is another way of getting around this problem. My solution does not require changing the <code>select.tagx</code> file.</p> <p>I made changes to two places.</p> <p>Firstly, at the <code>BookController</code>, I had overwritten the populate method for this particular object, <code>Publisher</code>, for example.</p> <pre><code>@ModelAttribute("publisher") public Collection&lt;Publisher&gt; populatePublisher() { Collection&lt;Publisher&gt; result = new ArrayList&lt;Publisher&gt;(); // Add an empty item Publishertmp = new Publisher(); tmp.setId(0L); result.add(tmp); result.addAll(Publisher.findAllPublisher()); return result ; } </code></pre> <p>It is important to set the Id to 0. If the Id is not 0, the first empty item will not be displayed.</p> <p>Then I had overwritten the <code>ApplicationConversionServiceFactoryBean</code> </p> <pre><code>protected void installFormatters(FormatterRegistry registry) { registry.addConverter(new PublisherConverter()); super.installFormatters(registry); // Register application converters and formatters } static class PublisherConverter implements Converter&lt;Publisher, String&gt; { public String convert(Publisher publisher) { if (publisher.getId().intValue() == 0) { return "-- Not Selected --"; } return new StringBuilder().append(publisher.toString()); } } </code></pre> <p>By changing the converter, you can see <code>-- Not Selected --</code> on the first item. When the form is submitted to the controller, you just need to add code to identify if an empty publisher is selected and make adjustment to suit your logic. I believe that's about it.</p> <p>You can leave the publisher drop down box as <code>required = "true"</code> and it will still work.</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.
    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