You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by John McTeague <jo...@shortslant.com> on 2004/01/30 12:39:44 UTC
Script problem in custom component
I have created a component called MaxLengthValidField, which extends upon
ValidField by taking in a maxlength property that limits the number of
characters that can be entered by rendering a maxlength attribute on the
<input> tag.
Each time I add one of these components, I include a script that provides
some utility javascript functions for each text field, enable/disable
field etc. The .script is declared in the MaxLengthValidField.html page
as follows:
<span jwcid="@Script" script="EnableDisableComponent.script"
form="ognl:form" object="ognl:components.MaxLengthValidField_validfield"/>
....
The EnableDisableComponent.script is as follows:
<?xml version="1.0" ?>
<!DOCTYPE script PUBLIC
"-//Apache Software Foundation//Tapestry Script Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Script_3_0.dtd">
<script>
<input-symbol key="object" class="org.apache.tapestry.AbstractComponent"
required="yes"/>
<input-symbol key="form" class="org.apache.tapestry.IForm" required="yes"/>
<let key="childId" unique="yes">
${object.id}${object.name}
</let>
<let key="componentName" >
${object.container.id}
</let>
<body>
<![CDATA[
function disable_${componentName}() {
document.${form.name}.${childId}.disabled = true;
}
function enable_${componentName}() {
document.${form.name}.${childId}.disabled = false;
}
]]>
</body>
</script>
When a page using this component is first rendered, everything is fine.
If I declare a component in the .page called surname, I get two
javascript funtions:
enable_surname(){
document.Form0.MaxLengthValidField_validfield.disabled=false;
}
disable_surname(){
document.Form0.MaxLengthValidField_validfield.disabled=true;
}
When I have multiple MaxLenghtValidFields, the functions reference
MaxLengthValidField_validfield$0, MaxLengthValidField_validfield$1 etc as
normal.
However when I submit the page and encounter an application error that
immediately returns me to the same page, although my enable_X and
disable_X functions stil exist, their contents have changed to:
document.Form0.MaxLengthValidField_validfieldMaxLengthValidField_validfield.disabled=false;
i.e. The name has been duplicated. The id attribute of the input tag
remains MaxLengthValidField_validfield however (therefore my javascript
fails).
Does anyone know the cause? I originally suspected the line
${object.id}${object.name} in my .script was at fault, but that is the
only value I can put in there that will work.
It should be noted that no MaxLengthValidField.java exists. The
MaxLengthValidField.jwc refers to org.apache.tapestry.BaseComponent.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org