Re: Struggling with Ajax in T5 ...

2011-01-31 Thread LLTYK

The key part of zone updater that does what you want is this:
  void afterRender() {
String url = resources.createEventLink(event, context).toAbsoluteURI();
...
renderSupport.addScript("%sZoneUpdater = new ZoneUpdater(%s)", prefix,
spec.toString());
  }


This is the interface from Tapestry to Javascript. The string in the
addScript call is literal javascript (except for the %s) that's added to the
bottom of the page.

You are basically looking for the right url to hit from javascript that will
trigger your Tapestry method. createEventLink generates this url
('createEventLink("register", "placeholderforputtingstudentid")'), addScript
will pass it to the Javascript, and in there "zoneManager.updateFromUrl"
proceeds to ping that url. Another way to ping urls from js is with
Prototype:
http://www.prototypejs.org/api/ajax/request

-- 
View this message in context: 
http://tapestry-users.832.n2.nabble.com/Struggling-with-Ajax-in-T5-tp5970312p5976916.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

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



Re: Struggling with Ajax in T5 ...

2011-01-30 Thread Inge Solvoll
Hi!

I haven't read all of this thread, but I have one suggestion: You should
"hijack" your onclick handlers with javascript to do additional work before
or after calling the original onclick. Don't know how experienced you are
with javascript, but it will look something like this:

var oldOnclick = firstButton.onclick;
firstButton.bind('click', myOwnOnclickListener);
var myOwnOnClickListener = function(event) {
  // My own code here
  oldOnclick();
}


On Fri, Jan 28, 2011 at 6:30 PM, Jessica Sobieski <
jessica.sobie...@gmail.com> wrote:

> Hi Thiago -
>
> > Which buttons? I'm not following you.
>
> To answer your question, I'm talking about these buttons in my template:
>
> Student Registration
> 
> 
> 
>
> These input buttons come from an HTML stored in a database. I can't change
> that design, and these buttons must call register(studentId) javascript
> function.
>
> So what kind of JavaScript code can I use to connect register(studentId)
> function with the page class registerStudent method?
>
> Adam
>
> On Fri, Jan 28, 2011 at 10:34 AM, Thiago H. de Paula Figueiredo <
> thiag...@gmail.com> wrote:
>
> > On Fri, 28 Jan 2011 13:57:16 -0200, Jessica Sobieski <
> > jessica.sobie...@gmail.com> wrote:
> >
> >  Hello boys!
> >>
> >
> > Hi!
> >
> >
> >  1) I don't control how buttons are generated, therefore they must call
> >> register(studentId) javascript. No way around it.
> >>
> >
> > Which buttons? I'm not following you.
> >
> >
> >>public String getStudent() {
> >>return student.getName();
> >>}
> >> }
> >>
> >> Here is my question:
> >>
> >> 2) I must somehow call Tapestry from register(studentId) method. I am
> >> both, clueless and frustrated as to how to do it.
> >>
> >
> > Just ask us. :)
> >
> > Define an event name for it. My example will use "register". Use the
> > JavaScript code in
> > http://tinybits.blogspot.com/2010/03/new-and-better-zoneupdater.html to
> > correctly handle zone updates. Use a query parameter to pass information.
> > Your code will look like this (not tested):
> >
> >
> > public class StudentCourse {
> >
> >@Inject @Id("confirmation") private Block confirmationBlock;
> >
> >@Inject private StudentDao studentDao;
> >
> >private Student student;
> >
> >@OnEvent("register") // without this annotation,
> >Object registerStudent(@RequestParameter("id") Integer studentId) {
> >
> >student = studentDao.register(studentId);
> >return confirmationBlock;
> >}
> >
> >public String getStudent() {
> >return student.getName();
> >}
> > }
> >
> > This is probably a not complete solution, but at least I gave you some
> > hints. :) I hope it helps.
> >
> > --
> > 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-unsubscr...@tapestry.apache.org
> > For additional commands, e-mail: users-h...@tapestry.apache.org
> >
> >
>


