EEVblog Electronics Community Forum

Products => Computers => Programming => Topic started by: bobcat2000 on March 07, 2020, 06:58:17 pm

Title: Grails Frameworks
Post by: bobcat2000 on March 07, 2020, 06:58:17 pm
I start using Grails.

I understand the concept of the Params.  You POST the values from the view.  The values are in the Params variable.  Just like anything HTML.

However, I don't understand the concept when you pass values to the controller as an argument.  What do you type in the View to make the view POST the values as an argument to the controller?  Where are the values in "mySaveData" coming from for example?

Any pointer is appreciated!  Thanks!



def save(mySaveData) {

}
Title: Re: Grails Frameworks
Post by: SiliconWizard on March 09, 2020, 03:48:48 pm
Had never heard of Grails. It's there: https://grails.org/

Sorry, but I think you won't find many people here to answer your questions. It's too specific IMO (web application development), and you'd probably have much better luck on a purely software developement forum - maybe even better yet, a web development forum.
Title: Re: Grails Frameworks
Post by: bobcat2000 on March 11, 2020, 03:00:39 pm
I thought Grails was popular.  I guess not.
Title: Re: Grails Frameworks
Post by: typoknig on March 21, 2020, 04:34:47 am
Grails is an MVC framework which stands for Model View Controller. The most basic use case is that you send a request to a Controller and it gets "some data" and renders that data in a View. The "some data" it gets is an instance of a Model. So the direct answer to your question of "where are the values coming from" is that they are coming from the instance of the Model the Controller queried. That instance is available in the View for you to interact with.
Title: Re: Grails Frameworks
Post by: bobcat2000 on March 21, 2020, 02:35:25 pm
Thanks for you reply.  I thought this topic is dead.


I understand the concept.  However, I don't understand this particular mechanic for how this is written in Grails.

Normally, the View POST back the values to the Controller.  The Controller will get the values from the params variable.

save() {
    def myFirstName = params.firstName
}

I have been seeing a save() function with an argument.  I don't understand this syntax.  What and where do you enter this "userInfo"?  What is the syntax?   

save(userInfo) {
   def myFirstName = userInfo.firstName
}
Title: Re: Grails Frameworks
Post by: typoknig on March 23, 2020, 07:07:04 pm
When I've done what you are describing it has been via a hidden field and for a single value, not an object (I.e. a parameter of the userInfo object, not the entire userInfo object). In your view's form tag which has a POST method you would add something like this assuming userInfo was available in your view in the first place:

Code: [Select]
<g:hidden field name="firstName" value="${userInfo?.firstName}">

Then firstName would be an argument available in your save method.
Title: Re: Grails Frameworks
Post by: bobcat2000 on March 24, 2020, 02:36:45 am
Ah!  I see!

Thanks for the pointer.

I may be wrong.  But... Doesn't "params" already has all those variables hidden or not POST back to the controller?  Why do it like this with an extra argument?



Title: Re: Grails Frameworks
Post by: typoknig on March 24, 2020, 11:56:52 am
You are correct that you don't need to pass info to a Controller that is already in params. This is for passing additional info, like maybe the ID of some other object or some additional value that isn't a form field.