For example I've such gsp-code, this is table tag content:
<table class="table">
<thead>
<tr>
<th>Restaurant name</th>
<th>Booking date</th>
<th>Booking time from</th>
<th>Booking time till</th>
<th>Hall</th>
<th>Place in table</th>
<%-- <th>Price</th>--%>
<th></th>
</tr>
</thead>
<tbody>
<g:each in="${tableInfo}" var="table">
<tr>
<td>${table.cafeeName.cafeeName}</td>
<td>${new SimpleDateFormat("yyyy-MM-dd").format(table.reservationDate)}</td>
<td>${table.startTimeLimit.toString(timeForm)}</td>
<td>
<g:if test="${table.endTimeLimit != null}">
${table.endTimeLimit.toString(timeForm)}
</g:if>
<g:else>
<p>-</p>
</g:else>
</td>
<td>${table.hall}</td>
<g:if test="${table.places != 0}">
<td>${table.places}</td>
</g:if>
<g:else>
<td>-</td>
</g:else>
<%-- <td>${table.cost}</td>--%>
<td><g:link action="deleteReservedTable" params="[cafeeName: "${table.cafeeName.cafeeName}", cafeeAPI: "${table.cafeeName.apiInit}",
date: "${table.reservationDate }", startTime: "${table.startTimeLimit }", endTime: "${table.endTimeLimit }",
placesAmount: "${table.places }", cost: "${table.cost }", hall: "${table.hall}"]">Cancel</g:link></td>
</tr>
</g:each>
</tbody>
</table>
When I do an action, a row in table is delete, but when I reload page another row will be delete too. How to avoid it? May be, I must to clean GET/POST request? How to do it? Or better to attach a warning before deleting?
def deleteReservedTable(params){
try {
def user = Person.findByUsername(springSecurityService.currentUser.username)
ApiRequest apiRequest
if(params['cafeeAPI'] != ""){
apiRequest = ApiHandlerController.request(params['cafeeAPI'], "TO_DELETE", params)
def myPlace = ReservedTable.findByVisitorAndCafeeName(user, Cafee.findByApiInit(params['cafeeAPI']))
myPlace.delete(flush: true)
}else{
def myPlace = ReservedTable.findByVisitorAndCafeeNameAndPlaces(user, Cafee.findByCafeeName(params['cafeeName']), Integer.parseInt(params['placesAmount']))
def cafee = Cafee.findByCafeeName(params['cafeeName'])
def table = TablePlacesInfo.where {
placesInTableAmount == Integer.parseInt(params['placesAmount'])
hall {
hallName == params['hall']
cafee {
cafeeName == cafee.getCafeeName()
}
}
}.get()
myPlace.delete(flush: true)
if(table != null){
table.tableForReservationAmount += 1
cafee.totalReservationPlaces += 1
if(!table.save(flush: true)){
table.errors.each{
println it
}
}
}
if(!cafee.save(flush: true)){
cafee.errors.each{
println it
}
}
}
showReservedTableForVisitor()
} catch (Exception e) {
render (view:'error.gsp')
e.printStackTrace()
}
}
Your delete action deleteReservedTable
should redirect back to main view.
Basically it should be:
GET requests should be used only to retrieve data, POST can be used to update state on server