You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by de...@vitalassets.com on 2004/03/18 18:06:09 UTC

New user - need some component help - ClassCastException on submit

I'm a new user to tapestry. I've been working with it for a week now and we've decided to move our present servlet-based app to Tapestry. I am having trouble writing what I thought was a simple component. The component is simply a way to encompass several field types into one so that my developers can use our field component and based on the data type of the field it decides whether to show a TextField, PropertySelection, Checkbox, etc.

The page with the form code displays the components correctly, but the submit fails with a ClassCastException at org.apache.tapestry.param.AbstractParameterConnector.resetParameter. This is coming from the dynamic Enhance subclass created by Tapestry for my page that references my component.

The possible problem is the parameter in my new component is a bean. This bean uses various String objects to retrieve properties, but the submit only inputs into the String object called value. Perhaps I am supposed to create a custom binding, but it seemed that Tapestry was doing everything correctly.

The PVInput page renders just fine including making the decision on which type of field to show. The exception shows that the submit contained all the data for each field, but then it threw the Exception:

component: accolade.PVInput$Enhance_102@174d4c9[PVInput] 
location: context:/WEB-INF/PVInput.page, line 7, column 47 

java.lang.ClassCastException
Stack Trace: 
org.apache.tapestry.param.AbstractParameterConnector.resetParameter(AbstractParameterConnector.java:189) 
 
Any pointers on the correct way to create components would be great. I've spent several hours going through the old Developers guide and the newer User's guide, but I can't seem to find any examples like what I'm doing with a form parameter and no java class for the component, just the jwc and html files.

Here are the key snippets from my code:

PVInput.page:
<property-specification name="pvFieldObject" type="accolade.PVField"/>
<component id="myPvField" type="PVFieldComponent">
        <binding name="pvField" expression="pvFieldObject" />
</component>

PVInput.html:
<span jwcid="myPvField" /> (this is inside a foreach which seems to work great)

PVFieldComponent.jwc:
<component-specification class="org.apache.tapestry.BaseComponent" allow-body="yes" allow-informal-parameters="yes">
    <parameter name="pvField" type="accolade.PVField" required="yes" direction="form"/>
	<component id="pvInputLabel" type="Insert">
		<binding name="value" expression="pvField.name" />
	</component>
	<component id="pvInputField" type="TextField">
		<binding name="value" expression="pvField.value" />
	</component>
	<component id="pvSelectField" type="PropertySelection">
        <binding name="model" expression="pvField.uomValueModel" />
        <binding name="value" expression="pvField.value" />
	</component>

</component-specification>

PVFieldComponent.html:
<span jwcid="pvInputLabel" class="pvfieldlabel">Field Label</span>
<br>
<span jwcid="@Conditional" condition="ognl:pvField.lov">
      <select jwcid="pvSelectField" class="pvfield">
          <option value="sample">Sample Select Field</option>
       </select>
</span>
<span jwcid="@Conditional" condition="ognl:! pvField.lov">
      <input type="text" jwcid="pvInputField" class="pvfield" value="Sample Input Field"/>
</span>

PVField.java:
public class PVField implements Serializable {
	private String name = "";
	private String value = "";
	private String recid = "";
	private String uomType = "";
	private String defaultValue = "";
...
	public String getValue() {
		return value;
	}
	
	public void setValue(String value) {
		this.value = value;
	}
...
}


Thanks in advance,
David

--------------------------------------
David Ethell
Senior Engineer, Vital Assets, Inc.
Phone: 800.860.0607 Ex: 102
Email: dethell@vitalassets.com 
3916 Germantown Rd 
Edgewater, MD 21037 
--------------------------------------

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


Re: New user - need some component help - ClassCastException on submit

Posted by Denis Ponomarev <oz...@romsat.ua>.
> <parameter name="pvField" type="accolade.PVField" required="yes" direction="form"/>

Try direction="auto"


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


Re: New user - need some component help - ClassCastException on submit

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
I haven't thought through this in detail, but a quick suggestion - use  
contrib:FormConditional instead of Conditional.  I don't know if that  
would solve the problem or not, but maybe?  Its really the right  
conditional component to use anyway though.

	Erik

