官术网_书友最值得收藏!

Time for action – fixing the OptionGroup example

It's time for our good deed of the day. OptionGroup has a very simple method to turn on a multiple selection mode: setMultiSelect.

  1. Open or import the optiongroup example in your IDE.
  2. Add og.setMultiSelect(true) after instantiating og.
  3. Deploy and run the example.

What just happened?

Take a look at the new interface:

As you can see, now the component is displayed as an assortment of checkboxes and the getValue method (of both OptionGroup and Property) returns a Java Collection (actually a Set). This happens when we activate multiselect mode.

Note

We are not talking about Java EE, but just in case, the correct answers are:

Session beans and Message-driven beans

Have a go hero – improve the OptionGroup example

Try changing the OptionGroup example application to show a message informing whether the answer is correct or not. Here is a quick hint: cast the value to a Java Set instance.

Twin column selects

Instead of the OptionGroup component we can use TwinColSelect. We can change OptionGroup for TwinColSelect in the previous example:

TwinColSelect og = new TwinColSelect(
    "Two kinds of EJBs in Java EE are:", answers);

With this, we get an interesting component for selection:

.

Date/time pickers

Vaadin includes a nice date/time picker with multiple configuration options. You can add a date picker using this:

DateField dateField = new DateField("Select a date");

This will display a field to directly type the date and a button to open a convenient calendar:

The getValue method of DateField returns a java.util.Date object. You can configure the resolution of DateField. For example, to allow users select only a year, we can do this:

dateField.setResolution(Resolution.YEAR);

This will show a more restrictive component:

Note

Resolution is a Java enum that includes the YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND values to use in your date pickers.

A date format can be specified using the setDateFormat method:

dateField.setDateFormat("yyyy-MM-dd");
Note

yyyy-MM-dd is the date format for the ISO 8601 standard.

Note

If you want to display the entire calendar selector (instead of the input field with the button to open a calendar) use InlineDateField.

主站蜘蛛池模板: 章丘市| 来安县| 西吉县| 遂平县| 格尔木市| 沽源县| 化德县| 二连浩特市| 十堰市| 朝阳县| 龙江县| 牡丹江市| 雅安市| 增城市| 沅江市| 青岛市| 广水市| 堆龙德庆县| 望都县| 江西省| 陆河县| 肇源县| 玉树县| 沙坪坝区| 武功县| 淮南市| 西宁市| 鹤峰县| 景泰县| 郓城县| 波密县| 涿鹿县| 兴国县| 墨玉县| 和平区| 上思县| 临湘市| 南京市| 卓资县| 兴海县| 响水县|