You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jose Gonzalez Gomez <jg...@opentechnet.com> on 2004/11/05 19:00:48 UTC

Direction of parameters [was: Totally lost with ClassCastException problem]

    Ok, using the in direction for the parameter seems to solve this 
issue... but I still have some doubts: let's say I have the following:

objectA:ClassA
     |--propertyA
     |--propertyB
     |--propertyC:ClassB
                |--propertyD
                |--propertyE

and the following Tapestry components:

Page
 |--@Form
      |--@TextField (objectA.propertyA)
      |--@TextField (objectA.propertyA)
      |--@MyCustomComponent (parameter -> objectA.propertyC)  (**)
                        |--@TextField (parameter.propertyD)
                        |--@TextField (parameter.propertyE)


    It's clear for me that if I have a component that modifies a "leaf" 
property, as propertyD, its parameter should have the form direction, as 
it's the case of TextField. But what happens with intermediate 
components, as MyCustomComponent (**)? My first thought was that I 
should also use the form direction, as MyCustomComponent, in some sense, 
edits the objectA.propertyC property. But it seems I was wrong. I guess 
that in order to use the form direction, the component should provide a 
new object from the data introduced in the embedded fields so Tapestry 
can assign this new object to objectA.propertyC, am I right?

    So if I only want to edit properties of objectA.propertyC, but not 
objectA.propertyC itself, I must use the in direction... but wouldn't 
that lead to misunderstanding the component? I mean, somebody looking at 
the component specification could think that this component just renders 
the property, instead of editing the nested properties...

    Best regards
    Jose


-------- Original Message --------
Subject: 	Totally lost with ClassCastException problem
Date: 	Fri, 05 Nov 2004 18:11:20 +0100
From: 	Jose Gonzalez Gomez <jg...@opentechnet.com>
Reply-To: 	Tapestry users <ta...@jakarta.apache.org>
To: 	Tapestry users <ta...@jakarta.apache.org>



   Hi there,

   I'm getting a ClassCastException in a point of my Tapestry 
application and I cannot find the root of the problem. I have simplified 
the problem as much as I can, but I still don't see the solution... here 
you have the clues:

   I have two classes (Organization -> PostalAddress) and a form to 
edit the Organization data. As PostalAddress will be used in other 
classes/forms I have extracted the fields of PostalAddress into a 
component with a single parameter, the PostalAddress to edit. Whenever 
my form is shown, either empty or with a selected Organization, 
everything is fine (I create an empty Organization with an empty 
PostalAddress in pageBeginRender in case there is no Organization 
selected). But whenever I submit the form I get a ClassCastException. 
Once I got the error, I took out almost everything but the problematic 
things.

Stack trace of the exception as shown by Tapestry:
An exception has occurred.

You may continue by *restarting 
<http://localhost:8080/interbanca/restart.do>* the session.

org.apache.tapestry.ApplicationRuntimeException

component: 
com.houndline.interbanca.web.admin.OrganizacionPage$Enhance_0@7b9a29[admin/organizacion/organizacion] 

location: 
context:/WEB-INF/espec-paginas/admin/organizacion/Organizacion.page, 
line 19, column 81

java.lang.ClassCastException

Stack Trace:

   * org.apache.tapestry.param.AbstractParameterConnector.resetParameter(AbstractParameterConnector.java:148)

   * org.apache.tapestry.param.ParameterManager.resetParameters(ParameterManager.java:124)

   * org.apache.tapestry.AbstractComponent.cleanupAfterRender(AbstractComponent.java:932)

   * org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:863)

   * org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)

   * org.apache.tapestry.form.Form.renderComponent(Form.java:362)
   * org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)

   * org.apache.tapestry.form.Form.rewind(Form.java:568)
   * org.apache.tapestry.engine.RequestCycle.rewindForm(RequestCycle.java:435)

   * org.apache.tapestry.form.Form.trigger(Form.java:582)
   * org.apache.tapestry.engine.DirectService.service(DirectService.java:169)

   * org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:872)

   * org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java:197)

   * org.apache.tapestry.ApplicationServlet.doPost(ApplicationServlet.java:326)
   * [...]



   From Organization.page:

<property-specification name="selectedOrganization" 
type="[fullPackageName].Organization"/>
<component id="postalAddress" type="PostalAddress">
   <binding name="postalAddress" 
expression="selectedOrganization.postalAddress"/>
</component>

   From PostalAddress.jwc (I have commented out all embedded components 
while testing, and with only this I get the error):

<component-specification class="org.apache.tapestry.BaseComponent" 
allow-body="no" allow-informal-parameters="no">
   <parameter name="postalAddress" direction="form" 
type="[fullPackageName].PostalAddress" required="yes"/>
</component-specification>

   From OrganizationPage.java:

 public void pageBeginRender( PageEvent arg0 )
   {
   if( this.getSelectedOrganization( ) == null )
     {
     this.setSelectedOrganization( new Organization( ) );
     }
   }

   From Organization.java:

 private PostalAddress postalAddress  = new PostalAddress( );


   Any help would be greatly appreciated... the only thing I doubt 
about it is the direction of the parameter... should this be form?

   Thanks in advance, best regards
   Jose

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Direction of parameters [was: Totally lost with ClassCastException problem]

Posted by "Filip S. Adamsen" <fi...@stubkjaer-adamsen.dk>.
Your @MyCustomComponent will IIRC have to use the direction form, as it 
is still editing a property. You might get subtle errors if you don't. 
(Someone, please correct me if I'm wrong here.)

I can't wait for Tapestry 3.1 - no parameter direction anymore!

-Filip

Jose Gonzalez Gomez wrote:
> 
>    Ok, using the in direction for the parameter seems to solve this 
> issue... but I still have some doubts: let's say I have the following:
> 
> objectA:ClassA
>     |--propertyA
>     |--propertyB
>     |--propertyC:ClassB
>                |--propertyD
>                |--propertyE
> 
> and the following Tapestry components:
> 
> Page
> |--@Form
>      |--@TextField (objectA.propertyA)
>      |--@TextField (objectA.propertyA)
>      |--@MyCustomComponent (parameter -> objectA.propertyC)  (**)
>                        |--@TextField (parameter.propertyD)
>                        |--@TextField (parameter.propertyE)
> 
> 
>    It's clear for me that if I have a component that modifies a "leaf" 
> property, as propertyD, its parameter should have the form direction, as 
> it's the case of TextField. But what happens with intermediate 
> components, as MyCustomComponent (**)? My first thought was that I 
> should also use the form direction, as MyCustomComponent, in some sense, 
> edits the objectA.propertyC property. But it seems I was wrong. I guess 
> that in order to use the form direction, the component should provide a 
> new object from the data introduced in the embedded fields so Tapestry 
> can assign this new object to objectA.propertyC, am I right?
> 
>    So if I only want to edit properties of objectA.propertyC, but not 
> objectA.propertyC itself, I must use the in direction... but wouldn't 
> that lead to misunderstanding the component? I mean, somebody looking at 
> the component specification could think that this component just renders 
> the property, instead of editing the nested properties...
> 
>    Best regards
>    Jose