Vaadin23 navigate is not working in BeforeEnterEvent - vaadin

I try to check if specific parameters of a url are valid. If they aren't the user should be navigated to a different route. It's important that it's a navigate and not a redirect.
When i try to use UI.getCurrent().navigate() in der BeforeEnterEvent i'm experiencing some weird issues.
Some workarround i found is when i call the navigate method in the UI.getCurrent().access() function. Since then the code will be executed at a later point.
UI.getCurrent().access(() -> UI.getCurrent().navigate(""));
So i'm wondering if this is the right way to do this because this seems pretty bad. Is there a better event to call the navigate method?

Related

Vaadin23 vaadin.eagerServerLoad=true and BeforeEnterObserver

I switched to vaadin.eagerServerLoad=true in order to fix the issue with incorrect HTTP status code (I need to return 404 when it is needed).
I also noticed one issue which potentially maybe related to the vaadin.eagerServerLoad=true. On the views with com.vaadin.flow.router.BeforeEnterObserver the method BeforeEnterObserver.beforeEnter is executed twice when I for the very first time enter the page (please note that there is no such issue when I navigate between views in the already constructed UI). This is why now as a temporal fix I have to call removeAll() as a first line in the beforeEnter method.
What am I doing wrong and how to fix it?

URL: Include a parameter inside a destination query

I've searched a lot to try and solve this problem, but I'm not quite sure what to search for. I didn't really manage to find anything.
Essentially I'm working on a website in which users can register for an event. However, if the user is not logged in, I need to redirect them to the registration screen. This much I've been able to accomplish without much difficulty. However I need to redirect back to the event that they attempted to register for.
My real problem is that the URL of the page I need to return to contains an a parameter, and I'm not sure how to make the registration page take that parameter into account when it redirects back.
Currently when an anonymous user tries to go to
http://[...].com/drupal/?q=civicrm/event/register&id=6
I have it redirect you to
http://[...].com/drupal/?q=user/register&destination=civicrm/event/register&id=6
However, once the form is submitted the "&id=6" is not taken as part of the destination parameter, which means you just go to.
http://[...].com/drupal/?q=civicrm/event/register
Which is not a valid page.
Is there a way for me make the destination parameter include "&id=6"?
On a whim I've also tried.
[...]destination='civicrm/event/register&id=6'
[...]destination="civicrm/event/register&id=6"
[...]destination=civicrm/event/register#id=6
You need to url-encode the value for your destination. Try this:
[..]destination=civicrm/event/register%3Fid%3D6
%3F is hex code for question mark (?), %3D is code for equals (=).

Determining where parameters passed from view to controller originated

In my ApplicationController parent class I have an action method called dig which reads parameters via the params[] hash-like structure. I would like to have any view that builds a link to any controller via link_to helper function with the dig action to call the parent's action first. I'd like to then be able to determine either what that parameterized information represents (its type), or what created the link (the previous or originating view).
Any ideas on the best way to do this? Is there a way to pass an object via the link_to and then use its meta data? If so, would this break the rails paradigm?
If you're looking for what called what inside your code, Ruby's caller method is the basis for the stack dump that occurs when an exception occurs. You can tap into that and ask what the calling chain was at any point.
If you want to trace the incoming requests from the browser from an outside site, it becomes a lot more difficult because browsers don't like to reveal the last location any more. If the browser is being redirected around your own site you can use sessions or cookies to trace its movement.
I think that to have the originating link what you would need to do is something like this:
request.env['HTTP_REFERER']
This will get the URL where the action was originated, from there you can process the URL to get controller, action and id. Hope this helps!

Why can't I set a breakpoint in a ASP.NET view?

If I set a breakpoint in the compiled code (for instance in an action), I can then step through, and eventually am stepping through the generation of the View.
I've found this useful a couple of times, but it's tedious as you have to step through a lot of code to get there.
However, I can't set a breakpoint in view. I just receive the message 'This is not a valid location for a breakpoint' from VS2008. Why is this?
Right click on the code you want to break on and go to "Breakpoint -> Insert Breakpoint".
Why? Must have something to do with the face your not working with a pure code file and hitting the left sidebar doesn't know which block of code to use.
Another thing that comes to my mind is to use the debugger; keyword in the view, though I am not 100% sure it will work as in ASP.NET ajax site.
Click to the code where you want to debug and than press F9.
UpTheCreek,
Not really a 'nice' way to do it, however, you can insert some 'flip-flop' code in your view that CAN have a breakpoint placed in it and then step from there. This code doesn't neccessarily have to perfom a function (tho obviously, would be useful if it did).
anyway, you don't want the crumbs, so here's the (meal) deal:
<%
int rspId = 0;
string uniqPageId = Guid.NewGuid().ToString().Replace("-", "");
%>
then, simply place the breakpoint at the side of any of those variable definitions.
Not clean and definately a 'jfar' markdown candidate :-)

ASP.Net MVC - strange params caching behaviour in Actions

I'm facing a strange problem in my project. My actions are getting old param values instead of the actual values which are in Request.Params. I created a HomeController.Echo(string text) action to illustrate it (see screenshot). When I call the action for the first time like "Home/Echo?text=aaa" everything works fine. When I call the same action second time with different text value ("Home/Echo/text=bbb"), I get the old "aaa" value again in my action "text" parameter. Strange think is that Request.Params contains the right "bbb" value.
I'm thinking if there's something I could break myself, but can't figure out anything. I'm serving controllers from IoC container, I overrided ControllerActionInvoker.InvokeActionMethodWithFilters method (to inject dependencies into filters from IoC) and I'm handling HttpApplication.AuthenticateRequest. Im'not working with params/binding anyhow in any of these...
screenshot
The problem was caused by some threading issues probably - I forgot to register controllers in my IoC container with per-request lifecycle (they were registered as singletons).
Have you debugged through the application to see where the value is getting switched out. A simple watch on the text variable (whatever you call it in the code) should yield where the variable gets changed. Without code to run through, I have no clue where it is happening.
I would say write a test, but there is still a possibility of UI interfering here. If you find where in the code it is changing, then write a test to confirm the bug and start whacking at it.
I suggest you to start commenting all the methods you overrode until you isolate the problem. In worst case you will get to the point where the ASP.NET MVC wizard left your project when you created it and where parameter binding definitely worked.

Resources