I'm writing a grails (v2.4.4) app to store information on Songs in a music library. One of the "attributes" of a song is the "key". So I want to write a validation/lookup table (domain class) that will hold all valid keys. Since not everyone doing the data entry will automatically know what a staff with 1 Flat is the F Major scale/key I want to include a image of the staff as a comparison
(I can't paste the image of the staff, not enough "points", you can see a staff example in wikepedia if you are interested. http://en.wikipedia.org/wiki/F_major)
I can get this file stored into the MySQL table as a BLOB - grails does that just fine. But I can't for the life of me (using many of the examples I have found) to get the image to "show". All I see in the "Valid Key List" is the string of "bytes". can someone point me in the right direction please.
ValidKeys Domain Class:
package musicdb
class ValidKeys {
String musicalKey
String aka
byte[] staffImg
static constraints = {
musicalKey (unique: true, nullable: false)
aka (nullable: true)
staffImg (nullable: true, maxSize: (1024*1024))
}
}
ValidKeysControler: (standard "generated" controller)
package musicdb
import static org.springframework.http.HttpStatus.*
import grails.transaction.Transactional
@Transactional(readOnly = true)
class ValidKeysController {
static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
respond ValidKeys.list(params), model:[validKeysInstanceCount: ValidKeys.count()]
}
def show(ValidKeys validKeysInstance) {
respond validKeysInstance
}
def create() {
respond new ValidKeys(params)
}
@Transactional
def save(ValidKeys validKeysInstance) {
if (validKeysInstance == null) {
notFound()
return
}
if (validKeysInstance.hasErrors()) {
respond validKeysInstance.errors, view:'create'
return
}
validKeysInstance.save flush:true
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.created.message', args: [message(code: 'validKeys.label', default: 'ValidKeys'), validKeysInstance.id])
redirect validKeysInstance
}
'*' { respond validKeysInstance, [status: CREATED] }
}
}
def edit(ValidKeys validKeysInstance) {
respond validKeysInstance
}
@Transactional
def update(ValidKeys validKeysInstance) {
if (validKeysInstance == null) {
notFound()
return
}
if (validKeysInstance.hasErrors()) {
respond validKeysInstance.errors, view:'edit'
return
}
validKeysInstance.save flush:true
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.updated.message', args: [message(code: 'ValidKeys.label', default: 'ValidKeys'), validKeysInstance.id])
redirect validKeysInstance
}
'*'{ respond validKeysInstance, [status: OK] }
}
}
@Transactional
def delete(ValidKeys validKeysInstance) {
if (validKeysInstance == null) {
notFound()
return
}
validKeysInstance.delete flush:true
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.deleted.message', args: [message(code: 'ValidKeys.label', default: 'ValidKeys'), validKeysInstance.id])
redirect action:"index", method:"GET"
}
'*'{ render status: NO_CONTENT }
}
}
protected void notFound() {
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'validKeys.label', default: 'ValidKeys'), params.id])
redirect action: "index", method: "GET"
}
'*'{ render status: NOT_FOUND }
}
}
}