Home Grails passing object to gsp
Reply: 0

Grails passing object to gsp

user1363
1#
user1363 Published in June 21, 2018, 10:16 am

I want to pass my database User object from controller to .gsp page so I can use it's properties in the view. Here's the controller code:

def login(String username, String password){
        def userList = getUserListFromDatabase();
        User usr = new User(username: username, password: password);
        println usr.username + '   ' + usr.password;
        username = params?.username;
        password = params?.password;
        println userList.size();
        for(User u : userList){
            println 'username: ' + u.username + ' password: ' + u.password;

            if(u.password.equals(password) && u.username==username){
                User user = u;
                flash.user = u;
                render (view: 'login.gsp');
                //debug
                println 'user.username: ' + user.username;
                return;
            }

        }
        render 'login failed';
    }

And that's how I'd like to show it in the view:

</head>
    <g:set var="now" value="${new Date()}"/>
    <g:set var="user"/>
<body>
        Login successful!<br/>
        User: ${user?.username}<br/>

</body>

What would be a proper way to pass the object with all it's properties to the view? I can't get to it.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.339159 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO