You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Randy Simon <ra...@hotmail.com> on 2006/03/07 20:17:46 UTC
Problem using preserveDataModel="true"
I'm sure I am doing something wrong, but I can't figure out what it is. I
have the following:
<h:form>
<h:commandButton action="#{dataSourceEditor.newProperty}"
value="New Property" />
<p></p>
<t:dataTable value="#{dataSourceEditor.dataModel}"
preserveDataModel="true"
var="property" border="1">
<h:column>
<h:inputText value="#{property.name}" />
</h:column>
<h:column>
<h:outputText value="#{property.type}" />
<h:inputHidden value="#{property.type}" />
</h:column>
</t:dataTable>
</h:form>
My dataSourceEditor bean is in request scope and has the following methods.
public DataModel getDataModel() {
if (dataModel == null) {
dataModel = new ListDataModel();
}
dataModel.setWrappedData(properties);
return dataModel;
}
public void setDataModel(DataModel dm) {
dataModel = dm;
}
public String newProperty() {
DSProperty property = new DSProperty();
property.setName("new property");
property.setType(Property.LONG);
if (dataModel != null) {
properties = (List) dataModel.getWrappedData();
}
if (properties == null) {
properties = new ArrayList();
}
properties.add(property);
return null;
}
When I click the "new property" button I would expect my "setDataModel"
method to be called then the "newProperty" method to be called where I add a
new property to the list. However, when I click on the "new property"
button I get the following class cast exception.
java.lang.ClassCastException: javax.faces.model.ListDataModel
at
org.apache.myfaces.component.html.ext.HtmlDataTable.updateModelFromPreservedDataModel(HtmlDataTable.java:254)
at
org.apache.myfaces.component.html.ext.HtmlDataTable.processUpdates(HtmlDataTable.java:240)
at javax.faces.component.UIForm.processUpdates(UIForm.java:196)
at
javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:927)
at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:363)
at
com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:81)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at
weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225)
at
weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127)
at
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:272)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at
org.apache.beehive.netui.pageflow.PageFlowPageFilter.runPage(PageFlowPageFilter.java:299)
at
org.apache.beehive.netui.pageflow.PageFlowPageFilter.doFilter(PageFlowPageFilter.java:214)
at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at
org.apache.shale.faces.ShaleApplicationFilter.doFilter(ShaleApplicationFilter.java:285)
at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at
com.bea.p13n.servlets.PortalServletFilter.doFilter(PortalServletFilter.java:329)
at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3192)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at
weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:1984)
at
weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1891)
at
weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1318)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
I am completely stumped about why this happens. Thanks in advance for your
help.
Randy
Re: Problem using preserveDataModel="true"
Posted by Randy Simon <ra...@hotmail.com>.
Thanks Enrique, but this doesn't really seem to help me.
My guess is that the problem comes from the line
_SerializableDataModel dm = (_SerializableDataModel)getDataModel();
in
org.apache.myfaces.component.html.ext.HtmlDataTable.updateModelFromPreservedDataModel.
Does it matter that I am using the Sun RI with Tomahawk? I was hoping that
someone else ran into this same problem and could tell me how they fixed it.
Randy
>From: "Enrique Medina" <e....@gmail.com>
>Reply-To: "MyFaces Discussion" <us...@myfaces.apache.org>
>To: "MyFaces Discussion" <us...@myfaces.apache.org>
>Subject: Re: Problem using preserveDataModel="true"
>Date: Tue, 7 Mar 2006 22:50:29 +0100
>
>Maybe a look to this Wiki may help...
>
>http://wiki.apache.org/myfaces/Working_With_DataTable_And_PreserveDataModel
>
>On 3/7/06, Randy Simon <ra...@hotmail.com> wrote:
> >
> > I'm sure I am doing something wrong, but I can't figure out what it is.
>I
> > have the following:
> >
> > <h:form>
> > <h:commandButton action="#{dataSourceEditor.newProperty}"
> > value="New Property" />
> > <p></p>
> > <t:dataTable value="#{dataSourceEditor.dataModel}"
> > preserveDataModel="true"
> > var="property" border="1">
> > <h:column>
> > <h:inputText value="#{property.name}" />
> > </h:column>
> > <h:column>
> > <h:outputText value="#{property.type}" />
> > <h:inputHidden value="#{property.type}" />
> > </h:column>
> > </t:dataTable>
> > </h:form>
> >
> > My dataSourceEditor bean is in request scope and has the following
> > methods.
> >
> > public DataModel getDataModel() {
> > if (dataModel == null) {
> > dataModel = new ListDataModel();
> > }
> >
> > dataModel.setWrappedData(properties);
> >
> > return dataModel;
> > }
> >
> >
> > public void setDataModel(DataModel dm) {
> > dataModel = dm;
> > }
> >
> > public String newProperty() {
> > DSProperty property = new DSProperty();
> > property.setName("new property");
> > property.setType(Property.LONG);
> >
> > if (dataModel != null) {
> > properties = (List) dataModel.getWrappedData();
> > }
> >
> > if (properties == null) {
> > properties = new ArrayList();
> > }
> >
> > properties.add(property);
> >
> > return null;
> > }
> >
> > When I click the "new property" button I would expect my "setDataModel"
> > method to be called then the "newProperty" method to be called where I
>add
> > a
> > new property to the list. However, when I click on the "new property"
> > button I get the following class cast exception.
> >
> > java.lang.ClassCastException: javax.faces.model.ListDataModel
> > at
> >
> >
>org.apache.myfaces.component.html.ext.HtmlDataTable.updateModelFromPreservedDataModel
> > (HtmlDataTable.java:254)
> > at
> > org.apache.myfaces.component.html.ext.HtmlDataTable.processUpdates(
> > HtmlDataTable.java:240)
> > at javax.faces.component.UIForm.processUpdates(UIForm.java:196)
> > at
> >
>javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java
> > :927)
> > at
>javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java
> > :363)
> > at
> > com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(
> > UpdateModelValuesPhase.java:81)
> > at
>com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java
> > :200)
> > at com.sun.faces.lifecycle.LifecycleImpl.execute(
> > LifecycleImpl.java:90)
> > at
>javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
> > at
> > weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(
> > StubSecurityHelper.java:225)
> > at
> > weblogic.servlet.internal.StubSecurityHelper.invokeServlet(
> > StubSecurityHelper.java:127)
> > at
> > weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java
> > :272)
> > at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java
> > :26)
> > at
> > weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java
> > :42)
> > at
> > org.apache.beehive.netui.pageflow.PageFlowPageFilter.runPage(
> > PageFlowPageFilter.java:299)
> > at
> > org.apache.beehive.netui.pageflow.PageFlowPageFilter.doFilter(
> > PageFlowPageFilter.java:214)
> > at
> > weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java
> > :42)
> > at
> > org.apache.shale.faces.ShaleApplicationFilter.doFilter(
> > ShaleApplicationFilter.java:285)
> > at
> > weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java
> > :42)
> > at
> > com.bea.p13n.servlets.PortalServletFilter.doFilter(
> > PortalServletFilter.java:329)
> > at
> > weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java
> > :42)
> > at
> >
>weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run
> > (WebAppServletContext.java:3192)
> > at
> > weblogic.security.acl.internal.AuthenticatedSubject.doAs(
> > AuthenticatedSubject.java:321)
> > at
> >
>weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
> > at
> > weblogic.servlet.internal.WebAppServletContext.securedExecute(
> > WebAppServletContext.java:1984)
> > at
> > weblogic.servlet.internal.WebAppServletContext.execute(
> > WebAppServletContext.java:1891)
> > at
> > weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java
> > :1318)
> > at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
> > at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
> >
> > I am completely stumped about why this happens. Thanks in advance for
> > your
> > help.
> >
> > Randy
> >
> >
> >
Re: Problem using preserveDataModel="true"
Posted by Enrique Medina <e....@gmail.com>.
Maybe a look to this Wiki may help...
http://wiki.apache.org/myfaces/Working_With_DataTable_And_PreserveDataModel
On 3/7/06, Randy Simon <ra...@hotmail.com> wrote:
>
> I'm sure I am doing something wrong, but I can't figure out what it is. I
> have the following:
>
> <h:form>
> <h:commandButton action="#{dataSourceEditor.newProperty}"
> value="New Property" />
> <p></p>
> <t:dataTable value="#{dataSourceEditor.dataModel}"
> preserveDataModel="true"
> var="property" border="1">
> <h:column>
> <h:inputText value="#{property.name}" />
> </h:column>
> <h:column>
> <h:outputText value="#{property.type}" />
> <h:inputHidden value="#{property.type}" />
> </h:column>
> </t:dataTable>
> </h:form>
>
> My dataSourceEditor bean is in request scope and has the following
> methods.
>
> public DataModel getDataModel() {
> if (dataModel == null) {
> dataModel = new ListDataModel();
> }
>
> dataModel.setWrappedData(properties);
>
> return dataModel;
> }
>
>
> public void setDataModel(DataModel dm) {
> dataModel = dm;
> }
>
> public String newProperty() {
> DSProperty property = new DSProperty();
> property.setName("new property");
> property.setType(Property.LONG);
>
> if (dataModel != null) {
> properties = (List) dataModel.getWrappedData();
> }
>
> if (properties == null) {
> properties = new ArrayList();
> }
>
> properties.add(property);
>
> return null;
> }
>
> When I click the "new property" button I would expect my "setDataModel"
> method to be called then the "newProperty" method to be called where I add
> a
> new property to the list. However, when I click on the "new property"
> button I get the following class cast exception.
>
> java.lang.ClassCastException: javax.faces.model.ListDataModel
> at
>
> org.apache.myfaces.component.html.ext.HtmlDataTable.updateModelFromPreservedDataModel
> (HtmlDataTable.java:254)
> at
> org.apache.myfaces.component.html.ext.HtmlDataTable.processUpdates(
> HtmlDataTable.java:240)
> at javax.faces.component.UIForm.processUpdates(UIForm.java:196)
> at
> javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java
> :927)
> at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java
> :363)
> at
> com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(
> UpdateModelValuesPhase.java:81)
> at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java
> :200)
> at com.sun.faces.lifecycle.LifecycleImpl.execute(
> LifecycleImpl.java:90)
> at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
> at
> weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(
> StubSecurityHelper.java:225)
> at
> weblogic.servlet.internal.StubSecurityHelper.invokeServlet(
> StubSecurityHelper.java:127)
> at
> weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java
> :272)
> at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java
> :26)
> at
> weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java
> :42)
> at
> org.apache.beehive.netui.pageflow.PageFlowPageFilter.runPage(
> PageFlowPageFilter.java:299)
> at
> org.apache.beehive.netui.pageflow.PageFlowPageFilter.doFilter(
> PageFlowPageFilter.java:214)
> at
> weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java
> :42)
> at
> org.apache.shale.faces.ShaleApplicationFilter.doFilter(
> ShaleApplicationFilter.java:285)
> at
> weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java
> :42)
> at
> com.bea.p13n.servlets.PortalServletFilter.doFilter(
> PortalServletFilter.java:329)
> at
> weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java
> :42)
> at
> weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run
> (WebAppServletContext.java:3192)
> at
> weblogic.security.acl.internal.AuthenticatedSubject.doAs(
> AuthenticatedSubject.java:321)
> at
> weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
> at
> weblogic.servlet.internal.WebAppServletContext.securedExecute(
> WebAppServletContext.java:1984)
> at
> weblogic.servlet.internal.WebAppServletContext.execute(
> WebAppServletContext.java:1891)
> at
> weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java
> :1318)
> at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
> at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
>
> I am completely stumped about why this happens. Thanks in advance for
> your
> help.
>
> Randy
>
>
>
RE: Problem using preserveDataModel="true"
Posted by Yee CN <ye...@streamyx.com>.
I have been puzzling over preserveDataModel attribute as well.
Below is my current understanding:
If preserveDataModel="false"
- Tomahawk will call getDataModel() during the APPLY_REQUEST_VALUES phase.
This will create a fresh copy of the dataModel (assuming your bean is in
request scope).
- It will call getDataModel() again during the RENDER_RESPONSE phase. This
will reuse the dataModel created above.
If preserveDataModel="true"
- Tomahawk will NOT call getDataModel() during the APPLY_REQUEST_VALUES
phase. However it will NOT call setDataModel() as well. It seems to work
with an internally saved copy of the dataModel.
- Therefore your program code will NOT receive a 'saved' version of the
dataModel.
- Tomahawk will call getDataModel() during RENDER_RESPONSE phase. This will
cause your program to generate a fresh copy of the dataModel.
I have to say - I spend many hours on and off trying to understand this
beast. Such is my understanding at present. I hope it will help you to track
down your problem.
Regards,
Yee
-----Original Message-----
From: Randy Simon [mailto:randy_simon@hotmail.com]
Sent: Wednesday, 8 March 2006 3:18 AM
To: users@myfaces.apache.org
Subject: Problem using preserveDataModel="true"
I'm sure I am doing something wrong, but I can't figure out what it is. I
have the following:
<h:form>
<h:commandButton action="#{dataSourceEditor.newProperty}"
value="New Property" />
<p></p>
<t:dataTable value="#{dataSourceEditor.dataModel}"
preserveDataModel="true"
var="property" border="1">
<h:column>
<h:inputText value="#{property.name}" />
</h:column>
<h:column>
<h:outputText value="#{property.type}" />
<h:inputHidden value="#{property.type}" />
</h:column>
</t:dataTable>
</h:form>
My dataSourceEditor bean is in request scope and has the following methods.
public DataModel getDataModel() {
if (dataModel == null) {
dataModel = new ListDataModel();
}
dataModel.setWrappedData(properties);
return dataModel;
}
public void setDataModel(DataModel dm) {
dataModel = dm;
}
public String newProperty() {
DSProperty property = new DSProperty();
property.setName("new property");
property.setType(Property.LONG);
if (dataModel != null) {
properties = (List) dataModel.getWrappedData();
}
if (properties == null) {
properties = new ArrayList();
}
properties.add(property);
return null;
}
When I click the "new property" button I would expect my "setDataModel"
method to be called then the "newProperty" method to be called where I add a
new property to the list. However, when I click on the "new property"
button I get the following class cast exception.
java.lang.ClassCastException: javax.faces.model.ListDataModel
at
org.apache.myfaces.component.html.ext.HtmlDataTable.updateModelFromPreserved
DataModel(HtmlDataTable.java:254)
at
org.apache.myfaces.component.html.ext.HtmlDataTable.processUpdates(HtmlDataT
able.java:240)
at javax.faces.component.UIForm.processUpdates(UIForm.java:196)
at
javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:92
7)
at
javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:363)
at
com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhas
e.java:81)
at
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at
weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSe
curityHelper.java:225)
at
weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelpe
r.java:127)
at
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:272)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at
org.apache.beehive.netui.pageflow.PageFlowPageFilter.runPage(PageFlowPageFil
ter.java:299)
at
org.apache.beehive.netui.pageflow.PageFlowPageFilter.doFilter(PageFlowPageFi
lter.java:214)
at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at
org.apache.shale.faces.ShaleApplicationFilter.doFilter(ShaleApplicationFilte
r.java:285)
at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at
com.bea.p13n.servlets.PortalServletFilter.doFilter(PortalServletFilter.java:
329)
at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(W
ebAppServletContext.java:3192)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubjec
t.java:321)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at
weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletC
ontext.java:1984)
at
weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.
java:1891)
at
weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:131
8)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
I am completely stumped about why this happens. Thanks in advance for your
help.
Randy