thk
thk

Reputation: 91

Unable to decode the urlMapping in Grails application

Problem: I am able to execute the default action(listLatest) of my Controller(ReviewMetricsController). But, I am not able to explicitly invoke other action(index) with form submission. I am using Grails 2.0.4 and running my application in development mode from Eclipse IDE with Grails plugin installed.

Detail: I have a form in my gsp as shown below

    <g:form name="queryForm"
        url="[controller:'reviewMetrics', action:'index']">
        <g:actionSubmit value="submit" />
    </g:form>

When I submit the above form, I get 404 error

The requested resource (/reviewmetricsapp/reviewMetrics/index) is not available

My Controller(reviewMetricsController.groovy) looks as shown below

package reviewmetricsapp

class ReviewMetricsController {

    static scope = "session"
    static defaultAction = "listLatest"
    def gatherMetricsService
    def grailsApplication
    def latestMetrics

    def index() {
        render(view:"dashboard", model: [model: latestMetrics])
    }

    def listLatest(){
        println grailsApplication.config.metricsapp.perlScript.loc
        latestMetrics = gatherMetricsService.getLastWeekMetrics()
        println "printing ${latestMetrics}"
        render(view:"showMetrics", model: [metrics: latestMetrics])
    }

}

And my urlMappings.groovy looks as shown below

class UrlMappings {

    static mappings = {
        "/$controller/$action?/$id?"{ constraints {
                // apply constraints here
            } }

        "/reviewMetrics/index"{
            controller="reviewMetrics"
            action="index"
        }

        "/"(view:"/index")
        "500"(view:'/error')
    }
}

Any help is appreciated

Upvotes: 0

Views: 240

Answers (1)

Chris
Chris

Reputation: 8109

  1. You do not need to change the URLMappings-file for your use-case. (remove the special case handling for reviewMetrics/index - its handled from the first rule)

  2. Please use the following form definition:

    <g:form name="queryForm"
       controller="reviewMetrics"
       action="index">
       [..]
    </g:form>
    
  3. Please double check that your action is not accessed - simply put a plain index.gsp and do not care inside the controller. I guess the error is somewhere else.

Upvotes: 1

Related Questions