Sag
Sag

Reputation: 73

how to make layout work in grails when link has id (or not)

The following is my code in land.gsp page.

 <table style="padding: 10 ">
                <thead>
                    <tr style="color: blue">
                        <td>Gname</td>
                        <td>Gowner</td>
                        <td>Device number</td>
                        <td>Edit </td>
                        <td>Delete </td>


                    </tr>
                </thead>
                <tbody>
                <g:each in="${Groups.list()}" status="i" var="groupsInstance">
                <g:set var="myid" value="${groupsInstance.id}"></g:set>
                    <tr class="${(i % 2) == 0 ? 'even' : 'odd'}">

                        <td>${fieldValue(bean: groupsInstance, field: "gname")}</td>
                        <td>${fieldValue(bean: groupsInstance, field: "gowner")}</td>
                        <td>${fieldValue(bean: groupsInstance, field: "devicenum")}</td>
                        <td><g:link action="edit" id="${groupsInstance.id}">Edit</g:link></td>
                        <td><g:link action="deleteme" id="${groupsInstance.id}">Delete</g:link></td>

                    </tr>
                </g:each>
                </tbody>
            </table> 

But When I click on edit The layout of the page is not working( javascript, images, styles). But the id get passed to the edit.gsp page correctly. When I change

<td><g:link action="edit" id="${groupsInstance.id}">Edit</g:link></td>

to

<td><g:link action="edit" >Edit</g:link></td>

that is without passing id and clicking on edit will give a page with correct Layout. Following is my edit action

def edit(Long id) {
        def groupsInstance = Groups.get(id)
        if (!groupsInstance) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'groups.label', default: 'Groups'), id])
            redirect(action: "list")
            return
        }

        [groupsInstance: groupsInstance]
    }

Where I went wrong? I want to pass the id to edit page with all correct layout.

Upvotes: 0

Views: 242

Answers (3)

Jeff Scott Brown
Jeff Scott Brown

Reputation: 27220

From looking at your edit action it looks like if no id is supplied then you redirect to the list action and you say the layout is fine there. If the id is specified (and it is valid) you are rendering the edit view. I expect that the problem is in your edit.gsp which is not currently shown in your description.

Upvotes: 0

Daniel Wondyifraw
Daniel Wondyifraw

Reputation: 7713

Try to adopt with below option based on your preference :

<g:link action="/conference/participated" id="${it.conference.id}" 
               params="[foo: 'bar', bar: 'foo']">My Link!</g:link>

I see in your code that when

def groupsInstance = Groups.get(id)
        if (!groupsInstance) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'groups.label', default: 'Groups'), id])
            redirect(action: "list")
            return

You have redirected it to a list page , am sure list page has different layout setting and that is the change , please check on that and let me know!

Upvotes: 1

stenix
stenix

Reputation: 3106

Try to view the source html in your browser, that might give you a clue to what is wrong.

Upvotes: 2

Related Questions