On Mar 18, 2004, at 12:06 PM, dethell@vitalassets.com wrote:

> I'm a new user to tapestry. I've been working with it for a week now  
> and we've decided to move our present servlet-based app to Tapestry. I  
> am having trouble writing what I thought was a simple component. The  
> component is simply a way to encompass several field types into one so  
> that my developers can use our field component and based on the data  
> type of the field it decides whether to show a TextField,  
> PropertySelection, Checkbox, etc.
>
> The page with the form code displays the components correctly, but the  
> submit fails with a ClassCastException at  
> org.apache.tapestry.param.AbstractParameterConnector.resetParameter.  
> This is coming from the dynamic Enhance subclass created by Tapestry  
> for my page that references my component.
>
> The possible problem is the parameter in my new component is a bean.  
> This bean uses various String objects to retrieve properties, but the  
> submit only inputs into the String object called value. Perhaps I am  
> supposed to create a custom binding, but it seemed that Tapestry was  
> doing everything correctly.
>
> The PVInput page renders just fine including making the decision on  
> which type of field to show. The exception shows that the submit  
> contained all the data for each field, but then it threw the  
> Exception:
>
> component: accolade.PVInput$Enhance_102@174d4c9[PVInput]
> location: context:/WEB-INF/PVInput.page, line 7, column 47
>
> java.lang.ClassCastException
> Stack Trace:
> org.apache.tapestry.param.AbstractParameterConnector.resetParameter(Abs 
> tractParameterConnector.java:189)
>
> Any pointers on the correct way to create components would be great.  
> I've spent several hours going through the old Developers guide and  
> the newer User's guide, but I can't seem to find any examples like  
> what I'm doing with a form parameter and no java class for the  
> component, just the jwc and html files.
>
> Here are the key snippets from my code:
>
> PVInput.page:
> <property-specification name="pvFieldObject" type="accolade.PVField"/>
> <component id="myPvField" type="PVFieldComponent">
>         <binding name="pvField" expression="pvFieldObject" />
> </component>
>
> PVInput.html:
> <span jwcid="myPvField" /> (this is inside a foreach which seems to  
> work great)
>
> PVFieldComponent.jwc:
> <component-specification class="org.apache.tapestry.BaseComponent"  
> allow-body="yes" allow-informal-parameters="yes">
>     <parameter name="pvField" type="accolade.PVField" required="yes"  
> direction="form"/>
> 	<component id="pvInputLabel" type="Insert">
> 		<binding name="value" expression="pvField.name" />
> 	</component>
> 	<component id="pvInputField" type="TextField">
> 		<binding name="value" expression="pvField.value" />
> 	</component>
> 	<component id="pvSelectField" type="PropertySelection">
>         <binding name="model" expression="pvField.uomValueModel" />
>         <binding name="value" expression="pvField.value" />
> 	</component>
>
> </component-specification>
>
> PVFieldComponent.html:
> <span jwcid="pvInputLabel" class="pvfieldlabel">Field Label</span>
> <br>
> <span jwcid="@Conditional" condition="ognl:pvField.lov">
>       <select jwcid="pvSelectField" class="pvfield">
>           <option value="sample">Sample Select Field</option>
>        </select>
> </span>
> <span jwcid="@Conditional" condition="ognl:! pvField.lov">
>       <input type="text" jwcid="pvInputField" class="pvfield"  
> value="Sample Input Field"/>
> </span>
>
> PVField.java:
> public class PVField implements Serializable {
> 	private String name = "";
> 	private String value = "";
> 	private String recid = "";
> 	private String uomType = "";
> 	private String defaultValue = "";
> ...
> 	public String getValue() {
> 		return value;
> 	}
> 	
> 	public void setValue(String value) {
> 		this.value = value;
> 	}
> ...
> }
>
>
> Thanks in advance,
> David
>
> --------------------------------------
> David Ethell
> Senior Engineer, Vital Assets, Inc.
> Phone: 800.860.0607 Ex: 102
> Email: dethell@vitalassets.com
> 3916 Germantown Rd
> Edgewater, MD 21037
> --------------------------------------
>
> ---------------------------------------------------------------------
> 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