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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:02:54+00:00 2026-06-09T04:02:54+00:00

Is it possible to define optional parameter when rendering an scala template in Play

  • 0

Is it possible to define optional parameter when rendering an scala template in Play Framework 2?

My controller looks like this:

public static Result recoverPassword() {
    Form<RecoveryForm> resetForm = form(RecoveryForm.class);
    return ok(recover.render(resetForm));
    // On success I'd like to pass an optional parameter:
    // return ok(recover.render(resetForm, true));
}

My Scala template looks like this:

@(resetForm: Form[controllers.Account.RecoveryForm], success:Boolean = false)

Also tried:

@(resetForm: Form[controllers.Account.RecoveryForm]) (success:Boolean = false)

In both cases i got “error: method render in class recover cannot be applied to given types;”

  • 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-09T04:02:56+00:00Added an answer on June 9, 2026 at 4:02 am

    From Java controller you can’t omit assignation of the value (in Scala controller or other template it will work), the fastest and cleanest solution in this situation is assignation every time with default value, ie:

    public static Result recoverPassword() {
        Form<RecoveryForm> resetForm = form(RecoveryForm.class);
    
        if (!successfullPaswordChange){
            return badRequest(recover.render(resetForm, false));
        }
    
        return ok(recover.render(resetForm, true));
    }
    

    Scala template can stay unchanged, as Scala controllers and other templates which can call the template will respect the default value if not given there.

    BTW: as you can see, you should use proper methods for returning results from Play’s actions, see ok() vs badRequest() also: forrbiden(), notFound(), etc, etc

    You can also use flash scope for populating messages and use redirect() to main page after successful password change, then you can just check if flash message exists and display it:

    public static Result recoverPassword() {
        ...
        if (!successfullPaswordChange){
            return badRequest(recover.render(resetForm, false));
        }
    
        flash("passchange.succces", "Your password was reseted, check your mail");
        return redirect(routes.Application.index());
    }
    

    in ANY template:

    @if(flash.containsKey("passchange.succces")) {
        <div class="alert-message warning">
            <strong>Done!</strong> @flash.get("passchange.succces")
        </div>
    } 
    

    (this snippet is copied from Computer Database sample for Java, so you can check it on your own disk)

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

Sidebar

Related Questions

It's possible to define an alias in C# like this using kvp = System.Collections.Generic.KeyValuePair<string,
is it not possible to define a static const array? i would like to
Is it possible to define path with optional path variables. like the uri below:
Is it possible to define an Interface with optional implementation methods? For example I
In C#: Is it possible define a method that input parameter is any method
Is it possible to write template definition for this data type? myclass<int, myclass<int> >
Is it possible to define generic operators in Scala? Scala lets me map arbitrary
I know that in C# it is possible to define optional parameters. My question
Possible Duplicate: Define a method that has many (or infinite) arguments I have the
Possible Duplicate: Is it possible to define enumalpha? Is there any equivalent of Java

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.