Jils
Jils

Reputation: 783

Grails - set variable from javascript function

When I tried to set a variable from javascript function in GSP view I had error: "Cannot invoke method func() on null object"

GSP:

<g:set var="variable" value="${tr.func.name()}" />

I also tried to the get around the problem without success: variable is undifined

<g:javascript>var test = tr.func.name();</g:javascript>
<g:set var="variable" value="${test}" />
<g:javascript>alert(${variable});</g:javascript>

Thanks

Upvotes: 0

Views: 2515

Answers (2)

Igor Artamonov
Igor Artamonov

Reputation: 35961

You should use Javascript in browser. GSP works on server side.

Just pass date in GMT to browser, and apply formatting there. There is a good js library for Date formatting: moment.js

Upvotes: 2

Joshua Moore
Joshua Moore

Reputation: 24776

You can't do that. <g:set> is used to set server-side variables within the GSP. Javascript is client-side.

Upvotes: 1

Related Questions