myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Iov (JIRA)" <...@myfaces.apache.org>
Subject [jira] Created: (MYFACES-1532) Custom converter consequently ignored
Date Tue, 13 Feb 2007 22:08:05 GMT
Custom converter consequently ignored
-------------------------------------

                 Key: MYFACES-1532
                 URL: https://issues.apache.org/jira/browse/MYFACES-1532
             Project: MyFaces Core
          Issue Type: Bug
          Components: General
    Affects Versions: 1.1.4, 1.1.5-SNAPSHOT
         Environment: MyFaces + Facelet + Ajax4JSF
            Reporter: Paul Iov


The way how the custom converters are handled in current code is totally incosistent!
This issue can be splited into two parts:

1. Initial rendering of component, which provides custom converter don't check this, but just
throws an exception: "Expected submitted value of type ... for Component:...", if the type
of bound bean property dosn't match expected type. (i.e. h:selectBooleanCheckbox can't be
bound to a String property, even with a custom converter, that converts a string value posted
from client to "true"/"false", "1"/"0", "yes"/"no" or whatever, because this converter is
just not called at this stage.)

Usecase
in bean:
----------------------------------------
private String strBoolean = "1";
	
public String getStrBoolean() {
	return strBoolean;
}

public void setStrBoolean(String strBoolean) {
	this.strBoolean = strBoolean;
}


converter:
---------------------------------------
public class BooleanConverter implements Converter {
	
	public Object getAsObject(FacesContext arg0, 
			                   UIComponent arg1,
			                        String newValue) throws ConverterException {
		return newValue.equalsIgnoreCase("true") ? "1" : "0";
	}

	public String getAsString(FacesContext arg0, 
			                   UIComponent arg1,
			                        Object myValue) throws ConverterException {
		return myValue.toString().equalsIgnoreCase("1") ? "true" : "false";
		//what should we return here, to make the UIBoolean happy???
		//"checked"/"" ? "on"/"" ? nothing works, because this method is
		//just not called!
	}

}

in xhtml:
------------------------------------
<h:selectBooleanCheckbox value="#{MyBean.strBoolean}"
				converter="MyBooleanConverter"/>


causes:
----------------------------------
Expected submitted value of type Boolean for Component :...

Side note: if property in bean is initialized to null, all works great without any warning
and the initial state of component's value becomes false!

Well, t:inputCalendar implements own converter handling and it works great, if some valid
string is posted from client, but it's not possible to set initial value of component in bean,
i.e.

private String strDate = "01.01.2006";

The initial 'rendered' state of component is always an empty string.



2. The second one should be probably the JSF Specification issue, but somehow is also converter
related... AJAX compatybility. I've discovered some strange behaviour by using ajaxSingle
feature from A4J. If a component's value is not present in request (ajaxSingle approach),
it becomes null during 'Apply request values' phase regardless of custom converter (which
tries to catch this situation in getAsObject() method). The warning "There should always be
a submitted value..." is correct, but why should the framework not try to let custom converter
deal with this situation, if it's provided?

regards,
paul

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message