0
我想顯示一個錯誤消息,正好位於它下面的單個字段。但是在文檔中找不到如何設置它。播放框架:如何爲動態表單中的特定字段設置錯誤消息
我的控制器操作:
操作1:以表格
public static Result retrieveEcommerceTransaction(Long id) {
Logger.debug("InstantCheck:retrieveEcommerceTransaction()-Retrieving transaction for txn id : " + id);
if(id != null && (id instanceof Long)) {
EcommerceRequestManager ecomRequestManager = new EcommerceRequestManager();
CustomerTransactionProfile customerTransactionProfile = ecomRequestManager.populateCustomerTxnProfile(id);
Cache.set(String.valueOf(id), customerTransactionProfile);
if(customerTransactionProfile != null) {
instantCheckForm = instantCheckForm.fill(customerTransactionProfile);
return ok(views.html.instantcheck.index.render(instantCheckForm));
}
}
return badRequest(Constants.STATUS_CODE_MISSING_PARAMETERS);
}
行動2包裹模型創建初始視圖:在圖形式被提交時被調用。使用動態表單獲取表單值。
public static Result checkLoanEligibility() {
String actionUrl = null;
DynamicForm form = Form.form().bindFromRequest();
String pan = form.get("n_pan");
if(pan.isEmpty() || pan.length() != 10) {
form.reject(new ValidationError("pan", "Invalid PAN value. Please enter a valid PAN value"));
} else {
actionUrl = <code for calling manager class for post processing.....>
}
return ok(actionUrl);
}
檢視:
<div>
<div>
<label for="">PAN</label>
<div>
<input id="i_pan" type="text" name="n_pan" value="@instantCheckForm.field("PAN").value()"/>
@for(error <- form("pan").errors) {
<p>@error.message</p>
}
</div>
</div>
錯誤消息:
not found: value form
在線路
@for(error <- form("pan").errors) {
我遵循Play文檔來創建這段代碼。使用form(「pan」)錯誤時出現什麼問題?
是否有任何模板可以顯示如何使用動態表單和表單包裝模型來創建和處理HTML表單?
問候, 蘇拉傑