groovy.lang.MissingPropertyException - grails

I have been trying to use dynamic scaffolding in groovy on grails to see the list of the Tasks. My domain class is as follows
package projecttracker
import java.util.Date;
class Task
{
String name
String description
Date dueDate
String toString() {
"${name}"
}
static belongsTo = [enduser: EndUser ,project: Project]
static constraints = {
name()
description()
dueDate()
}
}
My controller class is as follows:
package projecttracker
class TaskController {
def scaffold =true
def index() {
redirect(action:list)
}
}
But, whenever I call the index method of the Task controller, the following error occurs:
URI : /ProjectTracker/task/index
Class: groovy.lang.MissingPropertyException
Message: No such property: list for class: projecttracker.TaskController Possible solutions: edit, flash, class
Around line 7 of grails-app\controllers\projecttracker\TaskController.groovy
4: def scaffold =true
5:
6: def index() {
7: redirect(action:list)
8: }
9:}
Can someone tell me, how to define the list method here? Thanks in advance.

Make sure you use a string for the method name, and the scaffold variable must be static, i.e.
static scaffold = true
def index() {
redirect(action:'list')
}

Related

"How to add elements to list"

I am trying to add element in a list from a different method but i am not able to do.
When I am using static keyword in list then i am able to add. I don't understand how it is working.
WITH STATIC
public class QuotesController : ApiController
{
static List<Quote> quotes = new List<Quote>()
{
new Quote(){Id=0,Author="ram",Description="hhkhkhh",Title="gjgj" },
new Quote(){Id=1,Author="shyam",Description="ououo",Title="ouo" }
};
[HttpGet]
public IEnumerable<Quote> Get()
{
return quotes;
}
public void Post([FromBody]Quote quote)
{
quotes.Add(quote);
}
}
I expect the item to be added in list without using static.

Access controller level variable from action method attribute

I have the following base class for all controllers-
public abstract class BaseController:Controller
{
public string BaseUrl
{
get { return "something"; }
}
}
I also have the following action filter attribute-
public class CheckQueryStringAttribute : ActionFilterAttribute
{
string baseUrl;
public CheckQueryStringAttribute(string BaseUrl)
{
baseUrl = BaseUrl;
}
}
I would like to use BaseUrl from base controller into attribute as follows-
public class LoginController : BaseController
{
[CheckQueryString(BaseUrl)]
public ActionResult LoginSuccess()
{
return View();
}
}
Is there any way to do it?
You couldn't pass a variable or object reference in attribute constructor parameter because attributes will resolve at compile time so you can only pass constant by their constructor.
But if you exactly explain what you want to do may i can solve your problem in other way.

How create a listener to a attribute service in grails

I have a problem. I am programming a grails application and I want create a listener to determinate attribute on my service class that I use it on my controller. When this attribute changes I want that the controller be notified. Someone can give a tip or the way to do this? The pseudo-code controller and service are bellow.
class myController{
def someService
def index() {
def return = someService.doSomething();
render (template: "template")
}
}
My Service
class myService {
private void doSomething(){
//some code here changing the variable to be listened
...
...
}
}

Why dynamic scaffolding with Grails doesn't work proprely?

I've tried to scaffold dynamically some domains in GRAILS , but after adding items into database they doesn't show up in the listing view (User/index) in this case :
User.groovy
package scaffold_test
class User {
String username
String address
static constraints = {
}
}
UserController.groovy
package scaffold_test
class UserController {
def scaffold=true
def index() { }
}
so after running the application, I can see the User controller in the Grails home page,I can add Users, and I can see the added instances via DbConsole. But i can't list the instances in the User/index view. Thanks !
Delete def index() { } to let the scaffolding generate all of the methods.

Grails Class with hasMany

I have this domain class that has a one-to-many relationship as with dynamic scaffolding show below:
Domain:
package mienapp
class Announcements {
String user
String title
String comments
Date dateCreated
static hasMany = [tag: Tags]
static mapping = {
comments sqlType: 'text'
}
static constraints = {
}
}
Controller:
package mienapp
class AnnouncementsController {
def scaffold = true
def index() {
redirect(action: list)
}
}
When controller redirects to list, the table shows all fields defined in announcements class. How can I show the value of field from tags in the table as well?
Assuming your list method returns a model with an Announcements instance as
def list() {
..
[announcementsInstance: announcementsInstance, ...]
}
in your view, you can access tags like so
<g:each in="${announcementsInstance.tag}" var="tag">
${tag.someproperty}
</g:each>

Resources