Bastian Voigt
Bastian Voigt

Reputation: 5671

Why does Tapestry's select component not show my selected value when the option strings contain line breaks?

In my application I use a List<String> as model for a select box. Each of the option strings contains a line break at the end.

The options are displayed fine, but it seems that Tapestry strips the line breaks before rendering the options, and then on submit it is unable to match the stripped string against the list of options, which still contains the line breaks.

For this reason my select box always comes up with the blank option selected, although the property already has a non-null value.

Upvotes: 0

Views: 2016

Answers (1)

lance-java
lance-java

Reputation: 27994

You have not provided a model parameter so tapestry has no way of knowing the available values. The model must be a SelectModel instance. There's a few options for creating a SelectModel.

  1. Provide a comma separated String and let tapestry's TypeCoercer create an appropriate SelectModel.
  2. Provide a java.util.List and let tapestry's TypeCoercer create an appropriate SelectModel.
  3. Provide a java.util.Map and let tapestry's TypeCoercer create an appropriate SelectModel.
  4. @Inject SelectModelFactory and invoke create(List<?> objects, String labelProperty) to create a SelectModel from a List using a bean property as the label for each.
  5. Create a custom SelectModel yourself.

http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/corelib/components/Select.html http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/SelectModel.html http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/services/SelectModelFactory.html http://tapestry.apache.org/typecoercer-service.html

Upvotes: 1

Related Questions