You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Danny Angus <Da...@slc.co.uk> on 2003/09/24 16:14:43 UTC

@Script, how to, why, and whether?




Hi,

I'm new to Tapestry and having trouble with scripting. First off I can't
get the script component to work at all, (help?!) but read on..
We have a need for some quite involved javascript driven DHTML and I'm
wondering if this requirement is, in practice, going to be incompatible
with tapestry?
It certainly seems that I have to jump through hoops of fire to use
javascript in the documented way, and I suspect it is a bit sensitive given
that I can't get a simple single line script (alert("hello");)rendered by
the component.
Help us to choose tapestry....what are my options?

Background:
The application involves multiple pages in a data gathering excercise, the
plan is to omit pages where an answer given earlier means that a whole page
of questions is now no longer relevant. However for performance reasons
we're loath to make a trip to the server just to disable or enable the odd
individual question here and there.

d.



***************************************************************************
The information in this e-mail is confidential and for use by the addressee(s) only. If you are not the intended recipient (or responsible for delivery of the message to the intended recipient) please notify us immediately on 0141 306 2050 and delete the message from your computer. You may not copy or forward it or use or disclose its contents to any other person. As Internet communications are capable of data corruption Student Loans Company Limited does not accept any  responsibility for changes made to this message after it was sent. For this reason it may be inappropriate to rely on advice or opinions contained in an e-mail without obtaining written confirmation of it. Neither Student Loans Company Limited or the sender accepts any liability or responsibility for viruses as it is your responsibility to scan attachments (if any). Opinions and views expressed in this e-mail are those of the sender and may not reflect the opinions and views of The Student Loans Company Limited.

This footnote also confirms that this email message has been swept for the presence of computer viruses.

**************************************************************************


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


Re: @Script, how to, why, and whether?

Posted by Harish Krishnaswamy <hk...@comcast.net>.
That's a good point, I shall add this to the wiki. BTW, one may find the 
previous explanation in the wiki under Tapestry FAQ @Script Why And How.

The resource-path is relative to the classpath, so /scripts/xyz.js may 
be placed under WEB-INF/classes/scripts/xyz.js.

-Harish

F. Da Costa Gomez wrote:

> F. Da Costa Gomez wrote:
>
>>
>>> Would I use a static-binding (in a .page or .jwc definition) with a 
>>> xyz.js as value to incorporate an 'ordinary' xyz.js file in an 
>>> .script template?
>>> Or how would I go about that?
>>
>>
>>
>> Never mind, had another look in the Dev gguide and it seems that I 
>> would have to use include-script to accomplish this.
>
>
> Hmm, bit pre-mature here.
> *http://localhost:8081/scripts* shows me the .js files (could this be 
> dis-allowed by any chance?) but including <include-script 
> resource-path="/scripts/xyz.js" /> does not seem to do the trick.
> Nor resource-path="xyz.js" nor resource-path="/app/scripts/xyz.js".
>
> What would be the correct approach to set the resource-path.
> *http://localhost:8081/app* points to the start of the app.
>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
>>
>>
>> __________ NOD32 1.519 (20030926) Information __________
>>
>> This message was checked by NOD32 Antivirus System.
>> http://www.nod32.com
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> 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: @Script, how to, why, and whether?

Posted by "F. Da Costa Gomez" <dc...@fixed.com>.
F. Da Costa Gomez wrote:

>
>> Would I use a static-binding (in a .page or .jwc definition) with a 
>> xyz.js as value to incorporate an 'ordinary' xyz.js file in an 
>> .script template?
>> Or how would I go about that?
>
>
> Never mind, had another look in the Dev gguide and it seems that I 
> would have to use include-script to accomplish this.

Hmm, bit pre-mature here.
*http://localhost:8081/scripts* shows me the .js files (could this be 
dis-allowed by any chance?) but including <include-script 
resource-path="/scripts/xyz.js" /> does not seem to do the trick.
Nor resource-path="xyz.js" nor resource-path="/app/scripts/xyz.js".

What would be the correct approach to set the resource-path.
*http://localhost:8081/app* points to the start of the app.

>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
>
> __________ NOD32 1.519 (20030926) Information __________
>
> This message was checked by NOD32 Antivirus System.
> http://www.nod32.com
>
>
>



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


Re: @Script, how to, why, and whether?

Posted by "F. Da Costa Gomez" <dc...@fixed.com>.
> Would I use a static-binding (in a .page or .jwc definition) with a 
> xyz.js as value to incorporate an 'ordinary' xyz.js file in an .script 
> template?
> Or how would I go about that?

Never mind, had another look in the Dev gguide and it seems that I would 
have to use include-script to accomplish this.


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


Re: @Script, how to, why, and whether?

Posted by "F. Da Costa Gomez" <dc...@fixed.com>.
Harish Krishnaswamy wrote:

> That's all there is to it! Boy, this could have been a document! I'll 
> probably stick it in the Wiki.
>
> -Harish

It definitly should be!
Very good explanation of the 'advanced' use of JS indeed.

