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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:03:05+00:00 2026-06-02T21:03:05+00:00

I have a play template in which the most typical scenario for a parameter

  • 0

I have a play template in which the most typical scenario for a parameter is “null”.
I have understood that idiomatic Scala favors Option instead.
My first intuition coming from java would be using null.

Case with null:
In Controller

views.html.addPost(errors.errorsAsJson)

In View

@(errors: play.api.libs.json.JsValue = null) 
...
@if(errors != null){@errors}

Case with Option:
In Controller

views.html.addPost(Option(errors.errorsAsJson))

In View

@(errors: Option[play.api.libs.json.JsValue] = None)
...
@{errors match {
      case None => {}
      case _ => {errors.get}
    }
}

Update: I got it now.
Instead of:

@{errors match {
    case None => {}
    case _ => {errors.get}
 }
}

I could just do

@errors

Update 2:
Apparently I didn’t have to do the null check with null either? Maybe somePlay framework magic? Calling a null variable worked without exception.

  • 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-02T21:03:06+00:00Added an answer on June 2, 2026 at 9:03 pm

    The reason Option is less verbose is that you don’t need to do those null checks. In other words, your match/case verbosity is unnecessary.

    Let’s assume we have these two variables:

    val x: Option[Int] = Some(5)
    val y: Option[Int] = None
    

    If we want to call a function things that are Some rather than None, we don’t need to null-check:

    x foreach println  // prints 5
    y foreach println  // nothing printed
    

    Or if we want to apply a function and get a new result, it’s similar, and keeps track of whether the input was present or not.

    val f = (i: Int) => i + 1
    x map f  // Some(6)
    y map f  // None
    

    There are plenty more examples of how Option cleans things up, but this should give you an idea.

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

Sidebar

Related Questions

If I have some erroneous code, commented in a *scala.html template file in Play,
I have a play appliaction that works if It is the root of the
I have a Play Framework (1.2.4) project with PlayMorphia that has two different database
I am making an App in which i have to play music from iPod
Suppose I have an autolocker class which looks something like this: template <T> class
I have a WebMethod that looks like this which is used to populate a
I have a template that has some Javascript used to generate graphs in the
I have come from using the Play! Framework where putting links in a template
I have a ComboBox. Without changing the template, is there a way that I
I have an RJS template that I use to essentially do the following: Fade

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.