Grails won't retrieve single item from list using get(params.id) -
i have table input information displayed, when click name of want go new page displays item clicked , not everything.
here controller...
class recipecontroller { def index() { def recipe = recipes.list() //recipes grails domain [recipe: recipe] } def newrecipeform() { } def createrecipe() { def r = new recipes(name: params.name, course: params.course, diet: params.diet) r.save() redirect(action:"index") } def deleterecipe() { def r = recipes.get(params.id) r.delete() redirect(action:"index") } def showrecipe() { def rec = recipes.get(params.id) [recipe: rec] }
}
my index.gsp recipe name clickable should redirect id new page displays recipe info.
<g:each var="recipes" in="${recipe}"> <tbody> <tr> <td><g:link action="showrecipe" id="${recipes.id}">${recipes.name}</g:link></td> </tr> </tbody> </g:each>
and showrecipe.gsp recipe should displayed itself...but keeps displaying of them add
<g:each var="rec" in="${recipe}"> <tbody> <tr> <td>${rec.name}</td> </tr> </tbody> </g:each>
any guidance awesome! thanks
i first error in index.
it recipe.id have retrieving id´s , sending them in link. should not use uppercase in property name, compiler might think of property class. code should more like:
<tr> <td><g:link action="showrecipe" id="${recipes.id}">${recipes.name}</g:link></td> </tr> </g:each>
add println(params) or log.info(params) in show() action print params , see receiving view.
also careful naming conventions. might want change recipe recipelist or something, , recipes recipeinstance or recipe. make code more readable, , make easier you.
edit
as @nitin dhomse said need access data of single recipe don´t need
<g:each var="rec" in="${recipe}">
in show.gsp.
it more like
<table> <tbody> <tr> <td>${recipe?.id}</td> <td>${recipe?.name}</td> .... </tbody> </table>
also, should either redirect in show() action if dont find recipe instance or access properties $(recipe?.name) in show.gsp, otherwise nullpointer exceptions.
Comments
Post a Comment