<t:inputHtml doesn't work when using it with Custom Object that encapsulates a String value
-------------------------------------------------------------------------------------------
Key: MYFACES-786
URL: http://issues.apache.org/jira/browse/MYFACES-786
Project: MyFaces
Type: Bug
Versions: 1.1.0
Environment: Windows XP Professional, j2sdk1.4.2_09, Tomcat 4.1.30
Reporter: Javier Alperte
The t:inputHtml crash (with a ClassCastException) in method
"public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException"
when you try to use a custom converter and a custom value object as a bind value with the component.
I we look inside the method be find the next sentences:
RendererUtils.checkParamValidity(facesContext, uiComponent, InputHtml.class);
InputHtml editor = (InputHtml) uiComponent;
String submittedDocument = (String) RendererUtils.getConvertedUIOutputValue(facesContext, editor, submittedValue);
return editor.getValueFromDocument( submittedDocument );
I think that the problem is that you are always expecting a String value as the result of getConvertedUIOutputValue, when other types could be returned, for example a Custom Type object.
I think that if we change the order of the two last lines, the code will run ok. The result could be something like:
String submittedDocument = editor.getValueFromDocument( (String) submittedValue );
return RendererUtils.getConvertedUIOutputValue(facesContext, editor, submittedDocument);
Let me explain better with an example:
If you define a Custom Class "MyHtmlValue" like:
public class MyHtmlValue {
private String value;
public String getValue() { blablabla.... }
public void setValue(String value) { blablabla.... }
}
and you also define your converter like:
public class MyHtmlValueConverter implements Converter {
public Object getAsObject(FacesContext context, UIComponent component, String value) throws
ConverterException {
MyHtmlValue strVal = new MyHtmlValue();
strVal.setValue(value);
return strVal;
}
public String getAsString(FacesContext context, UIComponent component, Object value) throws
ConverterException {
return value == null ? "" : ((MyHtmlValue) value).getValue();
}
}
the component will crash when you do something like:
<t:inputHtml id="longTextField" binding="#{myBean.myHtmlValue}" required="false"
converter="myHtmlValueConverter"/>
because the component is expecting an object of type "String" as a result of "RendererUtils.getConvertedUIOutputValue", when an object of type "MyHtmlValue" is returned
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
[jira] Closed: (MYFACES-786)
Posted by "Bruno Aranda (JIRA)" <de...@myfaces.apache.org>.
[ http://issues.apache.org/jira/browse/MYFACES-786?page=all ]
Bruno Aranda closed MYFACES-786:
--------------------------------
Fix Version: Nightly
Resolution: Fixed
This has been fixed in the SVN (r331260) and it will be available in the next nightly build. Thanks Javier!
> <t:inputHtml doesn't work when using it with Custom Object that encapsulates a String value
> -------------------------------------------------------------------------------------------
>
> Key: MYFACES-786
> URL: http://issues.apache.org/jira/browse/MYFACES-786
> Project: MyFaces
> Type: Bug
> Versions: 1.1.0
> Environment: Windows XP Professional, j2sdk1.4.2_09, Tomcat 4.1.30
> Reporter: Javier Alperte
> Fix For: Nightly
>
> The t:inputHtml crash (with a ClassCastException) in method
> "public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException"
> when you try to use a custom converter and a custom value object as a bind value with the component.
> I we look inside the method be find the next sentences:
> RendererUtils.checkParamValidity(facesContext, uiComponent, InputHtml.class);
> InputHtml editor = (InputHtml) uiComponent;
> String submittedDocument = (String) RendererUtils.getConvertedUIOutputValue(facesContext, editor, submittedValue);
> return editor.getValueFromDocument( submittedDocument );
> I think that the problem is that you are always expecting a String value as the result of getConvertedUIOutputValue, when other types could be returned, for example a Custom Type object.
> I think that if we change the order of the two last lines, the code will run ok. The result could be something like:
> String submittedDocument = editor.getValueFromDocument( (String) submittedValue );
> return RendererUtils.getConvertedUIOutputValue(facesContext, editor, submittedDocument);
>
> Let me explain better with an example:
> If you define a Custom Class "MyHtmlValue" like:
> public class MyHtmlValue {
> private String value;
> public String getValue() { blablabla.... }
> public void setValue(String value) { blablabla.... }
> }
> and you also define your converter like:
> public class MyHtmlValueConverter implements Converter {
> public Object getAsObject(FacesContext context, UIComponent component, String value) throws
> ConverterException {
> MyHtmlValue strVal = new MyHtmlValue();
> strVal.setValue(value);
> return strVal;
> }
> public String getAsString(FacesContext context, UIComponent component, Object value) throws
> ConverterException {
> return value == null ? "" : ((MyHtmlValue) value).getValue();
> }
> }
> the component will crash when you do something like:
> <t:inputHtml id="longTextField" binding="#{myBean.myHtmlValue}" required="false"
> converter="myHtmlValueConverter"/>
> because the component is expecting an object of type "String" as a result of "RendererUtils.getConvertedUIOutputValue", when an object of type "MyHtmlValue" is returned
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira