Grails Frameworks - Page 1
Forum section: electronics / general

author: bobcat2000
author_rank: Regular Contributor
timestamp: March 07, 2020, 06:58:17 pm
content: 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) {}

author: SiliconWizard
author_rank: Super Contributor
timestamp: March 09, 2020, 03:48:48 pm
content: 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.

author: bobcat2000
author_rank: Regular Contributor
timestamp: March 11, 2020, 03:00:39 pm
content: I thought Grails was popular. I guess not.

author: typoknig
author_rank: Regular Contributor
timestamp: March 21, 2020, 04:34:47 am
content: 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.

author: bobcat2000
author_rank: Regular Contributor
timestamp: March 21, 2020, 02:35:25 pm
content: 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}

author: typoknig
author_rank: Regular Contributor
timestamp: March 23, 2020, 07:07:04 pm
content: 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:<g:hidden field name="firstName" value="${userInfo?.firstName}">Then firstName would be an argument available in your save method.

author: bobcat2000
author_rank: Regular Contributor
timestamp: March 24, 2020, 02:36:45 am
content: 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?

author: typoknig
author_rank: Regular Contributor
timestamp: March 24, 2020, 11:56:52 am
content: 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.