2012-10-08 49 views
0

我正在使用Play 2.0與Scala,我想提取一些存儲在隱藏字段中的值。如何從錯誤案例中提取隱藏字段

控制器中的形式:

val recommendationForm: Form[Recommendation] = Form(
     mapping(
      "fromMail" -> email, 
      "fromName" -> nonEmptyText(5, 30), 
      "toMail" -> email, 
      "toName" -> nonEmptyText(5, 30), 
      "message" -> optional(text(0, 300)), 
      "productGroupId" -> nonEmptyText(), 
      "masterProductId" -> nonEmptyText() 
     ) 
     (Recommendation.apply)(Recommendation.unapply) 
    ) 

def doRecommend = xyzAction { implicit request => 
    recommendationForm.bindFromRequest.fold(
     errors => { 
     errors.data.map(x => println(x)) 
     BadRequest("") 
     }, 
     { 
     case (recommendation) => { 
     Ok("") 
     } 
     } 
    ) 
    } 

的情況下,建議類:

case class Recommendation(fromMail: String, fromName: String, toMail: String, toName: String, message: Option[String], productGroupId: String, masterProductId: String) 

的HTML:

@form(action = routes.Product.doRecommend) { 

       <input type="hidden" value="@{(productGroup \ "@id").text}" /> 
       <input type="hidden" value="@{(currentMasterProduct \ "@id").text}" /> 

    @inputText(field = recommendationForm("fromName"), 
         '_label -> "", 
         'placeholder -> Messages("recommendation.from.name"), 
         '_showConstraints -> false, 
         'class -> "text ui-widget-content ui-corner-all" 
         ) 

some more fields... 
} 

生成的隱藏字段的HTML:

<input type="hidden" value="74.75.652"> 

但我無法提取的誤差這兩個隱藏字段。它只打印其他五個。我怎樣才能提取隱藏的?

回答

0

我不得不這樣做是爲了給輸入字段的名稱屬性...

<input type="hidden" value="@{(productGroup \ "@id").text}" name="@recommendationForm("productGroupId").name" />