You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Martin Dietze <di...@fh-wedel.de> on 2007/06/27 10:08:43 UTC

T5: Conditional JavaScript code

Hi,

 I would like to add inline JavaScript code to a form depending
on conditions set within the page class. I thus wrote code like
this:

| <script type="text/javascript">
| function myFunc() {
| <t:if test="prop:myCondition">
|   for (var i = 0; i < someConstant; i++) {
|     doSomethin();
|   }
| </t:if>
| }
| </script>

This code causes problems since obviously Tapestry expects
well-formed HTML code here (note the '<' character). I also run
into problems if I put the inline JavaScript into HTML
comments, the code gets completely ignored then.

Since after each submit of the form the condition in the <t:if>
changes I don't really see any alternative to this construct,
or is there any fix/better way to do this?

Cheers,

Martin

-- 
----------- / http://herbert.the-little-red-haired-girl.org / -------------
=+= 
Yoda of Borg I am. Assimilated you will be.

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


Re: T5: Conditional JavaScript code

Posted by Nick Westgate <ni...@key-planning.co.jp>.
You'll get better advice from JS gurus, but I usually just reverse the condition:

for (var i = 0; someConstant >= i ; i++) {

Cheers,
Nick.


Martin Dietze wrote:
> Hi,
> 
>  I would like to add inline JavaScript code to a form depending
> on conditions set within the page class. I thus wrote code like
> this:
> 
> | <script type="text/javascript">
> | function myFunc() {
> | <t:if test="prop:myCondition">
> |   for (var i = 0; i < someConstant; i++) {
> |     doSomethin();
> |   }
> | </t:if>
> | }
> | </script>
> 
> This code causes problems since obviously Tapestry expects
> well-formed HTML code here (note the '<' character). I also run
> into problems if I put the inline JavaScript into HTML
> comments, the code gets completely ignored then.
> 
> Since after each submit of the form the condition in the <t:if>
> changes I don't really see any alternative to this construct,
> or is there any fix/better way to do this?
> 
> Cheers,
> 
> Martin
> 

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


Re: T5: Conditional JavaScript code

Posted by Jesse Kuhnert <jk...@gmail.com>.
I'm not sure about the best solution for this but have you tried replacing <
with &lt; to make the parser happy about well formed html ?

(or do a <script><!-- --></script> style comment block ? )

On 6/27/07, Martin Dietze <di...@fh-wedel.de> wrote:
>
> Hi,
>
> I would like to add inline JavaScript code to a form depending
> on conditions set within the page class. I thus wrote code like
> this:
>
> | <script type="text/javascript">
> | function myFunc() {
> | <t:if test="prop:myCondition">
> |   for (var i = 0; i < someConstant; i++) {
> |     doSomethin();
> |   }
> | </t:if>
> | }
> | </script>
>
> This code causes problems since obviously Tapestry expects
> well-formed HTML code here (note the '<' character). I also run
> into problems if I put the inline JavaScript into HTML
> comments, the code gets completely ignored then.
>
> Since after each submit of the form the condition in the <t:if>
> changes I don't really see any alternative to this construct,
> or is there any fix/better way to do this?
>
> Cheers,
>
> Martin
>
> --
> ----------- / http://herbert.the-little-red-haired-girl.org /
> -------------
> =+=
> Yoda of Borg I am. Assimilated you will be.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

Re: T5: Conditional JavaScript code

Posted by 蝈蝈龙 <el...@gmail.com>.
Hi Howard,

When do TP5  plan to support CDATA?
I think it is very important.


2007/6/29, Howard Lewis Ship <hl...@gmail.com>:
>
> for (var i = 0; i &lt; someConstant; i++) {
>
> On 6/27/07, Martin Dietze <di...@fh-wedel.de> wrote:
> > Hi,
> >
> >  I would like to add inline JavaScript code to a form depending
> > on conditions set within the page class. I thus wrote code like
> > this:
> >
> > | <script type="text/javascript">
> > | function myFunc() {
> > | <t:if test="prop:myCondition">
> > |   for (var i = 0; i < someConstant; i++) {
> > |     doSomethin();
> > |   }
> > | </t:if>
> > | }
> > | </script>
> >
> > This code causes problems since obviously Tapestry expects
> > well-formed HTML code here (note the '<' character). I also run
> > into problems if I put the inline JavaScript into HTML
> > comments, the code gets completely ignored then.
> >
> > Since after each submit of the form the condition in the <t:if>
> > changes I don't really see any alternative to this construct,
> > or is there any fix/better way to do this?
> >
> > Cheers,
> >
> > Martin
> >
> > --
> > ----------- / http://herbert.the-little-red-haired-girl.org /
> -------------
> > =+=
> > Yoda of Borg I am. Assimilated you will be.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> --
> Howard M. Lewis Ship
> TWD Consulting, Inc.
> Independent J2EE / Open-Source Java Consultant
> Creator and PMC Chair, Apache Tapestry
> Creator, Apache HiveMind
>
> Professional Tapestry training, mentoring, support
> and project work.  http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: Conditional JavaScript code

Posted by Howard Lewis Ship <hl...@gmail.com>.
for (var i = 0; i &lt; someConstant; i++) {

On 6/27/07, Martin Dietze <di...@fh-wedel.de> wrote:
> Hi,
>
>  I would like to add inline JavaScript code to a form depending
> on conditions set within the page class. I thus wrote code like
> this:
>
> | <script type="text/javascript">
> | function myFunc() {
> | <t:if test="prop:myCondition">
> |   for (var i = 0; i < someConstant; i++) {
> |     doSomethin();
> |   }
> | </t:if>
> | }
> | </script>
>
> This code causes problems since obviously Tapestry expects
> well-formed HTML code here (note the '<' character). I also run
> into problems if I put the inline JavaScript into HTML
> comments, the code gets completely ignored then.
>
> Since after each submit of the form the condition in the <t:if>
> changes I don't really see any alternative to this construct,
> or is there any fix/better way to do this?
>
> Cheers,
>
> Martin
>
> --
> ----------- / http://herbert.the-little-red-haired-girl.org / -------------
> =+=
> Yoda of Borg I am. Assimilated you will be.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

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


RE: T5: Conditional JavaScript code

Posted by Adam Ayres <ad...@lithium.com>.
You could use the PageRenderSupport Environmental annotation to set a
JavaScript variable in your page class that is the evaluated by the
embedded component JavaScript.

MyPageComponent.java:

@Environmental
private PageRenderSupport pageRenderSupport;

@BeginRender
void beginRender() {
	pageRenderSupport.addScript("var myPageCondition = " +
isMyCondition() + ";");
}

Private boolean isMyCondition() {
	return myConditionLogic();
}

However seems a little weird that you would want to conditionally set
the logic on a JavaScript function, seems like you would want to
conditionally call the function instead.

Adam


-----Original Message-----
From: Martin Dietze [mailto:di@mail.fh-wedel.de] On Behalf Of Martin
Dietze
Sent: Wednesday, June 27, 2007 1:09 AM
To: users@tapestry.apache.org
Subject: T5: Conditional JavaScript code

Hi,

 I would like to add inline JavaScript code to a form depending
on conditions set within the page class. I thus wrote code like
this:

| <script type="text/javascript">
| function myFunc() {
| <t:if test="prop:myCondition">
|   for (var i = 0; i < someConstant; i++) {
|     doSomethin();
|   }
| </t:if>
| }
| </script>

This code causes problems since obviously Tapestry expects
well-formed HTML code here (note the '<' character). I also run
into problems if I put the inline JavaScript into HTML
comments, the code gets completely ignored then.

Since after each submit of the form the condition in the <t:if>
changes I don't really see any alternative to this construct,
or is there any fix/better way to do this?

Cheers,

Martin

-- 
----------- / http://herbert.the-little-red-haired-girl.org /
-------------
=+= 
Yoda of Borg I am. Assimilated you will be.

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


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