0

Converter with parameter

asked 2009-12-16 11:03:21 +0800

haddorp gravatar image haddorp
81 2 3

How to parse additional parameters to a converter attribute? Per default a new TypeConverter instance is created.

Is it possible to call the method coerceToUi with further parameters or is it possible to use a pre-instantiated class?

What is the optimal approach for this requirement?

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2009-12-17 18:10:22 +0800

robertpic71 gravatar image robertpic71
1275 1

First, there is no way to extend the TypeConverter directly.

Here are my work-a-rounds:

1. use the object instead of the object.attribute
my real world example:
It want to show "customer.sales" but the sales should have another colour when the is > 10 % higher than the last years sales.
The get the whole information i need the customer so i use

<rows>
   <row self="@{each=customer}">
        <label value="@{customer.number}"/>
         ..
         <label value="@{customer, converter='com.at.od.converters.sales'}"/>
         ...

Now i get the customer inside my TypeConverter and have no problem to evaluate the color.

2. use custom-attributes to communicate with the TypeConverter
See this side for some examples with "static" parameters.

I should be possible to setup i.e. a converterprogram in the attribute.
<label value="@{customer, converter='com.at.od.converters.spring'}">
<custom-attributes convert="${springconverter}"/></label>
I've not tested this, but it should work.

Note that the timing for all kinds of listbinding (listbox, rows, combobox...) is important. The single-row/item is used as template for the databinding.
If you need the attribute in all items you have to set this before the binder renders and copy the template.

3. use databinding for custom-attributes
Since ZK 5RC it is possible to use databinding for custom-attributus. So you could pass all your parameters inside custom-attributes and the last one render the item.

/Robert

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-12-16 11:03:21 +0800

Seen: 847 times

Last updated: Dec 17 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More