-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
I'm trying to use spring instead of full class name, like this:
<radiogroup selectedItem="@{pedidoVenda.origemEstoque, converter=${origemEstoqueRadiogroupConverter}}">
But the ${} isn't evaluated and it's treated like the actual class name. Is there a way to do it?
Regards,
Felipe Cypriano
>> I'm trying to use spring instead of full class name, like this:
This is not possible with the actual ZK version. There is also posted a featurerequest.
Meanwhile use fixed converters or try the SpringUtil from ZK inside the converter.
/Robert
how do u define your bean in spring configuration file?
/robbie
So, it's time to resurrect this thread. Now I need this functionality to avoid lots of implementation that changes almost nothing, based on the unique-possible-solution given by henrichen in Input masks and data binding not working, I'll need one type for each mask I use in my app.
If it was possible to use spring bean in converters I only need to create a single class and one spring bean for each mask, something like (to simplify this is groovy/grails code):
package com.felipecypriano; class MaskFilterTypeConverter implements TypeConverter { String maskToAvoid public Object coerceToBean(java.lang.Object val, Component comp) { if (maskToAvoid.equals(val)) { TypeConverter.IGNORE } return val; } } // And the beans definition - using Grails Spring DSL, the result is the same as xml phoneMaskTypeConverter(com.felipecypriano. MaskFilterTypeConverter){ bean -> bean.maskToAvoid = "(__) ____-____" } zipCodeMaskTypeConverter(com.felipecypriano. MaskFilterTypeConverter){ bean -> bean.maskToAvoid = "_____-___" }
And in the zul file:
<textbox value="@{phoneNumber, converter=phoneMaskTypeConverter}"/> <textbox value="@{zipCode, converter=zipCodeMaskTypeConverter}"/>
Is it possible? If it's not possible what need to be done to make it possible?
Currently, the converter accepts "converter class name only"(i.e. Sorry, no spring bean).
However, you can pass extra information into the converter via data binder arguments.
In zul file:
<textbox value="@{phoneNumber, converter=com.mypackage.PhoneNumberConverter, maskToAvoid='(__) ____-____'}"/>
In your converter,
public class PhoneNumberConverter implements TypeConverter { public Object coerceToBean(java.lang.Object val, Component comp) { Map args = (Map) comp.getAttribute(DataBinder.ARGS); //get the databinder argument map if (args != null) { String maskToAvoid = (String) args.get("maskToAvoid"); //get the argument named "maskToAvoid" if (maskToAvoid != null && maskToAvoid.equals(val)) { return TypeConverter.IGNORE } return val; } ... } ... }
The only problem using arguments is that value in 'maskToAvoid' needs to be hard coded everywhere, this can easily become a maintenance nightmare.
Don't you have any tips on where to look (which classes) so I could implement this functionality?
Hi Henri,
Yes, this is what I did. I've a super class named StringFiterConverter and subclasses like PhoneMaskFilterConverter:
simple groovy code:
class StringFilterConverter implements TypeConverter { final String stringToAvoid // coerceToBean implementation } class PhoneMaskFilterConverter extends StringFilterConverter { public PhoneMasFilterConverter() { super("(__) ____-____"); } }
I don't his option is better than using spring beans, it's more expensive. But, it's all we have for now.
If your grails domain class has a property (getter and/or setter) which returns a java.util.Date the code will be the same as using a Java class.
Look at the ZK components, like Datebox.
Asked: 2009-06-02 15:37:37 +0800
Seen: 950 times
Last updated: Apr 30 '10