You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Mike D Pilsbury <mi...@pekim.co.uk> on 2003/11/09 11:08:53 UTC

Referencing non form component from Javascript.

I need to change the style of a <div> from with Javascript but can't 
work out how to reference it. The Tapestry script framework is based 
around referencing form elements. It doesn't seem to name components 
outside of a form.

Am I going to have to use a form to achieve this? Replace the div with a 
from? If so, it seems like an abuse of a form to use it in that way; it 
won't contain any form elements at all.

I have a feeling I am missing something abouts using scripts in 
Tapestry, but I am not sure what.

Mike


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


Re: Referencing non form component from Javascript.

Posted by Harish Krishnaswamy <hk...@comcast.net>.
If you want to use a div in a Foreach, you may probably want to use the Any component. Something 
like <div jwcid="@Any" id="ognl:yourGeneratedId">. There is an example in the component reference 
that may want to take a look.

-Harish

Mike D Pilsbury wrote:

> Thanks Harish, that makes a lot of sense.
> 
> But that then raises a related issue. Because my <div> is in the 
> template of a component that is used in the body of a Foreach component, 
> I would then need to generate a unique id for it. I could possibly write 
> a bean to serve up incrementing ids ( a bit like the oddEven bean), and 
> use it with request level scope. But if feels like I shouldn't have to. 
> Most things in Tapestry are pretty straightforward, and it seems a shame 
> to have to go to these lengths for something relatively straight forward.
> 
> For now I am using a <form> element instead, but it feels wrong.
> 
> Mike
> 
> 
> Harish Krishnaswamy wrote:
> 
>> You can either reference all non-Tapestry items directly in the script 
>> or you can pass the id/name into the script as a parameter. For ex. if 
>> you have a <div id="yourDiv"> you can pass it into the script as a 
>> parameter like,
>>
>> <component id="yourScriptJwcId" type="Script">
>> ...
>> <static-binding name="divId" value="yourDiv"/>
>> ...
>> </component>
>>
>> Now in your .script,
>>
>> <script>
>> ...
>> <input-symbol name="divId" class="java.lang.String" required="yes"/>
>>
>> <body>
>> ...
>> ...${divId}... // referencing your div Id here like all other input 
>> symbols.
>> ..."yourDiv"... // hardcoding your div Id here, if you don't want to 
>> reuse this script with other divs. In this case you don't need the 
>> input symbol of course.
>> ...
>> </body>
>> ...
>> </script>
>>
>> -Harish
>>
>>
>> Mike D Pilsbury wrote:
>>
>>> I need to change the style of a <div> from with Javascript but can't 
>>> work out how to reference it. The Tapestry script framework is based 
>>> around referencing form elements. It doesn't seem to name components 
>>> outside of a form.
>>>
>>> Am I going to have to use a form to achieve this? Replace the div 
>>> with a from? If so, it seems like an abuse of a form to use it in 
>>> that way; it won't contain any form elements at all.
>>>
>>> I have a feeling I am missing something abouts using scripts in 
>>> Tapestry, but I am not sure what.
>>>
>>> Mike
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
> 
> 
> ---------------------------------------------------------------------
> 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: Referencing non form component from Javascript.

Posted by Mike D Pilsbury <mi...@pekim.co.uk>.
Thanks Harish, that makes a lot of sense.

But that then raises a related issue. Because my <div> is in the 
template of a component that is used in the body of a Foreach component, 
I would then need to generate a unique id for it. I could possibly write 
a bean to serve up incrementing ids ( a bit like the oddEven bean), and 
use it with request level scope. But if feels like I shouldn't have to. 
Most things in Tapestry are pretty straightforward, and it seems a shame 
to have to go to these lengths for something relatively straight forward.

For now I am using a <form> element instead, but it feels wrong.

Mike


Harish Krishnaswamy wrote:

> You can either reference all non-Tapestry items directly in the script 
> or you can pass the id/name into the script as a parameter. For ex. if 
> you have a <div id="yourDiv"> you can pass it into the script as a 
> parameter like,
>
> <component id="yourScriptJwcId" type="Script">
> ...
> <static-binding name="divId" value="yourDiv"/>
> ...
> </component>
>
> Now in your .script,
>
> <script>
> ...
> <input-symbol name="divId" class="java.lang.String" required="yes"/>
>
> <body>
> ...
> ...${divId}... // referencing your div Id here like all other input 
> symbols.
> ..."yourDiv"... // hardcoding your div Id here, if you don't want to 
> reuse this script with other divs. In this case you don't need the 
> input symbol of course.
> ...
> </body>
> ...
> </script>
>
> -Harish
>
>
> Mike D Pilsbury wrote:
>
>> I need to change the style of a <div> from with Javascript but can't 
>> work out how to reference it. The Tapestry script framework is based 
>> around referencing form elements. It doesn't seem to name components 
>> outside of a form.
>>
>> Am I going to have to use a form to achieve this? Replace the div 
>> with a from? If so, it seems like an abuse of a form to use it in 
>> that way; it won't contain any form elements at all.
>>
>> I have a feeling I am missing something abouts using scripts in 
>> Tapestry, but I am not sure what.
>>
>> Mike
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>


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


Re: Referencing non form component from Javascript.

Posted by Harish Krishnaswamy <hk...@comcast.net>.
You can either reference all non-Tapestry items directly in the script or you can pass the id/name 
into the script as a parameter. For ex. if you have a <div id="yourDiv"> you can pass it into the 
script as a parameter like,

<component id="yourScriptJwcId" type="Script">
	...
	<static-binding name="divId" value="yourDiv"/>
	...
</component>

Now in your .script,

<script>
	...
	<input-symbol name="divId" class="java.lang.String" required="yes"/>

	<body>
	...
		...${divId}... 	// referencing your div Id here like all other input symbols.
		..."yourDiv"...	// hardcoding your div Id here, if you don't want to reuse this script with other 
divs. In this case you don't need the input symbol of course.
	...
	</body>
	...
</script>

-Harish


Mike D Pilsbury wrote:

> I need to change the style of a <div> from with Javascript but can't 
> work out how to reference it. The Tapestry script framework is based 
> around referencing form elements. It doesn't seem to name components 
> outside of a form.
> 
> Am I going to have to use a form to achieve this? Replace the div with a 
> from? If so, it seems like an abuse of a form to use it in that way; it 
> won't contain any form elements at all.
> 
> I have a feeling I am missing something abouts using scripts in 
> Tapestry, but I am not sure what.
> 
> Mike
> 
> 
> ---------------------------------------------------------------------
> 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