Grails - URL mapping / default action and stream

Question -

I noticed that some of the applications I'm testing with have calls to a different view / controller from the submit file, but when this page is displayed, instead of seeing:

$ controller / $ page

I see:

$ Controller / index

Is this a problem with the URL mapping configuration? Default action? Just curious, because it looks like matching a default URI instead of the actual action.

view code:

<table> .. <g:actionSubmit class="stats" action="stats" value="View Stats"/> .. </table 

controller:

 def stats() { def teamId = Team.get(params.id) def allPlayers = Player.withCriteria { eq('team', teamId) and { eq('isActive', true) } } [allPlayers:allPlayers, teamId:params.id] } 

UrlMapping:

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

Edit

I really understood what it is. This bothers me even more.

The grailsSubmit action has an action associated with it. This form was just a normal form, without calling:

 <g:form> <g:actionSubmit class="stats" action="stats" value="View Stats"/> <g:actionSubmit class="schedule" action="schedule" value="View Schedule"/> <g:form> 

Thus, by default, the form redirects the action to $ controller / index. If you add an action call to the g: form tag, these two buttons will go to the correct page, but the URI will now be $ controller / $ g: form_action.

I think that I do not get the actionSubmit action point if the g: form is required as a wrapper.

+6
source share
1 answer

Yes, index is the default action for all controllers. Therefore, if you do not specify one, this is the page on which you will land for the controller.

This is discussed in more detail on the website. Namely, the rules:

  • If only one action is present, the default URI for the controller maps to this action.
  • If you define an index action, which is an action that processes requests when no actions are specified in the URI / workbook.
  • Alternatively, you can explicitly set it using the defaultAction property:

    static defaultAction = "list"

+4
source

Source: https://habr.com/ru/post/913630/


All Articles