Java Mailing List Archive

http://www.gg3721.com/

Home » users.tapestry »

[T5] Idiot Javascript question

Lance White

2008-11-26

Replies: Find Java Web Hosting

Author LoginPost Reply

Hi,

I'm trying to embed some JavaScript in a component, and for the life of me
cannot get it to work. I can sort of understand why it's not working, I just
can't see what to do to fix it - if anyone can point me towards a
resolution, I'd be grateful - I'm currently playing with 5.0.15.

OK, this isn't my actual component, but it shows the problem... a simple
component that has a button that calls a javascript function.

TML
----
<div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
  <input type="button" onclick="jsAlert()" value="JS Alert"/>
</div>

Java
----
import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.annotations.AfterRender;
import org.apache.tapestry5.annotations.Environmental;

public class JSAlert
{
 private String alert = "function jsAlert() { alert(\"HELLO\"); }";

 @Environmental
 private RenderSupport renderSupport;

 @AfterRender
 public void afterRender() {
   renderSupport.addScript(alert);
 }
}

Basically, when you click the button, the browser says the JSAlert function
is not defined.

TIA

Lance

--
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)

©2008 gg3721.com - Jax Systems, LLC, U.S.A.