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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:17:21+00:00 2026-05-26T09:17:21+00:00

When opening the url /users/{id}/foo I will display the view with a call to

  • 0

When opening the url

/users/{id}/foo

I will display the view with a call to

html.foo(userWithId)

In the controller method foo I want to make sure that id is the same as the loggedin user’s id and if not should redirect the user to

/users/{theLoggedInUsersId}/foo

using

html.foo(loggedInUser)

works fine but this is not a redirect, so the url in the browser still is

/users/{id}/foo

I want to really redirect so that the url is showing the correct id. I’m not sure how to do this. Using “Action” like this:

Action(foo(loggedInUsersId))

will get an error for using recursion without supplying a return type. Adding the return type play.template.Html to the controller method foo, will get a compiler error since Action returns a ScalaAction and not Html.

How should I do this. Should I even do it, am I stuck thinking about it in the wrong way?

Edit

The Redirect(…) works fine. But is it possible to do without it?
In pseudo-Scala:

def list(id: Long) = {
  if (some_criteria)
    html.list(user_with_id_equal_to_id)
  else if(another_criteria)
    list(another_user_id)
  else
    Action(Application.login)
}

The list(another_user_id) won’t work since it’s a recursive call and I have to supply a return type on the list method. Adding the return type play.templates.Html won’t work since that is not the return type of Action

Do you see what I’m getting at? If I instead of using a call to list uses html.list(user_with_another_id) then it won’t be a redirect and the url in the browser will still be /users/id/foo instead of /user/another_id/foo.

  • 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-26T09:17:21+00:00Added an answer on May 26, 2026 at 9:17 am

    There are two ways to go about doing this. The first is to use the Redirect return type.

    Redirect("/find/user/" + id)
    

    The way you want is to use the Action like you suggested.

    Action(findUser(id))
    

    This should work fine. Play actually resolves this call as URL and calls a redirect. So the first example I showed you is pretty much the same thing. The Action works better because it prevents you from having to change code if you change the url. We may need to see more of your code to see what’s going on.

    Here is a more clear example.

        def index( userId : Option[ String ] ) = {  
    
        Action(findCurrentUser(userId.getOrElse("test@test.com")))
    }
    
    def findCurrentUser(userId : String) = {
    
        User.find( "email = {email}" ).onParams( userId ).first() match {
    
            case Some( user ) => Json( user )
    
            case None => Error( "Could not find current user" )
        }
    }
    

    Reference: http://scala.playframework.org/documentation/scala-0.9.1/controllers#Returntypeinference

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

Sidebar

Related Questions

I am opening a URL in web view. I want to prevent it from
I just want to make sure that if I use the following, I am
I am using the python urllib2 library for opening URL, and what I want
I have the requirement to allow users to view the content of a document
that will allow my users to edit word documents locally in Word and have
I was using the java.net.URL.openStream() method to retrieve content from the server. I recently
I'm displaying some HTML with links in a UIWebView. I want the links to
I have a UITextView that is auto-detecting link URL's. Instead of opening it in
how to one page to another page without opening new window only url changed
I would like to split a custom url for app opening in iPhone into

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.