The value change event will be fired if the converted value does not
equal the current value. So therefore, in your example, if you have a
converter that converts "" to null, and your current value is null,
there will be no event.

On 7/6/07, vlad10 <[EMAIL PROTECTED]> wrote:

I'm fresh with JSF,
just started building some prototypes with facelets 1.1.11, myfaces
1.1.3/tomahawk 1.1.3.

I'm getting this general feeling that the framework is missing some
important feature.
I may create an inputText and populate it with a null value, the framework
conviniently will convert it into an empty string and populate my page.
However, on submit the valueChangeListener will fire with the reason that
null is not the same as an empty string.
I have another example. This the initial value is not null. I may explicitly
add a converter to that field, so the value stored in POJO as jva.util.Date
or as a BigDecimal or anything else will be nicely displayed on the screen,
but I'll face again the unwanted behavior of my valueChangeListener.
For the time being, I'm trying to compensate this deficiency in my app by
adding some filtering in a utility class. At the moment it's in the
beginning, just checking null/empty string case:

    /**
     * UIInput value is never null when submitted, but the POJO is always
     * initialized with nulls. This creates a false alarm by
valueChangeListeners.
     * This method tries to compensate this deficiency.
     * @param input
     * @param rec
     * @return
     */
    public static boolean isValueChanged(UIInput input, Object pojo) {
        String name = input.getId();
        Object val = BeanUtil.getBeanValue(pojo,name);
        if (val == null)
            if(StringUtils.isEmpty(input.getValue().toString()))
                return false;
            else
                return true;
        return (input.getValue().toString().compareTo(val.toString()) != 0);
    }

My question: am I missing something????
Do I really need to add another layer in my app, I may call it something
like JSF Frendly POJOs. I may perform all necessary conversions right there
when moving data from DB to the screen, and then on submit perform the
opposit conversion when moving data back. I hope I can avoid that.
Is not it possible for a framework to 'remember' not just an oldValue, but
also the conversion performed, so prior to comparing old/new values it would
apply that same converter to the old value???
I think, this part has been missed.

thanks
vlad
--
View this message in context: 
http://www.nabble.com/ValueChangeListener-challenges-tf4037711.html#a11471319
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Reply via email to