Simple text output (Spring 3+TL)

classic Classic list List threaded Threaded
4 messages Options
Jan
Reply | Threaded
Open this post in threaded view
|

Simple text output (Spring 3+TL)

Jan
Hi there,

I simply would like to make an ognl output like:

${model['test']} which would result in "Hello world" (or something else).

Unfortunately, the value is not being processed.

What am I doing wrong?

Thanks in advance,

Jan
Reply | Threaded
Open this post in threaded view
|

Re: Simple text output (Spring 3+TL)

danielfernandez
Administrator
Model variables are directly accessible, so if you add a "test" variable to your IContext, you just need to do:

${test}


Regards,
Daniel.
Jan
Reply | Threaded
Open this post in threaded view
|

Re: Simple text output (Spring 3+TL)

Jan
Hi and thanks for your reply!

I have following controller:


@Controller
public class TestController {

        @RequestMapping(value="/{slug}", method=RequestMethod.GET)
        public String index(HttpServletRequest req) {
                return "range";
        }
       
        @ModelAttribute("data")
        public String getStringData() {
                return "Hello, world!";
        }
}


In my template I got:

Value: ${data};

But it's not getting replaced :(
Reply | Threaded
Open this post in threaded view
|

Re: Simple text output (Spring 3+TL)

danielfernandez
Administrator

Sorry, I thought you were only talking about the expression, not the way of outputting it.

Thymeleaf does not output variables just by writing "${test}" (although there is something called "text inlining" which you can activate for doing a similar thing). The usual way to do this is:

something here

...although there is much more to it than just that.

Please have a look at any of the tutorials at http://www.thymeleaf.org/documentation.html in order to learn how to use thymeleaf.

Regards,
Daniel.