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

  • Home
  • SEARCH
  • 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 7690255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:21:14+00:00 2026-05-31T20:21:14+00:00

In my model all associated accounts are Long not normal integers. However, when handling

  • 0

In my model all associated accounts are Long not normal integers. However, when handling the Scala form in the new Play! 2.0 I can only validate an Int number in a form and not a Long.

http://www.playframework.org/documentation/2.0/ScalaForms

Take the following form:

val clientForm: Form[Client] = Form(
    mapping(
      "id" -> number,
      "name" -> text(minLength = 4),
      "email" -> optional(text),
      "phone" -> optional(text),
      "address" -> text(minLength = 4),
      "city" -> text(minLength = 2),
      "province" -> text(minLength = 2),
      "account_id" -> number
    )
    (Client.apply)(Client.unapply)
  )

Where you see account_id I want to apply a Long, so how could I cast that in the simplest way possible? The Client.apply syntax is awesome for its simplicity but I’m open to options like mapping. Thanks!

  • 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-05-31T20:21:15+00:00Added an answer on May 31, 2026 at 8:21 pm

    Found a really awesome way to do this that looks like is missing from the documentation I linked in the question.

    First, pull in Play! formats:
    import play.api.data.format.Formats._

    Then when defining the Form mapping use of[] syntax

    and then the new form val will look like:

    val clientForm = Form(
        mapping(
          "id" -> of[Long],
          "name" -> text(minLength = 4),
          "address" -> text(minLength = 4),
          "city" -> text(minLength = 2),
          "province" -> text(minLength = 2),
          "phone" -> optional(text),
          "email" -> optional(text),
          "account_id" -> of[Long]
        )(Client.apply)(Client.unapply)
      )
    

    Update: Using optional()

    After further experimentation, I discovered that you can mix of[] with the Play! optional to meet the optional variables defined in your class.

    So assume that the account_id above is optional…

    "account_id" -> optional(of[Long])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a registration form. I have a model for all
What is the importance of JTable model.Does all the swing components has model associated
My rails app has a simple model Links which tracks all the Urls associated
*Note to view all code, follow the link I am creating new accounts. Each
Using Model->find('all') returns an array with the following structure: array( 0 => array('Model1' =>
If I have Model.objects.all() I want to get only one object for any content_object=foo,
When the .net 2.0 framework first came out, the provider model was all the
I am writing an objective-c model to hold all of the data parsed from
All the examples I could find of flexible box model show stuff expanding either
I have the model Member that contains all informations about the registered member on

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.