You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jorge Quiroga <jq...@pctltda.com> on 2006/01/23 16:37:06 UTC

Naming js functions problem

Hello:

I'm newbie with T4 and I'm trying to do a component that is composed by 
a Checkbox, Label, A dynamic input control (could be a text, validtext, 
a checkbox or a combo) and a button.

The checkbox if is present, enable/disabled via javascript the button 
and the dynamic input control. By now the component generates the 
Javascript but when the component is called by a For then I don't know 
how to obtain the function name corresponding in the HTML code (to 
control the enabled disabled via on focus over the dynamic component and 
by the enabled informal parameter of the button) and every dynamic Input 
Component reacts only with the last dynamically generated js function 
and not with its correspond function, I search into the T4 documentation 
and the Tapestry in action book but doesn´t spotlight for this case and 
I saw some code of the Popup component, but I don´t understand it well 
(how to obtain the function name and attach it into de HTML or how 
calculate the function name if I don´t know how to obtain the real name 
of the component) and using the same approach in the java code I obtain 
the same result.

The .script involved part is:

<script>

<input-symbol key="check" class="org.apache.tapestry.form.Checkbox" 
required="no"/>

<set key="chkName" expression="check.name"/>

<let key="ctrlEnabled" unique="yes">
   enableCtrlChecked_${chkName}
</let>

<let key="CheckCheckBox" unique="yes">
   isCheckChecked_${chkName}
</let>

<body>
<if expression="not (chkName==null)">
<![CDATA[
function ${CheckCheckBox}()
{
   if (!${chkName}.checked)
     ${chkName}.focus()
}

function ${ctrlEnabled}()
{
   if (${chkName}.checked)
     return true;
   else return false;
}
]]>
</if>
</body>

</script>

and the HTML into the component is:

<table border="1" cellspacing="0">
<tr>
<td>
   <span jwcid="@If" condition="ognl:showCheckbox">
     <span jwcid="enableCtrl@Checkbox" value="ognl:checkEnabled"/>
   </span>
   <span class="labelClass" jwcid="@Insert" value="ognl:displayName"/>
</td>
   <div jwcid="comp@RenderBlock" block="ognl:inputType"/>
     <block jwcid="alfanumeric@Block">
       <td>
         <span jwcid="alfa@TextField" value="ognl:valor" 
size="ognl:inputSize" onfocus="HOW_I_CAN_DO_IT"/>
       </td>
       <span jwcid="@If" condition="ognl:showButton">
         <td>
           <input type="button" jwcid="@Any" value="..." onClick='return 
nwl_popWindow('+dialogURL+","+dialogWidth+","+dialogHeight+","+dialogCentered+","+dialogFeatures+","+dialogTitle+");"' 
enabled='HOW_I_CAN_DO_IT'/>
         </td>
       </span>
     </block>
... other blocks
</tr>
</table>
<span jwcid="@If" condition="ognl:showCheckbox">
   <span jwcid="@Script" script="CheckedLookupDialog.script" 
check="ognl:components.enableCtrl"/>
</span>
<span jwcid="@Else">
   <span jwcid="@Script" script="CheckedLookupDialog.script"/>
</span>

the .java is a POJO with abstracts getters and setters and as I said the 
getFuntionName (as PopupLink is) for focus and enabled doesn´t work and 
isn´t relevant.

I'm attack the problem in the wrong way? or I'm missing something?

Thanks for your time, and excuse me for re-send it.

JQ


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


Re: Naming js functions problem

Posted by Jorge Quiroga <jq...@pctltda.com>.
Well I find a solution for it, but I don´t know if is a better or at 
least the T4 way solution.

I have to add an ID parameter to my new component and use it to generate 
a javascript function name within .script and into the .java in order to 
.html get the js function name via ognl, but has a lot of weaks, for 
instance, when the For is iterating and doesn´t exist a real ID, then 
the enable/disable Checkbox control will be attached to the last one; 
another problem that I have with it, is if my Checkbox component is 
null, because is an optional parameter, then the key that obtains the 
name of the checkbox generates an error, then the Checkbox becomes 
required and isn´t that I want, and if I put an <if> T4 raise an error 
because it doesn't find the corresponding </if> that of course is present.

If someone has a better approach, and the solution to achive a real 
optional Checkbox, please tell me.

Thanks

JQ


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