SammyRulez

I always thought the joy of reading a book is not knowing what happens next.

I have joined Anti-IF Campaign
Nov 11 ’09

PlayFramework recipe: Reusable ajax Tags

HaveLet’s say it: Play! and Rails do have similarities. One thing I always liked of my Rails friends where the ajax tags. So I port them (or some of them) in Play!

Here the svn url to check out the Play!Module. All these tags are based on JQuery

  • Link opens a remote url in a page div with a fancy fade out - fade in effect and has the following parameters:
    1. update: the id of the div to be updated
    2. url: the remote url to be called. can be a reverse such as @Controller.action(params…)
  • Select the everyone favorite! If the observed select changes the target select is updated with remote data.
    1. observed: the id of the select to be observed
    2. target: the id of the select to be updated
    3. url: the remote url to be called. can be a reverse such as @Controller.action(params…) it must return Json data. renderJson method of Play! controller will make the day! the name attribute of the observed select and its actual value will be passed to the remote call as extra parameter
    4. value: the name of the property to be used as value of the target select’s options
    5. label:the name of the property to be used as label of the target select’s options
  • Observe updates a div when the value of a filed changes (useful for search as you type stuff)
    1. observed: the id of the field to be observed
    2. target: the id of the div to be updated
    3. url: the remote url to be called. can be a reverse such as @Controller.action(params…)
  • Form like the standard form but updates a div instead of refreshing the all page
    1. resultDiv the id of the div to be updated
    2. errorDiv the id to be updated in case of error
    3. action the remote url to be called. can be a reverse such as @Controller.action(params…)

Have Fun!