I have a model representation of my view named ApplicationModel.class
. I have a search map that takes all the parameter in my search form.
public class AppModel {
// Contain the search parameters input in view
public Map<String, String> search;
In my index.hmtl.scala i have:
@linkSearch(newPage:Int) = @{
routes.Application.search(newPage)
}
<form method="GET" action='@linkSearch(currentPage.getPage.get("intCurrPage"))'>
<div class = "search-row search-input">
<label for="emp_first_name"> FIRST NAME </label>
<input type="text" id="emp_first_name"
name='@appModel("search['empFirstName']").name'
value='@currentPage.getSearch.get("empFirstName")'/>
<input type="hidden" name="@appModel("search['exactFirstName']").name" value="0" />
<input type="checkbox" name='@appModel("search['exactFirstName']").name' value="1"/>
<p> Exact Match </p>
</div>
<div class = "search-row search-input">
<label for="emp_last_name"> LAST NAME </label>
<input type="text" id="emp_last_name"
name='@appModel("search['empLastName']").name'
value='@currentPage.getSearch.get("empLastName")'/>
<input type="hidden" name="@appModel("search['exactLastName']").name" value="0" />
<input type="checkbox" name='@appModel("search['exactLastName']").name' value="1"/>
<p> Exact Match </p>
</div>
</div>
</form>
In my controller Application.class
i have a search action:
/* form representation of AppModel.class */
public static Form<AppModel> appModelForm = Form.form(AppModel.class);
/**
* Handle the search submission form
*
* @param pageNum Current page number
* @return redirect back to list
*/
@Transactional(readOnly = true)
public static Result search(int pageNum) {
appModelForm = appModelForm.bindFromRequest();
System.out.println(appModelForm.data().get("search['exactFirstName']"));
System.out.println(appModelForm.data().get("search['exactLastName']"));
return redirect(routes.Application.list(pageNum);
}
how can i return a value of 1 if checkbox is search and 0. I tried the hidden and checkbox with the same name method but it is not working in my code. it always return 0. if i have something wrong with my code kindly correct me im only a newbie at this. thank you.
Aucun commentaire:
Enregistrer un commentaire