Re: Struggling with Ajax in T5 ...

2011-01-28 Thread Thiago H. de Paula Figueiredo
On Fri, 28 Jan 2011 15:30:31 -0200, Jessica Sobieski  
 wrote:



Hi Thiago -


Hi!


So what kind of JavaScript code can I use to connect register(studentId)
function with the page class registerStudent method?


See http://tinybits.blogspot.com/2010/03/new-and-better-zoneupdater.html  
for an example.


--
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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Struggling with Ajax in T5 ...

2011-01-28 Thread Jessica Sobieski
Hi Thiago -

> Which buttons? I'm not following you.

To answer your question, I'm talking about these buttons in my template:

Student Registration




These input buttons come from an HTML stored in a database. I can't change
that design, and these buttons must call register(studentId) javascript
function.

So what kind of JavaScript code can I use to connect register(studentId)
function with the page class registerStudent method?

Adam

On Fri, Jan 28, 2011 at 10:34 AM, Thiago H. de Paula Figueiredo <
thiag...@gmail.com> wrote:

> On Fri, 28 Jan 2011 13:57:16 -0200, Jessica Sobieski <
> jessica.sobie...@gmail.com> wrote:
>
>  Hello boys!
>>
>
> Hi!
>
>
>  1) I don't control how buttons are generated, therefore they must call
>> register(studentId) javascript. No way around it.
>>
>
> Which buttons? I'm not following you.
>
>
>>public String getStudent() {
>>return student.getName();
>>}
>> }
>>
>> Here is my question:
>>
>> 2) I must somehow call Tapestry from register(studentId) method. I am
>> both, clueless and frustrated as to how to do it.
>>
>
> Just ask us. :)
>
> Define an event name for it. My example will use "register". Use the
> JavaScript code in
> http://tinybits.blogspot.com/2010/03/new-and-better-zoneupdater.html to
> correctly handle zone updates. Use a query parameter to pass information.
> Your code will look like this (not tested):
>
>
> public class StudentCourse {
>
>@Inject @Id("confirmation") private Block confirmationBlock;
>
>@Inject private StudentDao studentDao;
>
>private Student student;
>
>@OnEvent("register") // without this annotation,
>Object registerStudent(@RequestParameter("id") Integer studentId) {
>
>student = studentDao.register(studentId);
>return confirmationBlock;
>}
>
>public String getStudent() {
>return student.getName();
>}
> }
>
> This is probably a not complete solution, but at least I gave you some
> hints. :) I hope it helps.
>
> --
> 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-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


Re: Struggling with Ajax in T5 ...

2011-01-28 Thread Thiago H. de Paula Figueiredo
On Fri, 28 Jan 2011 13:57:16 -0200, Jessica Sobieski  
 wrote:



Hello boys!


Hi!


1) I don't control how buttons are generated, therefore they must call
register(studentId) javascript. No way around it.


Which buttons? I'm not following you.



public String getStudent() {
return student.getName();
}
}

Here is my question:

2) I must somehow call Tapestry from register(studentId) method. I am  
both, clueless and frustrated as to how to do it.


Just ask us. :)

Define an event name for it. My example will use "register". Use the  
JavaScript code in  
http://tinybits.blogspot.com/2010/03/new-and-better-zoneupdater.html to  
correctly handle zone updates. Use a query parameter to pass information.  
Your code will look like this (not tested):


public class StudentCourse {

@Inject @Id("confirmation") private Block confirmationBlock;

@Inject private StudentDao studentDao;

private Student student;

@OnEvent("register") // without this annotation,
Object registerStudent(@RequestParameter("id") Integer studentId) {
student = studentDao.register(studentId);
return confirmationBlock;
}

public String getStudent() {
return student.getName();
}
}

This is probably a not complete solution, but at least I gave you some  
hints. :) I hope it helps.


--
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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org