从另一个动作中调用一个动作,而不是返回任何简单结果
def testSession = Action {
implicit request =>
val currentTimes = Calendar.getInstance().getTimeInMillis()
val validTimes = Long.parseLong(request.session.get("validTill").getOrElse("0"))
if(currentTimes>validTimes)
{
Ok("Session expired, Please log-in again")
}
else
{
//insert code here to call def saveDemographicDetailsBrowser = Action{}
}
如果登录未过期,我需要在else部分中插入代码以调用其他操作.接收json并点击的操作会将数据保存在db中.
I need to insert code in else section to call some other action if login has not expired. An action that receives the json and hit save the data in db.
如果您尝试从另一个Action调用一个Action,那么这仅表示您的设计有误.恕我直言,在这种情况下,您应该有一个具有核心功能的方法,并且动作都应调用该方法.
If you are trying to call an action from another Action then that simply means you have a wrong design. IMHO in such cases you should have a method which does the core functionality and both the Action's should make call to that method.
无论如何,如果您想调用另一个Action,则可以重定向:
Anyways if you wish to make a call to another Action, then you could redirect:
Redirect(routes.Dashboard.homePage)
如果问题是您希望通过在请求中放入新的json,然后使用此请求对Action
进行调用来对Action进行调用,那么这是严重不建议的,如果您仍然希望这样做,请查看 FakeRequest .
If the question is that you wish to make a call to Action by putting a new json in your request and then using this request to make a call to Action
, then that is seriously inadvisable and still if you wish to then have a look at FakeRequest.