2017-03-04 46 views
0
class InstitutionController extends Controller { 
    def updateInstitution = Action { implicit request => 
     { 
      request.body.asJson.get.validate[GallreyJsonValidationForUpdate].fold(
      valid = { 
       updateInstitution => 
       { 
         Redirect(routes.GalleryController.updateGallreyObject()).flashing("uuid"- >updateInstitution.uuid,"institutionName"->updateInstitution.institutionName,"details"->updateInstitution.details) 
       } 
      }, 
      invalid = { 
       errors => 
       { 
        val json=commonUtils.getResponse(Http.Status.BAD_REQUEST, ServerResponseMessages.VALIDATION_FAILED,JsError.toJson(errors)) 
        log.error("sending error in json{}", json) 
        BadRequest(json) 
       } 
      }) 
     } 
     } 

這就是我重定向到行動不重定向到在遊戲的框架另一個Action

class GalleryController extends Controller { 
def updateGallreyObject = Action { implicit request => 
    { 
     val uuid=request.flash.get("uuid") 
     val institutionName=request.flash.get("institutionName") 
     val details=request.flash.get("details") 
     Ok("some details") 
}} 
} 

這裏的行動是捲曲的文件,我使用

contentType="Content-type: application/json"; 

data='{ "uuid" : "123" , "institutionName" : "abc" , "details" : "some details" 

}'; 
echo " " 
echo "------------------ Sending Data ------------------" 
echo " " 
echo "Content-Type : " $contentType 
echo "Data : " $data 


echo " " 
echo "------------------  Response  ------------------" 
echo " " 
echo " " 


curl --include --request POST --header "Content-type: application/json" --data "$data" http://localhost:9000/institution/update 

響應我我得到的是

HTTP/1.1 303 See Other 
Location: /gallery/update 
Set-Cookie: PLAY_FLASH=uuid=123 &institutionName=abc&details=some+details; Path=/; HTTPOnly 
Date: Sat, 04 Mar 2017 14:40:29 GMT 
Content-Length: 0 

這裏是路線

POST /institution/update         controllers.InstitutionController.updateInstitution 

爲什麼不重定向到updateGallreyObject操作?我在做什麼錯了,請幫幫忙,我希望它重定向到updateGallreyObject行動與數據請大家幫忙,我期待這個迴應「某些細節」

更新我已經有了這條路線

POST /gallery/update         controllers.GalleryController.updateGallreyObject 

回答

0

因爲你需要爲您的updateGallreyObject路由映射。

GET /galery     controllers.GalleryController.updateGallreyObject 

P.S.在發佈之前重新格式化您的代碼。您可能想要使用外部格式化程序,如Scalariform或Scalafmt。

+0

我有它已添加它路由文件 – swaheed

0

嘗試使用matchfold,就像文檔中:https://www.playframework.com/documentation/2.3.x/ScalaJsonCombinators#Putting-it-all-together

request.body.asJson.get.validate[GallreyJsonValidationForUpdate] match { 
    case s: JsSuccess[GallreyJsonValidationForUpdate] => { 
    val updateInstitution: GallreyJsonValidationForUpdate = s.get 

    Redirect(routes.GalleryController.updateGallreyObject()).flashing("uuid"- >updateInstitution.uuid,"institutionName"->updateInstitution.institutionName,"details"->updateInstitution.details) 
    } 
    case e: JsError => { 
    val json=commonUtils.getResponse(Http.Status.BAD_REQUEST, ServerResponseMessages.VALIDATION_FAILED,JsError.toJson(errors)) 
    log.error("sending error in json{}", json) 
    BadRequest(json) 
    } 
}