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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:20:34+00:00 2026-05-25T03:20:34+00:00

Some of my Play Framework views will accept normal request (GET via a link)

  • 0

Some of my Play Framework views will accept normal request (GET via a link) and ajax request (called from a javascript code if the user have js enabled).

My actual problem is that my code looks for the two possibilities in the same method, something like this :

public static void lostPassword() {
    HashMap<String, Object> ajax = new HashMap<String, Object>();

    validation.clear();

    validation.required("email", params.get("email"));
    validation.email("email", params.get("email"));

    if (!validation.hasErrors()) {
        Account account = Account.findAccount(params.get("email"));
        if (account != null) {
            // Send the email:
            Mails.lostPassword(account);

            if (request.isAjax()) {
                ajax.put("success", true);
                renderJSON(ajax);
            }
            else {
                renderTemplate("account/password/sent.html");
            }
        }

        validation.addError("email", "This email does not exists."); // TRANS
    }

    if (request.isAjax()) {
        ajax.put("success", false);
        ajax.put("validation", AjaxUtils.fromValidationErrorsToAjax(validation.errors()));
        renderJSON(ajax);
    }
    else {
        validation.keep();
        renderArgs.put("email", params.get("email"));
        renderTemplate("account/password/form.html");
    }
}

As you can see, I check for which type of request is made for returning a proper response, and I’m sure it’s not the best way to do it.

But how would you do?

I thought about making a private method that would do the work and return a boolean, but what happens for the Validation object? And does that mean I would have to make two other methods, one for the HTML request, an other for the AJAX request?

How do you do?

Thanks for your help!

  • 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-25T03:20:34+00:00Added an answer on May 25, 2026 at 3:20 am

    You are better off using content types. It allows you to use a single controller, and have multiple Temaplates, for outputting in a variety of formats. In my book, I used a standard HTML page, and an RSS page as two view over the same controller action and associated model data.

    The Play documentation does a good job of explaining how to use it. http://www.playframework.org/documentation/1.2.3/routes#content-types

    Basically, you can do it programatically or in your routes file, or by allowing play to figure it out by the content type by the Http request type. The later is set in your ajax request by specifically setting up JSON as the content type. This should be straightforward, especially if you are using jquery for your Ajax requests.

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

Sidebar

Related Questions

I'm trying to port some code from Play Framework Java to Play Framework Scala
I'm building some crude CMS-like functionality (to get acquinted with Play Framework). For this
I am trying to perform some custom validation with play framework but I don't
Is it possible to use the templating engine from the Play Framework in other
I'm trying to get started with the play web framework and its scala support,
I've just started with the Play Framework and I'm running into some problems using
Writing a Java application using the Play framework and need some HTTP-Live streaming. I
Possible Duplicate: Play Framework appending # = to redirect after Facebook auth via OAuth2?
I'm writing a selenium test using the Play! Framework and some tests have common
I've been trying to create a Web Service with play framework. I've searched some

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.