You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Roman Kalukiewicz (JIRA)" <de...@myfaces.apache.org> on 2006/06/10 22:04:29 UTC

[jira] Created: (TOMAHAWK-486) preserveDataModel cannot work if dataTable connected to array property

preserveDataModel cannot work if dataTable connected to array property
----------------------------------------------------------------------

         Key: TOMAHAWK-486
         URL: http://issues.apache.org/jira/browse/TOMAHAWK-486
     Project: MyFaces Tomahawk
        Type: Bug

  Components: Extended Datatable  
    Versions: 1.1.1    
    Reporter: Roman Kalukiewicz


If there is preserveDataModel="true" then if dataTable is connected to array property then i have:
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
javax.faces.el.EvaluationException: Cannot set value for expression '#{creditsBean.credits}' to a new value of type [Ljava.lang.Object;
	at org.apache.myfaces.el.ValueBindingImpl.setValue(ValueBindingImpl.java:304)
	at org.apache.myfaces.component.html.ext.HtmlDataTable.updateModelFromPreservedDataModel(HtmlDataTable.java:269)
	at org.apache.myfaces.component.html.ext.HtmlDataTable.processUpdates(HtmlDataTable.java:242)
	at javax.faces.component.UIForm.processUpdates(UIForm.java:85)
	at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:428)
	at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:428)
	at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:153)
	at org.apache.myfaces.lifecycle.LifecycleImpl.updateModelValues(LifecycleImpl.java:277)
	at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:81)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
	at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
	at java.lang.Thread.run(Thread.java:595)
Caused by: javax.faces.el.EvaluationException: pl.mobiltek.rmobile2.web.beans.CreditsBean
	at org.apache.myfaces.el.PropertyResolverImpl.setValue(PropertyResolverImpl.java:155)
	at org.apache.myfaces.el.ValueBindingImpl.setValue(ValueBindingImpl.java:269)
	... 26 more
Caused by: javax.faces.el.EvaluationException: Bean: pl.mobiltek.rmobile2.web.beans.CreditsBean, property: credits
	at org.apache.myfaces.el.PropertyResolverImpl.setProperty(PropertyResolverImpl.java:372)
	at org.apache.myfaces.el.PropertyResolverImpl.setValue(PropertyResolverImpl.java:148)
	... 27 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.apache.myfaces.el.PropertyResolverImpl.setProperty(PropertyResolverImpl.java:368)
	... 28 more

The reason is in HtmlDataTable class in at org.apache.myfaces.component.html.ext.HtmlDataTable.updateModelFromPreservedDataModel at line 269 where you try to call valueBinding.setValue with newly created Object[].

<cite>
List lst = (List) dm.getWrappedData();
vb.setValue(context, lst.toArray(new Object[lst.size()]));
</cite>

If you want to preserve model of property with type Foo[] then you cannot call setValue with Object[] - you should do it with Foo[].

Simlpe example of problem can be show here - it shows that it's no allowed to do such things you do

public class Test {

    public static void main(String[] args) throws Exception {
        Method m = Test.class.getMethod("test", new Class[] {Test[].class});
        Object[] params = new Object[1];
        params[0] = new Object[0]; // here problem lies - should be 'Test[0]'
        m.invoke(new Test(), params);
    }
    
    public void test(Test[] param) {
        
    }
}

Maybe there should be new field in org.apache.myfaces.component.html.ext._SerializableArrayDataModel describing base class of serialized array. It can be used this way:

List lst = (List) dm.getWrappedData();
Class clazz = dm.getContainedClass();
Object[] array = Array.newInstance(clazz, lst.size());
vb.setValue(context, lst.toArray(array);

-- 
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