I am uploading files into a list. however I want to be able to specify to which parameter I am uploading so next time I access it I see the files I uploaded into that path only:
for example I have this dropdown menu:
<ul class="dropdown-menu" role="menu">
<li><g:link controller='Document' action='list' params='[fruit:"apple"]'>apple</g:link></li>
<li><g:link controller='Document' action='list' params='[fruit:"blueberry"]'>bluberry</g:link></li>
<li><g:link controller='Document' action='list' params='[fruit:"strawberry"]'>strawberry</g:link></li>
<li class="divider"></li>
<li><g:link resource="gm">v4sa</g:link></li>
</ul>
if I click on apple. and I upload a file. I want to be able to see those files only for params.fruit == apple
which means in this URL only : http://localhost:8080/file_down/document/list?fruit=apple
if I go to the URL of blueberry, I could upload files also, but in the list I can only see files uploaded for bluberry:
here are my upload controllers:
class DocumentController {
def index = {
redirect(action: "list", params: params)
}
def list() {
params.max = 10
[documentInstanceList: Document.list(params), documentInstanceTotal: Document.count()]
}
def upload() {
def uploadedFile = request.getFile('file')
if(uploadedFile.isEmpty())
{
flash.message = "File cannot be empty"
}
else
{
def documentInstance = new Document()
documentInstance.filename = uploadedFile.originalFilename
//fileSize
documentInstance.fileSize = uploadedFile.size
documentInstance.fileSize = documentInstance.fileSize/(1024*1024)
documentInstance.fullPath = grailsApplication.config.uploadFolder + documentInstance.filename
uploadedFile.transferTo(new File(documentInstance.fullPath))
documentInstance.save()
}
redirect (action: 'list')
}
and this is my list.gsp that shows the files in the table, it is the same table for all of the different parameters, and same gsp page, just shows different files :
<tbody>
<g:each in="${documentInstanceList}" status="i" var="documentInstance">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td><g:link action="download" id="${documentInstance.id}">${documentInstance.filename}</g:link></td>
<td><g:link id="${documentInstance.id}">${documentInstance.fileSize}MB</g:link></td>
<td><g:formatDate date="${documentInstance.uploadDate}" /></td>
<td><span class="button"><g:actionSubmit class="delete" controller="Document" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span></td>
</tr>
</g:each>
</tbody>
What should I do to upload only into one specific parameter and show it only at that parameter ?
thank you !
Aucun commentaire:
Enregistrer un commentaire