Grails Possible to use javascript with <g:if>? - grails

Is it possible to use the state of a javascript global variable in the "test=" of a tag? If so how would I access that variable since ${} is usually to evaluate variable sent from the Controllers.

Try using a jQuery function in conjunction with JSON data returned from your controller. You may be able to accomplish what I think you need.

Related

How to set Flow variables with data returned from Function?

https://www.twilio.com/docs/studio/widget-library#run-function
When you invoke a Function, you have two possible options for using variables: (1) you can pass Flow variables as parameters into a Function (e.g. flow.data.foo), and (2) you may set Flow variables with data returned from the Function (TwiML or JSON can be returned).
Does anyone know how to set Flow variables with data returned from a Function?
You should be able to follow the Liquid Syntax documented here, to do so.
Liquid Template Language - Assigning Variables
https://www.twilio.com/docs/studio/user-guide/liquid-template-language#variable-assignment
Or just call the returned variable by addressing the Function widget as shown at the link below:
https://www.twilio.com/docs/studio/widget-library#run-function
widgets.MY_FUCTION_WIDGET_NAME.parsed.xxxxx (where xxxxx is the JSON path).
Alan

Is it possible to hack the spring-security-core plugin #Secured annotation to be able to reference request params given to a controller?

I am using Grails 2.3.3 and spring-security-core:2.0-RC4 plugin.
I am trying to protect a controller action by securing it depending on the result of a method call from a service that takes a parameter. This parameter should be something inside the request parameters.
I'd like to be able to do the following:
#Secured("#mySecurityService.myCustomCheck(params.id)")
def myAction(){
//do some things
}
I managed to be able to do the following:
#Secured("#mySecurityService.myCustomCheck()")
but now I have no idea how to access the request parameters that are sent to the controller.
Is it even architecturally possible to reference params variables inside the #Secured notation?
PS: I know you'll ask me to use spring-security-acl plugin. My problem is that it also adds a bunch of other things that I don't think I require.
In 2.0 you can use a closure as the annotation's check; there's a brief writeup and example in the docs: https://grails-plugins.github.io/grails-spring-security-core/v2/guide/newInV2.html
You'd express your example as this:
#Secured(closure={
ctx.mySecurityService.myCustomCheck(
request.getParameter('id'))
})
Return true to allow access.
Note that the ApplicationContext is available as the ctx variable, and the request as request; this is in addition to the other variables and methods that are available when using SpEL (see the Spring Security docs for details). params isn't available, but you can access values using request.getParameter

Is there any way to pass Dart variables to another browser window?

I know that I can use local storage, cookies and postMessage but all these methods only accept simple types. I want to pass objects and lists directly to the other window.
I found a similar question but using javascript. I'd like to do something just like Victor pointed in the following link.
Can I pass a JavaScript variable to another browser window?
Trying anything similar in Dart gives me a warining even before running.
var popup = window.open('popup.html', '');
popup.variable = localVariable; //warning here
Passing objects is not possible.
You can serialize to JSON to make it a simple type and pass it using postMessage and then deserialize.
Lists and maps containing only simple types should work with postMessage.

How to pass Parameters to Partials and Components?

I'm pretty new to the Symfony Framework and currently searching for the Best-Practice way to pass Parameters from a search to the included partials.
Currently I'm checking for the Parameter in the executeSearch Method and then setting a variable that is available in the searchSuccess.php File.
In the searchSuccess.php File I'm simply passing the variable to the Partial in the include_partial Method in the array. I keep passing the variable around until I'm in the correct partial.
My Method seems to complicated and wrong, but it seems I can't access the sfRequest variables outside the executeSearch Method?
You can access the request object in any template by calling $sf_request.

Accessing user session from a custom routing class

Is there some way to acces the user object from a custom routing class?
I'd like to add a parameter when generating a url, and that parameter is inside the user session, so I need to access it.
The only way I found to access is using the sfContext::getInstance()->getUser(), but it's known to be inefficient.
Thanks!
I'd write it the way you mention - I've used that method in similar situations and never had an issue performance wise, and suspect you will be the same.
Also, never heard this mentioned as inefficient, but it is a little bit frowned upon because it couples the route to the context. An alternative that would overcome this would be to pass the variable to the route as you would any other parameter (or the user object if you need the whole thing). If you need to do this a lot, you can always make a custom url helper that wraps the existing url_for method, adding this param to any other details passed.
A workaround I have implemented (for now), is getting some data from somewhere (not ideal, I'm willing to access the user session yet), and set a new parameter inside $params, in the generate method of the custom routing class.
Hope it helps...

Resources