1 small additional question though.
Would I use a static-binding (in a .page or .jwc definition) with a 
xyz.js as value to incorporate an 'ordinary' xyz.js file in an .script 
template?
Or how would I go about that?
Reason: putting the js together is not done with the .script and it 
would be convenient to not have to keep on ctl-c/ ctl-p bewteen the two.

TIA,
Fermin DCG


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


Re: @Script, how to, why, and whether?

Posted by Harish Krishnaswamy <hk...@comcast.net>.
IMO, the script framework is an effective means to bundle scripts in 
components. It provides scripts with the advantages of components. It 
can now be reused like a component and not have to worry about renaming 
field names or the wiring between the fields and the scripts. You just 
declare the component and you are good to go. It certainly is another 
layer of abstraction that one will have to learn but once you have 
learned it, it is very powerful. And honestly there is not much to it.

The script framework is mandated by the fact that form element/field 
names are automatically generated by the framework. And so you write 
your script in XML and use *variables* for these names and let the 
framework provide the correct names during runtime. Going further, you 
may also ask the framework to provide other objects that would help in 
creating your script. For example...

<input-symbol key="select"
    class="org.apache.tapestry.form.PropertySelection" required="yes"/>

This defines an input variable "select" of type 
"org.apache.tapestry.form.PropertySelection". All such variables/symbols 
passed in to the script is stored in a symbol map. And now you can use 
the form select list name by using an ant style syntax like 
${select.name}. The expression within "${}" is an OGNL expression and is 
evaluated with respect to the symbol map. You may also define your own 
symbols/variables using <let...> like...

<let key="formObj">
    document.${select.form.name}
</let>
<let key="selectObj">
    ${formObj}.${select.name}
</let>

These variables/symbols are stored in the symbol map also. So now if you 
want to set the value of the form select list all you do is say 
${formObj}.${selectObj}.value = 'whatever'; this would be equivalent to 
document.myForm.mySelect.value = 'whatever'; where myForm is the form 
name and mySelect is the select list name.

<input-symbol...>s are like method parameters and <let...>s are like 
instance variables. Typically you would pass values to the 
<input-symbol...>s via the Script component like...

    <component id="myScript" type="Script">
        <static-binding name="script" 
value="<ScriptSpecificationName>.script"/>
        <binding name="select" 
expression="components.somePropertySelection"/>
    </component>

The actual scripts are defined in one of the two sections of the script 
specification, <body...> or <initialization...>, depending on when you 
want the script to execute. If you want the script to execute on load of 
the page, then you define it in the <initialization...>, if you want it 
to execute on any other event, define it in the <body...> section of the 
specification. For example...

<body>
<![CDATA[
  function onChangeList(listObj)
  {
    alert(listObj.value);
  }
]]>
</body>

<initialization>
  ${selectObj}.onchange = function(e)
  {
    onChangeList(${selectObj});
  }
</initialization>

As you can see in the rendered page all scripts are aggregated at the 
top of the page body, there are no more scripts all over the page. Even 
event handlers are attached to form objects in the initialization block.

One more thing to remember, scripts being components, and components by 
nature being independent of its environment, will render the script in 
the page once for every ocurrance of the component. If you want the body 
of the script to be rendered only once no matter how many times the 
component is used, just wrap the body in a <unique> tag like...

<body>
<unique>
<![CDATA[
  function onChangeList(listObj)
  {
    alert(listObj.value);
  }
]]>
</unique>
</body>

That's all there is to it! Boy, this could have been a document! I'll 
probably stick it in the Wiki.

-Harish


Danny Angus wrote:

>
>
>Hi,
>
>I'm new to Tapestry and having trouble with scripting. First off I can't
>get the script component to work at all, (help?!) but read on..
>We have a need for some quite involved javascript driven DHTML and I'm
>wondering if this requirement is, in practice, going to be incompatible
>with tapestry?
>It certainly seems that I have to jump through hoops of fire to use
>javascript in the documented way, and I suspect it is a bit sensitive given
>that I can't get a simple single line script (alert("hello");)rendered by
>the component.
>Help us to choose tapestry....what are my options?
>
>Background:
>The application involves multiple pages in a data gathering excercise, the
>plan is to omit pages where an answer given earlier means that a whole page
>of questions is now no longer relevant. However for performance reasons
>we're loath to make a trip to the server just to disable or enable the odd
>individual question here and there.
>
>d.
>
>
>
>***************************************************************************
>The information in this e-mail is confidential and for use by the addressee(s) only. If you are not the intended recipient (or responsible for delivery of the message to the intended recipient) please notify us immediately on 0141 306 2050 and delete the message from your computer. You may not copy or forward it or use or disclose its contents to any other person. As Internet communications are capable of data corruption Student Loans Company Limited does not accept any  responsibility for changes made to this message after it was sent. For this reason it may be inappropriate to rely on advice or opinions contained in an e-mail without obtaining written confirmation of it. Neither Student Loans Company Limited or the sender accepts any liability or responsibility for viruses as it is your responsibility to scan attachments (if any). Opinions and views expressed in this e-mail are those of the sender and may not reflect the opinions and views of The Student Loans Company Limited.
>
>This footnote also confirms that this email message has been swept for the presence of computer viruses.
>
>**************************************************************************
>
>
>---------------------------------------------------------------------
>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