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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:45:37+00:00 2026-05-22T16:45:37+00:00

Is there’s a way to get the value returned by a java controller method

  • 0

Is there’s a way to get the value returned by a java controller method in javascript in the views ?

what I want to do is:

i’m in view showX rendered by controller method X.show()

i want to create an object y so $.post(‘@{Y.create()}’)

now i need the id of the created object of type y to use it in the same view (showX).

is that possible?

  • 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-22T16:45:38+00:00Added an answer on May 22, 2026 at 4:45 pm

    It sound like what you need (although your question is very vague), is to return JSON from your controller method.

    Such as, in your controller, you can do

    public static void myActionOne() {
        renderJSON(myObject);
    }
    

    And then you will call myActionOne from your javascript using $.post. I would also suggest looking at the Play jsAction tag if you are not already using it. This will return a JSON representation of the object. You can then take whatever information you need and call a second action in the same way.

    Again, in the second action, I would suggest jsAction, as it makes passing parameters into your actions far easier.

    EDIT:
    Based on your edit, then all you need to do is in your controller method Y.create, do something like

    public static void create() {
        MyObject obj = new MyObject();
        obj.save();
        Long id = obj.id;
        renderJSON(id);
    }
    

    Obviously your code to create your object will be different, but you get the idea. You can then just take the data from the JQuery post response, and access the id that has been returned, using standard javascript.

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

Sidebar

Related Questions

There are a few ways to get class-like behavior in javascript, the most common
There are two popular closure styles in javascript. The first I call anonymous constructor
There is one table T ( id integer, primary key ( id). I want
There are lots of times where I'm not sure whether a particular method should
There's a thrird party app that needs to get information via custom http headers,
There are a few ways to do this in javascript. Foremost and most readable
There's a joke in there somewhere. Anyhoot. In the following code, the setForceVector method
There is a table with an int field - field_1. I want to insert
There is a conversion process that is needed when migrating Visual Studio 2005 web
There are two weird operators in C#: the true operator the false operator If

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.