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 9321917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:57:36+00:00 2026-06-19T03:57:36+00:00

I’m making a real push to understand the async powers of Play but finding

  • 0

I’m making a real push to understand the async powers of Play but finding a lot of conflict with regard to places where async invocation fits and places where the framework seems to conspire against its use.

The example I have relates to form validation. Play allows for ad-hoc constraints to be defined – see this from the docs:

val loginForm = Form(
  tuple(
    "email" -> email,
    "password" -> text
  ) verifying("Invalid user name or password", fields => fields match { 
      case (e, p) => User.authenticate(e,p).isDefined 
  })
)

Nice and clean. However, if I’m using a fully async data access layer (e.g. ReactiveMongo), such a call to User.authenticate(...) would return a Future and I’m thus in the dark as to how I can utilise the power of both the built in form binding features and the async tools.

It’s all well and good to publicise the async approach but I’m getting frustrated that certain parts of the framework don’t play so well with it. If the validation has to be done synchronously, it seems to defeat the point of the async approach. I’ve come across a similar problem when using Action composition – e.g. a security related Action that would make a call to ReactiveMongo.

Can anyone shed any light on where my comprehension is falling short?

  • 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-19T03:57:37+00:00Added an answer on June 19, 2026 at 3:57 am

    Yes, validation in Play is designed synchronously. I think it’s because assumed that most of time there is no I/O in form validation: field values are just checked for size, length, matching against regexp, etc.

    Validation is built over play.api.data.validation.Constraint that store function from validated value to ValidationResult (either Valid or Invalid, there is no place to put Future here).

    /**
     * A form constraint.
     *
     * @tparam T type of values handled by this constraint
     * @param name the constraint name, to be displayed to final user
     * @param args the message arguments, to format the constraint name
     * @param f the validation function
     */
    case class Constraint[-T](name: Option[String], args: Seq[Any])(f: (T => ValidationResult)) {
    
      /**
       * Run the constraint validation.
       *
       * @param t the value to validate
       * @return the validation result
       */
      def apply(t: T): ValidationResult = f(t)
    }
    

    verifying just adds another constraint with user-defined function.

    So I think Data Binding in Play just isn’t designed for doing I/O while validation. Making it asynchronous would make it more complex and harder to use, so it kept simple. Making every piece of code in framework to work on data wrapped in Futures is overkill.

    If you need to use validation with ReactiveMongo, you can use Await.result. ReactiveMongo returns Futures everywhere, and you can block until completion of these Futures to get result inside verifying function. Yes, it will waste a thread while MongoDB query runs.

    object Application extends Controller {
      def checkUser(e:String, p:String):Boolean = {
        // ... construct cursor, etc
        val result = cursor.toList().map( _.length != 0)
    
        Await.result(result, 5 seconds)
      }
    
      val loginForm = Form(
        tuple(
          "email" -> email,
          "password" -> text
        ) verifying("Invalid user name or password", fields => fields match { 
          case (e, p) => checkUser(e, p)
        })
      )
    
      def index = Action { implicit request =>
        if (loginForm.bindFromRequest.hasErrors) 
          Ok("Invalid user name")
        else
          Ok("Login ok")
      }
    }
    

    Maybe there’s way to not waste thread by using continuations, not tried it.

    I think it’s good to discuss this in Play mailing list, maybe many people want to do asynchronous I/O in Play data binding (for example, for checking values against database), so someone may implement it for future versions of Play.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I want to construct a data frame in an Rcpp function, but when I

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.