Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8706533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:38:13+00:00 2026-06-13T03:38:13+00:00

The setup: Using Play! framework v 2.0.4 The controller: def javascriptRoutes = Action {

  • 0

The setup:

Using Play! framework v 2.0.4

The controller:

  def javascriptRoutes = Action { implicit request =>
    Ok(
      Routes.javascriptRouter("jsRoutes")(
        routes.javascript.Admin.approve  
      )
    ).as("text/javascript")
  }

def approve(user: List[String]) = SecureAction('admin) { implicit ctx =>
    Logger.debug("Admin.approve: " + user.foldLeft("")(_ + "::" + _))
    user map { u =>
      User.approve(u)
    }
    Ok(Json.toJson(user))
  }

The view:

  function get_selected() {
      return  $.makeArray($(".user-selector").map(function (ind, user){
          if(user.checked) return user.name;
      }));
  }

 $("#button-approve").click(function(){
      jsRoutes.controllers.Admin.approve(get_selected()).ajax({
          success: function(data, status) {
              console.log("Users activated: " + data)
              for(i = 0; i < data.length; i++) {
                  id = "#" + data[i];
                  $(id + " > td > i.approved").removeClass("icon-flag").addClass("icon-check");
              }
              $(":checked").attr("checked", false);
          }
      });
  });

The routes:

PUT     /admin/users                controllers.Admin.approve(user: List[String])
GET     /admin/jsRoutes             controllers.Admin.javascriptRoutes

I also used the code mentioned in this question to allow binding of List[String] as a parameter.

The problem

The parameters are passed in a request reported like this:

PUT /admin/users?user=506b5d70e4b00eb6adcb26a7%2C506b6271e4b00eb6adcb26a8

The encoded %2C character being a comma. The controller interprets it as a single string because the debug line from the code above looks like this:

[debug] application - Admin.approve: ::506b5d70e4b00eb6adcb26a7,506b6271e4b00eb6adcb26a8

(using the default List.toString was misleading that’s why I used the foldLeft trick).

So

How to pass the list of checkbox selected users to the controller so it is interpretted as a list of strings, and not list of single string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:38:15+00:00Added an answer on June 13, 2026 at 3:38 am

    Ok. The problem was in the old implementation of QueryBinders that were missing the JavaScript part. The proper version is:

    package models
    
    import play.api.mvc.{JavascriptLitteral, QueryStringBindable}
    
    
    //TODO: remove when updating to 2.1                                                                                                                                                                                
    
    object QueryBinders {
    
      /**                                                                                                                                                                                                              
       * QueryString binder for List                                                                                                                                                                                   
       */
      implicit def bindableList[T: QueryStringBindable] = new QueryStringBindable[List[T]] {
        def bind(key: String, params: Map[String, Seq[String]]) = Some(Right(bindList[T](key, params)))
        def unbind(key: String, values: List[T]) = unbindList(key, values)
    
        /////////////// The missing part here...:
        override def javascriptUnbind = javascriptUnbindList(implicitly[QueryStringBindable[T]].javascriptUnbind)
      }
    
      private def bindList[T: QueryStringBindable](key: String, params: Map[String, Seq[String]]): List[T] = {
        for {
          values <- params.get(key).toList
          rawValue <- values
          bound <- implicitly[QueryStringBindable[T]].bind(key, Map(key -> Seq(rawValue)))
          value <- bound.right.toOption
        } yield value
      }
    
      private def unbindList[T: QueryStringBindable](key: String, values: Iterable[T]): String = {
        (for (value <- values) yield {
          implicitly[QueryStringBindable[T]].unbind(key, value)
        }).mkString("&")
      }
    
      /////////// ...and here
      private def javascriptUnbindList(jsUnbindT: String) = "function(k,vs){var l=vs&&vs.length,r=[],i=0;for(;i<l;i++){r[i]=(" + jsUnbindT + ")(k,vs[i])}return r.join('&')}"
    
      /**                                                                                                                                                                                                              
       * Convert a Scala List[T] to Javascript array                                                                                                                                                                   
       */
      implicit def litteralOption[T](implicit jsl: JavascriptLitteral[T]) = new JavascriptLitteral[List[T]] {
        def to(value: List[T]) = "[" + value.map { v => jsl.to(v)+"," } +"]"
      }
    
    }
    

    Now the query looks like this:

    PUT /admin/users?user=506b5d70e4b00eb6adcb26a7&user=506b6271e4b00eb6adcb26a8
    

    And finally everything works.

    Final note:

    In the Play! framework 2.1+ it should work without adding the code in the project sources. Actually the code is borrowed as-is from Play20/framework/src/play/src/main/scala/play/api/mvc/Binders.scala

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using the Play! framework and I've setup our Jenkins CI to run
I've setup my Play Framework 1.2.1 project to run from within IntelliJ using the
I'm using CoreAudio on iOS 5 to play MIDI files. I have everything setup,
Writing a Java application using the Play framework and need some HTTP-Live streaming. I
I had setup an app to play a video using the library suggested here
I am trying to embed videos using the Play Framework and JW Player. I
SETUP: Using Google Apps Script's UI (doGet) with tabPanel option. At the bottom of
Setup : Using PowerBuilder 6.5. I have a composite report (with a report header)
My current setup using hibernate uses the hibernate.reveng.xml file to generate the various hbm.xml
I have a datepicker control setup using the JQuery UI, I am also using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.