how show action works in grails 2.3.0 controller - grails

def show(Human humanInstance) {
respond humanInstance
//[Q1] In the above action humanInstance is works like Command object
//(I read it in grails doc) they said here call the Domain.get(id) but
//where the line [ Domain.get(id) ] written physically or where it executed when
//show call?
}

In 2.3.0 the line of code which invokes the “get” method for this particular scenario is at https://github.com/grails/grails-core/blob/v2.3.0/grails-plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/plugins/web/api/ControllersApi.java#L427.
Is that what you are looking for?

Related

action helper and routing priority laravel 5

I have two rules
Route::get('this-is-an-awesome-route', 'Ads#getIndex');
Route::controller('ads', 'Ads');
action('Ads#getIndex') renders
http://my-awesome-domain/ads
I want
http://my-awesome-domain/this-is-an-awesome-route
What's the problem ?
For some reason from Laravel 4.2 to Laravel 5 the logic changed a little bit. The line you wrote was working before, you just have to reverse everything as the router isn't processing your code the same way.
Tested and working solution
Route::controller('ads', 'Ads');
Route::get('this-is-an-awesome-route', 'Ads#getIndex');
The first route will be overwritten by the second one.
The second route is rewriting the first route declaration. Let's see:
// Ads#getIndex will be called
Route::get('this-is-an-awesome-route', 'Ads#getIndex');
// Ads#getIndex will be called too by native definition
Route::controller('ads', 'Ads');
Because of Route::controller('ads', 'Ads') is called as latest declaration it will overwrite the previous one. So, you have at least two ways to achieve this task
You could create a new function into Ads controller just to response to the first route:
Route::get('this-is-an-awesome-route', 'Ads#awesome');
Then:
public function awesome(){
// do stuff here
}
Rename the route name for your controller
Route::controller('ads', 'Ads', [
'getIndex' => 'ads.getHome',
]);
Now your Route::controller('ads', 'Ads'); will respond to getHome() instead getIndex() as per renamed route:
public function getHome(){
// do stuff for getIndex() definitions here
}

Box::info showing "refreshEx"

I have a method that displays a validation result using the syntax
Box::info(message,title);
However, the first time I run the code it displays the correct title, but the message refreshEx.
Debugging the code the message that is being used is correct, Valid Account Number, but what displays is refreshEx. If I rerun the process the correct message is displayed, this only happens the first time.
Just in case it matters the flow is
Form - DoValidation method creates Class to call...
Class - public AccountValidation method that calls...
- private displayValidation method that contains this code
Thanks...
I have seen this error (unfortunately), in an AX 2009 installation, launched from code behind a button in a form:
if(HIEItemOrderSetup.RMAvailable < HIEItemOrderSetup.RMQuantity)
{
ok = DialogButton::Ok == box::okCancel("#HIE848",DialogButton::Ok,"#HIE849");
}
As far as I can tell it only occurs when you have a breakpoint on your form, when you are updating it. Removing the breakpoint will show the original message or at least this is what I have found.
If the message contains some fields from the database, try to execute a reread() or refresh() or refreshEx() method (depending on the context) to the datasource before showing the value through the info box.
May be the cached data is not refreshed after an update or insert.
EDIT:
If you are specting a return parameter from an Event, don't forget that this is an async process. An example on MSDN:
http://msdn.microsoft.com/en-us/library/gg843664.aspx

Using coffescript in rails views doesn't work properly

I'm trying to use coffescript as views in Rails 3.2.11
I have create.js.coffee with the following lines:
is_valid = <%=#model.valid?%>
if is_valid
res = confirm("Are you sure you want to continue?")
if(res)
<%=#model.activate%>
window.location.href = "/blabla/models"
else
return
else
$('.form .field_with_errors').removeClass('field_with_errors')
jw_funcs.respond_with_error(<%=#response_invalid%>)
The problem is that the line of code <%=#model.activate%>
is executed every time. I think it depends on the fact that the erb engine runs independently from the coffee engine; If so, how can I do this ?
You really weren't expecting this coffee code to call your model method from the client's browser, were you?
Wrap #model.activate into its own controller action, which will be called by clients if the confirmation is given. Something like this:
res = confirm("Are you sure you want to continue?")
if(res)
$.ajax('/models/1234/activate', ...)
else
return

How to create link in grails webflow without execution state in url?

I want to display an image in my webflow wich comes from my domain object.
The domain object has an byte[] Array holding an image. The "image" method in my controller delivers the image to browser. This works fine.
In my webflow I'm doing this:
<img src="${createLink(controller:'shop', action:'image', id:shopInstance.id)}">
I can see the image in my frontend (in browser) but it reloads each time i click "next" or change my state in webflow because the image url contains a param that changes each event in webflow.
The created image url (example above) looks like this:
http://localhost:8080/project/shop/image/2?execution=e2s5
I don't want that the execution param is delivered into my image url. How can i fix this?
My guess is that this is a bug. A work around I used is the following
${createLink(controller: 'controller', action: 'action').replaceAll(/\?.*$/, "")}
This will use a regex to remove the execution parameter.
Not sure why you're getting that execution param but you could try: <img src="${resource(dir: 'shop/image', file: shopInstance.id)}"> and make sure the UrlMappings.groovy file has a mapping for 'ship/image' to the proper controller.
As of Grails 2.0.4, look at ApplicationTagLib.groovy, you can see
if (request['flowExecutionKey']) {
params."execution" = request['flowExecutionKey']
urlAttrs.params = params
if (attrs.controller == null && attrs.action == null && attrs.url == null && attrs.uri == null) {
urlAttrs[LinkGenerator.ATTRIBUTE_ACTION] = GrailsWebRequest.lookup().actionName
}
}
So Grails is forcing every link rendered within webflow to include that execution params. It looks like bug to me.

Grails: How do I print in the cmd console?

I wanna print a few values in the console, how do I do this?
Every time I get into a function, I want it to print a line with whatever text, I just wanna know if I'm getting into the function, and for some if-else statements.
Mostly for debugging.
If you mean "print to the console output panel", then you simply need to use println:
println "Hello, world"
Results in printed output:
groovy> println "Hello, world"
Hello, world
If that's not what you mean, can you clarify your question to be more specific?
you might want to consider grails built in logging functionality which provides the same functionality as println plus more
http://grails.github.io/grails-doc/3.0.x/guide/single.html#logging
in your app just say
log.info "Hello World"
to print something everytime you enter an action in a controller you can do something like this
class UserController {
def beforeInterceptor = {
log.info "Entering Action ${actionUri}"
}
def index = {
}
def listContributors = {
}
}
this will print out to the log whenever the controller methods are entered because of the controller interceptor
The regular java System.out.println("Your stuff"); works too.

Resources