All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.tapestry5.corelib.components.Palette.xdoc Maven / Gradle / Ivy

Go to download

Central module for Tapestry, containing interfaces to the Java Servlet API and all core services and components.

There is a newer version: 5.8.6
Show newest version

    

        

For this example, we'll implement a page from an e-commerce order wizard; the page collects information about special handling for the order:


This single screen shot doesn't capture the full richness of the user experience provided by the Palette component. The buttons enable and disable themselves based on what's selected. You can move items by double clicking, and you can move multiple items by selecting them and and then clicking the button.

This is a far better experience than using <select> with multiple enabled, as its very difficult to navigate a large list when using a traditional <select> and very easy to accidentally lose your selection. The price of this is the requirement for JavaScript on the client side.

In this contrived example, the possible types of special handling are defined using an enum. It's more likely, in the real world, that this would be defined in terms of a database entity.

Special Handling


]]>

Here we are able to omit the selected parameter (the list of selected items) because the Palette component's id matches a property of the page.

The model parameter will define the available options that can be selected. The encoder parameter will define how to translate server side values (the enum values) into client side strings and back.

handling; @Inject private Messages messages; @Property private final ValueEncoder encoder = new EnumValueEncoder(SpecialHandling.class); @Property private final SelectModel model = new EnumSelectModel(SpecialHandling.class, messages); }]]>

Tapestry has built-in public classes that help convert enum types into value encoders and select models.

Injecting a Messages object gives a component access to its own message catalog.

The Palette component will read the handling property when rendering (it's ok for it to be null). When the form is submitted, it will create a new List and update the handling property.

The Palette can also be used to order, not just select, items, by binding the reorder parameter to true. In that case, additional buttons are added that allow selected items to be moved up or down the list.

The Palette can be further customized through a mix of CSS and by replacing the images used for its various buttons.





© 2015 - 2024 Weber Informatics LLC | Privacy Policy