I am looking at a way to access parameter passed from different Url to use in my web Flow. I am getting URl like
----/newUserRegistration/userRegistration?execution=e20s1&tkn=f9e1cfe077c75ec79f39c61543407cac96ae57e2eca6576e5312b2a266cd8df0. New user registration is my controller name and userregistration is flow name. I have to capture tkn parameter and use this for my flow. How do I do this ? Please suggest me on this....
Given that your Webflow DSL is correct in an action block you can access it with params.tkn.
Related
I have the following URL Mapping:
"/Manage" {
controller = "portal"
action = "login"
app = "directoryManagement"
}
In the above snippet, app is an arbitrary embedded variable as described here: http://docs.grails.org/2.5.0/guide/single.html#embeddedVariables
The portal controller is a child of the authentication controller. All the login action does in the portal controller is call the login action of the authentication controller.
However, in the authentication controller, I am unable to access the embedded arbritary variable
params.app
I have been at this for hours and it seems like I'm missing something simple. Can anyone advise?
The above code should work for anyone that is trying to pass an arbitrary variable to a controller. I had a typo in my URL mapping which is why I wasn't seeing the 'app' parameter in my authentication controller.
I have a controller where I'm trying to set defaults based on the url - but have all of the requests going to one controller.
Trying to extend the answer in : URLMapping to direct all request to a single controller/action
I did this in URLMappings.groovy
"/**"(controller:"lab", action:"index", params:[labName:action])
Where I was hoping I could add the original action name to the parameters, but this doesn't seem to do anything.
Any way I could have all the requests going to that controller mapped to one action, and see what the original action name would be?
Action name is decided based on the url mapping not by the requested url. As you are using a single action, you will always get the action name as index. Based on your requirement below are some of the options that you can choose:
Use requested url and http method to find the right controller and action. Not recommended.
Use filter for setting default data
Use filter to redirect to the default controller after saving the original controller and action in request attributes. Not recommended as it will cause multiple redirects
Extend your controllers with the default controller and do the data setting in interceptor.
I'm currently using MVC5.
Imagine the scenario where one controller ActionA does its work and the redirects to another controller ActionB but also wants this second method to display a message on its related view.
If Controller ActionA sets the ViewBag.Message and then calls RedirectToAction, when ActionB starts, the value of that Message is gone.
What's the best way to pass a message from one action controller to another, without using Session ??
You can use TempData:
Action A:
TempData["Message"] = "Hi";
Action B:
var message = TempData["Message"];
Once you call the getter in Action B, the information will be automatically removed from memory.
This article is a really good explanation of the various persistence techniques available in ASP.NET MVC.
You say no session, but TempData can be a good place depending on what you're passing. It's essentially Session except that the item will be removed from Session once you've accessed it. TempData actually uses session by default unless you write your own provider.
Passing it as an option in the query string, or passing it as a parameter in the routing (similar to what AJ says)
Other than that you've got the standard run of the mill options that are provided in ASP.NET. HttpContext.Items or maybe HttpContext.Cache. But both of those are shared across the entire application domain so management can get tricky.
Remember, web is supposed to be stateless. So if it's really important for that message to get there, you probably want to put it in the URL somehow (query string or routing), or use a database.
I would put an optional argument on the method signature for ActionB, for example:
public ActionResult ActionB(string message = "")
Note that optional parameters need to be last in your parameters list.
I have a URL route of "ticket/{ticket_guid}/{controller}/{action}/{id}". Normally, the parameters would be parsed for you and passed as parameters to the controller action. I need to get access to the {ticket_guid} parameter from inside the Global.asax's Application_AuthenticateRequest event handler. What is the best way to parse out the ticket_guid parameter?
I think you're looking for something like this (if I have correctly assumed ASP.Net MVC):
ViewContext.RouteData.Values["ticket_guid"].ToString()
I am creating a Grails application which has an input page with text fields. Here the user can type in the data and on submit, the control goes to the action in controller.
Here I get the value of the form data using params.empName etc.
But the scope of this data is very small and doesnt get carried on if I do a redirect from the current action to another action.
Is there a way to increase the scope of the variables?
I am now to convert this to service oriented architecture. Therefore Is there a way to access these data in the service as well?
Please advice.
Thanks,
Megs
You can add...
params: params
...as an argument to the redirect, so that the incoming params are sent along with the redirect.
I don't think there's a built-in way to increase the scope. This is probably a Good Thing.
If you're redirecting in controllers, you should simply pass along the necessary parameters via the redirect() params dynamic property. Example:
def formHandler = {
// do stuff with params
redirect(action: 'anotherAction', params: params)
}
If you need scope to span multiple requests, e.g. if you're having a multi-step form entry given to the user, you might look into using web flows to persist state between requests.
For services, you're better off just passing down what you need as arguments to the service method, rather than exposing params. Example (similar to the Accessing Services section here):
// service
def myServiceMethod(def foo, def bar) {
// do stuff
}
// controller
def myService
def myControllerAction {
myService.myServiceMethod(params.foo, params.bar)
}
Exposing parameters from the controller to the service layer would break the layer-oriented approach Grails is trying to provide you; i.e. the "model" and "controller" components (of MVC) would be more tightly coupled.
I would also take a look at chaining actions as a way to pass the model information
http://www.grails.org/Controllers+-+Redirects