You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Tim Koop <ti...@timkoop.com> on 2010/07/14 19:27:07 UTC

Expansion for Javascript

  Hi everyone.

I've looked through the documentation, but I can't seem to find an 
answer for what I'm looking for.

I want to put a String into Javascript as a variable, like this:

<script>
var name = "${name}";
</script>

The problem is that if the name will have a quotation mark in it, it 
won't be escaped, and if it has angle brackets, they will be escaped.  
So a name like: /This->"One"/ will create a variable that looks like this:

<script>
var name = "This-&gt;"One"";
</script>

There must be a simple answer for this, but I haven't found it.

Thanks in advance.



-- 
Tim Koop
tim@timkoop.com <ma...@timkoop.com>
www.timkoop.com <http://www.timkoop.com>

Re: Expansion for Javascript

Posted by Michael Gentry <mg...@masslight.net>.
Actually, that would have an issue if your name had a single quote in
it.  You might have to use a hidden form value (hopefully you have a
form?).  There is a bug in the Tapestry hidden component, though, so
you have to do some tricks.  Something like ...

<t:form t:id="inputs">
<t:hidden t:id="name" value="name"/>
</t:form>


Then using Prototype in your JavaScript:

$('inputs')['name'].value

mrg


On Wed, Jul 14, 2010 at 1:30 PM, Michael Gentry <mg...@masslight.net> wrote:
> Assuming your example is in your TML file, try:
>
> var name='<t:outputraw value="name"/>';
>
> mrg
>
>
> On Wed, Jul 14, 2010 at 1:27 PM, Tim Koop <ti...@timkoop.com> wrote:
>>  Hi everyone.
>>
>> I've looked through the documentation, but I can't seem to find an answer
>> for what I'm looking for.
>>
>> I want to put a String into Javascript as a variable, like this:
>>
>> <script>
>> var name = "${name}";
>> </script>
>>
>> The problem is that if the name will have a quotation mark in it, it won't
>> be escaped, and if it has angle brackets, they will be escaped.  So a name
>> like: /This->"One"/ will create a variable that looks like this:
>>
>> <script>
>> var name = "This-&gt;"One"";
>> </script>
>>
>> There must be a simple answer for this, but I haven't found it.
>>
>> Thanks in advance.
>>
>>
>>
>> --
>> Tim Koop
>> tim@timkoop.com <ma...@timkoop.com>
>> www.timkoop.com <http://www.timkoop.com>
>>
>

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


Re: Expansion for Javascript

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 14 Jul 2010 15:13:45 -0300, Inge Solvoll <in...@gmail.com>  
wrote:

> And then you might say "Yeah, but something like this should be  
> built-in". A lot of things should, but there aren't too many Tapestry  
> committers :)

Having too many built-in features can be a problem too. Anyway, the  
recommended way of using JavaScript in Tapestry is not using <script> tags.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Expansion for Javascript

Posted by Inge Solvoll <in...@gmail.com>.
Actually, it's quite super easy to create those yourself :) Seriously, very
very easy.

Have a look at OutputRaw.java in the T5 source, and you'll get the idea.

And then you might say "Yeah, but something like this should be built-in". A
lot of things should, but there aren't too many Tapestry committers :)

Inge

On Wed, Jul 14, 2010 at 7:40 PM, Tim Koop <ti...@timkoop.com> wrote:

>  Cool!  It works!
>
> I still had to do the escaping of the quotation marks myself, but at least
> the html encoding doesn't need to be undone first.
>
>
>
> (Now if only there was outputjsstring, outputurl, outputtextarea,
> outputcsv, and outputcustom)
>
>
>
> Tim Koop
> tim@timkoop.com <ma...@timkoop.com>
> www.timkoop.com <http://www.timkoop.com>
>
> On 14/07/2010 12:30 PM, Michael Gentry wrote:
>
>> Assuming your example is in your TML file, try:
>>
>> var name='<t:outputraw value="name"/>';
>>
>> mrg
>>
>>
>> On Wed, Jul 14, 2010 at 1:27 PM, Tim Koop<ti...@timkoop.com>  wrote:
>>
>>>  Hi everyone.
>>>
>>> I've looked through the documentation, but I can't seem to find an answer
>>> for what I'm looking for.
>>>
>>> I want to put a String into Javascript as a variable, like this:
>>>
>>> <script>
>>> var name = "${name}";
>>> </script>
>>>
>>> The problem is that if the name will have a quotation mark in it, it
>>> won't
>>> be escaped, and if it has angle brackets, they will be escaped.  So a
>>> name
>>> like: /This->"One"/ will create a variable that looks like this:
>>>
>>> <script>
>>> var name = "This-&gt;"One"";
>>> </script>
>>>
>>> There must be a simple answer for this, but I haven't found it.
>>>
>>> Thanks in advance.
>>>
>>>
>>>
>>> --
>>> Tim Koop
>>> tim@timkoop.com<ma...@timkoop.com>
>>> www.timkoop.com<http://www.timkoop.com>
>>>
>>>  ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>

Re: Expansion for Javascript

Posted by Josh Canfield <jo...@gmail.com>.
> I still had to do the escaping of the quotation marks myself

