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?
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
And then you will call
myActionOnefrom your javascript using$.post. I would also suggest looking at the PlayjsActiontag 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
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.