I have a page that show all lists from "dataLansia" table. Like this one :
http://i61.tinypic.com/fliwcm.jpg
And then, I want to make a little improvement. When I pick a date from that date input and I press 'Cari' button, the page show me only the result from 'dataLansia' table where the attribute of 'Tanggal Data' match with the date I pick before. How to do that ?
Here's my stuff (controller, model, view) :
public class Application extends Controller {
//the other code
public static void rekap(){
List rekapProfil=dataLansia.findAll();
render(rekapProfil);
}
}
public class dataLansia extends Model{
public String tensi;
public int guladarah;
public int kolesterol;
public double asamurat;
#Unique
public java.util.Date tglData;
#Lob
public String keluhan;
#ManyToOne(cascade=CascadeType.ALL)
public potensi lans;
#ManyToOne(cascade=CascadeType.ALL)
public lansia lansia;
}
public class lansia extends Model {
#Unique
public int idLansia;
public String namaLansia;
public int umur;
#Lob
public String alamat;
#OneToMany(mappedBy="lansia",cascade=CascadeType.ALL)
public Collection<dataLansia> dataLansia;
public String toString(){
return namaLansia;
}
}
#{extends 'Template/Dashboard.html' /}
#{set title:messages.get('rekap.title') /}
<div class="row">
<input type="date" name="rekapTgl.tglData.format('yyyy-MM-dd')" /> <input type="submit" class="btn btn-info" value="Cari" />
<table class="table table-bordered table-striped responsive">
<thead>
<tr>
<th class="text-center">Tanggal Data</th>
<th class="text-center">ID Lansia</th>
<th class="text-center">Nama Lansia</th>
<th class="text-center">Umur</th>
<th class="text-center">Alamat</th>
<th class="text-center">Tensi<br />(mmHg)</th>
<th class="text-center">Gula Darah<br />(mg/dL)</th>
<th class="text-center">Kolesterol<br />(mg/dL)</th>
<th class="text-center">Asam Urat<br />(mg/dL)</th>
<th class="text-center">Keluhan</th>
<th class="text-center">Potensi / Tidak Potensi</th>
</tr>
</thead>
<tbody>
#{list items:rekapProfil, as:'rD'}
<tr>
<td class="text-center">${rD.tglData.format('dd-MM-yyyy')}</td>
<td class="text-center">${rD.lansia.idLansia}</td>
<td class="text-center">${rD.lansia.namaLansia}</td>
<td class="text-center">${rD.lansia.umur}</td>
<td class="text-center">${rD.lansia.alamat}</td>
<td class="text-center">${rD.tensi}</td>
<td class="text-center">${rD.guladarah}</td>
<td class="text-center">${rD.kolesterol}</td>
<td class="text-center">${rD.asamurat}</td>
<td class="text-center">${rD.keluhan}</td>
<td class="text-center">${rD.lans.namaPotensi}</td>
</tr>
#{/list}
</tbody>
</table>
#{else}
<br /><center><b><i>Belum ada lansia terimunisasi.</i></b></center>
#{/else}
</div>
Related
I need get data from html to controller with press button also Html data as list.
<thead>
<tr>
<th>Company Name</th>
<th>Book Name</th>
<th>Author</th>
<th>Price</th>
<th>Order</th>
</tr>
</thead>
<tbody>
<tr th:each="Books: ${Books }">
<td th:text="${Books.CompanyName}" />
<td th:text="${Books.BookName}" />
<td th:text="${Books.AuthorName}" />
<td th:text="${Books.Price}" />
<td th:button class="Order-Button" type="button" >Order</button> </td>
Also this is my Controller
#Autowired
private BookRep bookRep;
#RequestMapping(value = "/BookOrder")
ModelAndView submitBookOrder(){
ModelAndView mav = new ModelAndView("BookOrder");
mav.addObject("Books", bookRep.findAll());
return mav;
}
My expect to when user press take order button it will get row datas in controller
I wrote demo code for you. I think it will be useful for you. You can understand what you want by looking at the code
#GetMapping("/Books/{id}")
public String books(#PathVariable("id") Long id, Model model){
model.addAttribute("Books", bookService.getById(id));
return "book-list";
}
<-td> <-a th:href="#{/Books/{id}(id = ${book.id})}">
<-button type="submit" class="btn btn-info col-2" style="min-width: fit-content"> Books List<-/button>
Controller.java
#Controller
public class DashboardController {
#RequestMapping(value = "/delete", method = RequestMethod.GET)
public String deleteRow(#RequestParam("vehicleNo") int vehicleNo) {
userService.deleteRow(vehicleNo);
System.out.println("delete... " + vReg.getVehicleNo());
return ("/dashboard");
}
}
DaoImpl
public void deleteRow(Integer vehicleNo) {
String Sql = null;
Sql = "delete from vehiclereg where vehicleNo= " + vehicleNo;
jdbcTemplate.update(Sql, vehicleNo);
System.out.println("Deleted Record with vehicleNo = " + vehicleNo);
}
I think no need to passing 2 arguments to this function. Try this one...
jdbcTemplate.update(Sql);
same value returning,
JSP HomePage
<table id="myTable" border="1" cellspacing="10" >
<thead align="center" >
<tr>
<th data-priority="6">ID</th>
<th data-priority="5">Owner Name</th>
<th data-priority="4">Vehicle No</th>
<th data-priority="3">License No.</th>
<th data-priority="2">Address</th>
<th data-priority="1">Pollution Date </th>
<th data-priority="6">Action</th>
</tr>
</thead>
<c:forEach var="vreg" items="${vRegList}" varStatus="loop">
<tbody>
<tr>
<th scope="row">${loop.index+ 1}</th>
<td>${vreg.fullname}</td>
<td>${vreg.vehicleNo}</td>
<td>${vreg.licenceNo}</td>
<td>${vreg.address}</td>
<td>${vreg.date3}</td>
<td> <a class="glyphicon glyphicon-pencil" href=edit?vehicleNo=${vreg.vehicleNo}></a> |
<a class="glyphicon glyphicon-trash" onclick="return confirm('Are you sure you want to delete?')" href="delete?vehicleNo=${vreg.vehicleNo}"></a>|
<a class="glyphicon glyphicon-envelope" href="sms"></a> </td>
</tr>
</tbody>
Below is two lists and each list having different objects
public String execute(){
ArrayList<ViewCustomers> al = new Querydata().viewcust();
list = al;
ArrayList<bean> als = new Querydata().viewcust2();
list1 = als;
}
And now below is my JSP file:
<tbody class="table table-hover">
<d:iterator value="list" id="parent">
<tr id="demo">
<td><s:property value="#parent.cid"/></td>
<td><s:property value="#parent.customername"/></td>
<td><s:property value="#parent.cmobile"/></td>
<td><s:property value="#parent.travelfrom"/></td>
<td><s:property value="#parent.travelto"/></td>
<td><s:property value="#parent.date"/></td>
<d:iterator>
<td>
<select id="eid">
<option>select</option>
<option value='<s:property value="list1.EmpId"/>'></option>
</select>
</td>
<td>
<input type="text" name="name" value="" id=ename;>
</td>
</d:iterator>
<td>
<button type="button">GetEmployee</button>
</td>
</tr>
</d:iterator>
</tbody>
I am not getting the values of the lists.
I have a datatable inside a modal form and I need load it dynamically in serverside, I have a input where I catch value and need to send it via javascript (or other method different than get it from modelAttribute object)to load the table.
this is the datatable, I need the value stored in #idCProp input
<table th:if="${entity.formulario == 'formPerson'}" class="table dataTable" dt:deferLoading="10" id="propDT" dt:reloadSelector="#reloadProponent" dt:table="true" dt:sortable="true" dt:displaylength="10" dt:dom='ftip' dt:url="#{/person/loadProponents/__${entity.id}__/ **VALUE FROM INPUT**}" dt:serverside="true">
<thead>
<tr>
<th dt:property="entity.id" dt:renderFunction="nameAndLastName">Persona</th>
<th dt:property="entity.id" dt:sortable="false" dt:renderFunction="getProposalPost">Cargo</th>
<th dt:property="entity.id" dt:sortable="false" dt:renderFunction="getProposalInstitution">Institución</th>
<th dt:property="sendMethod.name" dt:sortable="false">Método de envío</th>
<th class="operations" dt:sortable="false" dt:property="id" dt:renderFunction="idToUrlProp"></th>
</tr>
</thead>
</table>
<input type="hidden" id="idCProp"/>
and this is the controller method
#RequestMapping(value = "/person/loadProponents/{idPerson}/{idCandidature}", method = RequestMethod.GET)
public #ResponseBody DatatablesResponse<Proposal> loadProponents(#PathVariable("idPerson") Long idPerson,#PathVariable("idCandidature") String idCandidature,
#DatatablesParams DatatablesCriterias criterias, HttpServletRequest request) {
//Do some stuff...
}
How can I send idCandidature variable?
I think the better way it's using dataTables API and request variables to do it.
Your view code would be :
<form id="searchForm">
<input type="hidden" id="idCProp"/>
<button class="btn btn-primary" type="button"
th:text="#{proposals.find}"
onclick="findProposals();"></button>
</form>
<table th:if="${entity.formulario == 'formPerson'}" class="table dataTable" dt:deferLoading="10" id="propDT" dt:reloadSelector="#reloadProponent" dt:table="true" dt:sortable="true" dt:displaylength="10" dt:dom='ftip' dt:url="#{/person/loadProponents/__${entity.id}__}" dt:serverside="true">
<thead>
<tr>
<th dt:property="entity.id" dt:renderFunction="nameAndLastName">Persona</th>
<th dt:property="entity.id" dt:sortable="false" dt:renderFunction="getProposalPost">Cargo</th>
<th dt:property="entity.id" dt:sortable="false" dt:renderFunction="getProposalInstitution">Institución</th>
<th dt:property="sendMethod.name" dt:sortable="false">Método de envío</th>
<th class="operations" dt:sortable="false" dt:property="id" dt:renderFunction="idToUrlProp"></th>
</tr>
</thead>
</table>
<script th:inline="javascript">
function findProposals() {
oTable_propDT.columns(2).search($("#idCProp").val());
... // more parameters if you need
oTable_propDT.columns(n).search($("#yoursearchparameterfrominput").val());
oTable_propDT.draw();
}
</script>
In your controller you already have everything you need :
#RequestMapping(value = "/person/loadProponents/{idPerson}", method = RequestMethod.GET)
public #ResponseBody DatatablesResponse<Proposal> loadProponents(#PathVariable("idPerson") Long idPerson, HttpServletRequest request) {
DatatablesCriterias criterias = DatatablesCriterias.getFromRequest(request);
DataSet<Proposal> dataset = proposalService.getProposalsDataset(criterias);
return DatatablesResponse.build(dataset, criterias);
}
Finally you just need to write proposalService#getProposalsDataset(DatatablesCriterias criterias) method that builds Dataset, I think it's nothing special.
I have some trouble with my jsp page's date value. Basically I have a date picker which allows me to pick date and save it to database. If I do not pick a date, the value is null which I check before setting it and passing it to the database. If its null, I modify it to a dummy date and then save it to database. This part works fine. But if the jsp page throws the not null validation, the value goes to the setter as null, gets modified there to the dummy value and reflected back in the form. I don't want that dummy value to be visible to the user. So is there any way I can put a check on the jsp page so that if the value is a dummy date value it will be visible as null to the user?
<b>Order Information</b>
<table>
<tr>
<td align="left"><form:label for="orId" path="orId" cssErrorClass="error">* Order Id :</form:label></td>
<td align="left"><form:input path="orId" size="35" maxlength="35" /> <form:errors path="orId" /></td>
</tr>
<tr>
<td align="left"><form:label for="orServicetag" path="orServicetag" cssErrorClass="error">* Service tag:</form:label></td>
<td align="left"><form:input path="orServicetag" size="35" maxlength="35" value= "${ticketList.ticServicetag}"/> <form:errors path="orServicetag" /></td>
</tr>
<tr>
<td align="left"><form:label for="orOwnerSUUsername" path="orOwnerSUUsername" cssErrorClass="error">* SU UserName:</form:label></td>
<td align="left"><form:input path="orOwnerSUUsername" id="suusnm" size="35" maxlength="35" value= "${ticketList.ticOwnerSuUsername}"/> <form:errors path="orOwnerSUUsername" /></td>
</tr>
<tr>
<td align="left"><form:label for="orTicId" path="orTicId" cssErrorClass="error">* Ticket Id</form:label></td>
<td align="left"><form:input path="orTicId" id="ticcrdt" size="35" maxlength="35" value= "${ticketList.ticId}"/> <form:errors path="orTicId" /></td>
</tr>
<tr>
<td align="left"><form:label for="orTicCreatedDate" path="orTicCreatedDate" cssErrorClass="error">* Ticket Date (YYYY-MM-DD):</form:label></td>
<td align="left"><form:input path="orTicCreatedDate" size="35" maxlength="35" value= "${ticketList.ticDate}"/> <form:errors path="orTicCreatedDate" /></td>
</tr>
<tr>
<td align="left"><form:label for="orPartOrdered" path="orPartOrdered" cssErrorClass="error">* Part Name :</form:label></td>
<td align="left"><form:input path="orPartOrdered" size="35" maxlength="35" /> <form:errors path="orPartOrdered" /></td>
</tr>
<tr>
<td align="left"><form:label for="orOrderedDate" path="orOrderedDate" cssErrorClass="error">* Part Ordered Date (YYYY-MM-DD):</form:label></td>
<td align="left"><form:input path="orOrderedDate" id="datepicker1" size="35" maxlength="35" /> <form:errors path="orOrderedDate" /></td>
</tr>
<tr>
<td align="left"><form:label for="orRecievedDate" path="orRecievedDate" cssErrorClass="error"> Part Received Date (YYYY-MM-DD):</form:label></td>
<td align="left"><form:input path="orRecievedDate" id="datepicker2" size="35" maxlength="35" /> <form:errors path="orRecievedDate" /></td>
</tr>
<tr>
<td align="left"><form:label for="orStatus" path="orStatus" cssErrorClass="error">* Order Status:</form:label></td>
<td align="left">
<select name="orStatus" id = "orStatus" id="slectboxid1">
<option value = "">---Select---</option>
<option value="Open">Open</option>
<option value="Progress">Progress</option>
<option value="Part Ordered">Part Ordered</option>
<option value="Part Arrived">Part Arrived/ Received</option>
<option value="Waiting for Owner's computer">Waiting for Owner's computer</option>
<option value="Installation">Installation in progress</option>
<option value="Closed">Closed</option>
</select>
<form:errors path="orStatus" /></td>
</tr>
</table>
<div align="center" style="margin-top:15px;" >
<form action="OrderDatabase" method="get">
<input type="submit" name="submit" value="View Order"/>
<input type="submit" name="save" value="save"/> |
<input type="reset" name="reset"/>
</form>
</div>
</form:form>
The Code for the ticketDetailsBean is as follows:
package com.helplaw.beans;
//import java.sql.*;
import java.util.Date;
public class OrderDetailsBean {
private String orId;
private String orPartOrdered;
private Date orTicCreatedDate;
private Date orOrderedDate;
private Date orRecievedDate;
private String orOwnerSUUsername;
private String orServicetag;
private String orStatus;
private int orTicId;
public String getOrId() {
return orId;
}
public void setOrId(String orId) {
this.orId = orId;
}
public String getOrPartOrdered() {
return orPartOrdered;
}
public void setOrPartOrdered(String orPartOrdered) {
this.orPartOrdered = orPartOrdered;
}
public Date getOrTicCreatedDate() {
return orTicCreatedDate;
}
public void setOrTicCreatedDate(Date orTicCreatedDate) {
this.orTicCreatedDate = orTicCreatedDate;
}
public Date getOrOrderedDate() {
return orOrderedDate;
}
public void setOrOrderedDate(Date orOrderedDate) {
this.orOrderedDate = orOrderedDate;
}
public Date getOrRecievedDate() {
return orRecievedDate;
}
public void setOrRecievedDate(Date orRecievedDate) {
if(orRecievedDate == null){
System.out.println("d11:" + orRecievedDate);
this.orRecievedDate = new Date(000000001);
}
else if(orRecievedDate.toString().equals("1969-12-31")){
System.out.println("d12:" + orRecievedDate);
this.orRecievedDate = null;
}
else{
System.out.println("d13:" + orRecievedDate);
this.orRecievedDate = orRecievedDate;
}
}
public String getOrOwnerSUUsername() {
return orOwnerSUUsername;
}
public void setOrOwnerSUUsername(String orOwnerSUUsername) {
this.orOwnerSUUsername = orOwnerSUUsername;
}
public String getOrServicetag() {
return orServicetag;
}
public void setOrServicetag(String orServicetag) {
this.orServicetag = orServicetag;
}
public String getOrStatus() {
return orStatus;
}
public void setOrStatus(String orStatus) {
this.orStatus = orStatus;
}
public int getOrTicId() {
return orTicId;
}
public void setOrTicId(int orTicId) {
this.orTicId = orTicId;
}
}
Just remove the NULL validation because it will never be null in your case where you are always setting a dummy value.
Alternatively, you can achieve it using hidden input field.
Steps to follow:
create hidden input fields one for each date input field.
set the value in hidden input field if value is changed in actual date input field using JavaScript
now set the dummy value in hidden input field rather than actual input field if value is null
read values from hidden input fields to save it in database
Note: swap the path attribute date input field with hidden input fields so that it will be picked from hidden input fields when form is submitted.