Take a look at JSONObject.quote(String string);


On Wed, Jul 14, 2010 at 10:40 AM, Tim Koop <ti...@timkoop.com> wrote:
>  Cool!  It works!
>
> I still had to do the escaping of the quotation marks myself, but at least
> the html encoding doesn't need to be undone first.
>
>
>
> (Now if only there was outputjsstring, outputurl, outputtextarea, outputcsv,
> and outputcustom)
>
>
> Tim Koop
> tim@timkoop.com <ma...@timkoop.com>
> www.timkoop.com <http://www.timkoop.com>
>
> On 14/07/2010 12:30 PM, Michael Gentry wrote:
>>
>> Assuming your example is in your TML file, try:
>>
>> var name='<t:outputraw value="name"/>';
>>
>> mrg
>>
>>
>> On Wed, Jul 14, 2010 at 1:27 PM, Tim Koop<ti...@timkoop.com>  wrote:
>>>
>>>  Hi everyone.
>>>
>>> I've looked through the documentation, but I can't seem to find an answer
>>> for what I'm looking for.
>>>
>>> I want to put a String into Javascript as a variable, like this:
>>>
>>> <script>
>>> var name = "${name}";
>>> </script>
>>>
>>> The problem is that if the name will have a quotation mark in it, it
>>> won't
>>> be escaped, and if it has angle brackets, they will be escaped.  So a
>>> name
>>> like: /This->"One"/ will create a variable that looks like this:
>>>
>>> <script>
>>> var name = "This-&gt;"One"";
>>> </script>
>>>
>>> There must be a simple answer for this, but I haven't found it.
>>>
>>> Thanks in advance.
>>>
>>>
>>>
>>> --
>>> Tim Koop
>>> tim@timkoop.com<ma...@timkoop.com>
>>> www.timkoop.com<http://www.timkoop.com>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>



-- 
--
http://www.bodylabgym.com - a private, by appointment only, one-on-one
health and fitness facility.
--
http://www.ectransition.com - Quality Electronic Cigarettes at a
reasonable price!
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

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


Re: Expansion for Javascript

Posted by Tim Koop <ti...@timkoop.com>.
  Cool!  It works!

I still had to do the escaping of the quotation marks myself, but at 
least the html encoding doesn't need to be undone first.



(Now if only there was outputjsstring, outputurl, outputtextarea, 
outputcsv, and outputcustom)


Tim Koop
tim@timkoop.com <ma...@timkoop.com>
www.timkoop.com <http://www.timkoop.com>

On 14/07/2010 12:30 PM, Michael Gentry wrote:
> Assuming your example is in your TML file, try:
>
> var name='<t:outputraw value="name"/>';
>
> mrg
>
>
> On Wed, Jul 14, 2010 at 1:27 PM, Tim Koop<ti...@timkoop.com>  wrote:
>>   Hi everyone.
>>
>> I've looked through the documentation, but I can't seem to find an answer
>> for what I'm looking for.
>>
>> I want to put a String into Javascript as a variable, like this:
>>
>> <script>
>> var name = "${name}";
>> </script>
>>
>> The problem is that if the name will have a quotation mark in it, it won't
>> be escaped, and if it has angle brackets, they will be escaped.  So a name
>> like: /This->"One"/ will create a variable that looks like this:
>>
>> <script>
>> var name = "This-&gt;"One"";
>> </script>
>>
>> There must be a simple answer for this, but I haven't found it.
>>
>> Thanks in advance.
>>
>>
>>
>> --
>> Tim Koop
>> tim@timkoop.com<ma...@timkoop.com>
>> www.timkoop.com<http://www.timkoop.com>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Expansion for Javascript

Posted by Michael Gentry <mg...@masslight.net>.
Assuming your example is in your TML file, try:

var name='<t:outputraw value="name"/>';

mrg


On Wed, Jul 14, 2010 at 1:27 PM, Tim Koop <ti...@timkoop.com> wrote:
>  Hi everyone.
>
> I've looked through the documentation, but I can't seem to find an answer
> for what I'm looking for.
>
> I want to put a String into Javascript as a variable, like this:
>
> <script>
> var name = "${name}";
> </script>
>
> The problem is that if the name will have a quotation mark in it, it won't
> be escaped, and if it has angle brackets, they will be escaped.  So a name
> like: /This->"One"/ will create a variable that looks like this:
>
> <script>
> var name = "This-&gt;"One"";
> </script>
>
> There must be a simple answer for this, but I haven't found it.
>
> Thanks in advance.
>
>
>
> --
> Tim Koop
> tim@timkoop.com <ma...@timkoop.com>
> www.timkoop.com <http://www.timkoop.com>
>

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


Re: Expansion for Javascript

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 14 Jul 2010 14:27:07 -0300, Tim Koop <ti...@timkoop.com> wrote:

>   Hi everyone.
>
> I've looked through the documentation, but I can't seem to find an  
> answer for what I'm looking for.
>
> I want to put a String into Javascript as a variable, like this:
>
> <script>
> var name = "${name}";
> </script>

The recommended and less error-prone way of using JavaScript in Tapestry 5  
is to put the most code possible in .js files and the generate the rest  
through RenderSupport.addScript().

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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