Redirecting issues with spring and springmobile - spring

I'm building a website using Spring and the SpringMobile extension.
I've configured the LiteDeviceDelegatingViewResolver with mobilePrefix = m/, tabletPrefix = t/ and enableFallback = true, so that, whenever a dedicated mobile (or tablet) view isn't available, the "normal" (desktop site) view is served.
The site has several sections and subsections. For instance, there's a Products section and several Categories within it.
Currently, there isn't a landing page for Products, so I redirect the user to the first Category. In other words, when the link to /products is clicked, the corresponding #Controller method redirects to /products/category1 (by returning "redirect:/products/category1"); then, the method mapped to /products/category1, serves the view (by returning "viewname").
This works as expected when using the desktop site. However, in the mobile site, whenever I try to browse to /products, I get automatically redirected to /m/products by SpringMobile (which is fine), but then my #Controller gets into action, and, instead of being eventually redirected to /m/products/category1, strangely I get redirected to /m/products/m//products/category1.
Any ideas on why is this happening, and on how to achieve the expected behavior?
P.S.: If I navigate directly to /m/products/category1, the desktop view (the fallback) is properly shown.

Well, it turns out this was a bug in SpringMobile(MOBILE-70, MOBILE-78) which was fixed in version 1.1.0.RC1. It also affected forward: redirection.
I've updated my project dependencies, and the issues appear to be gone for good.

Related

How do I get the Router navigate extra "replaceUrl" to work correctly?

I have a contact addition form that can be navigated to from multiple screens in our application.
Once the form is submitted, I then take the user to a screen to view the contact that was added.
When the user then makes use of the back button it should take them back to the screen that they originated from.
This might be the Android back button or one that calls the RouterExtensions back function.
I have made use of the navigate extra replaceUrl when navigating away from the form to the view page.
I have also tried using the skipLocationChange extra when navigating to the form but this creates more issues.
I have created a simple playground page flow that creates not quite the same issue but does throw an error that I don't know what to do with either:
https://play.nativescript.org/?template=play-ng&id=BfVcGZ&v=2
In our app, by making use of the replaceUrl extra, the back button does take the user to the correct page.
However, there is a brief moment where they see the form again. This isn't an ideal user experience.
In the linked Playground I do get an error:
Cannot reattach ActivatedRouteSnapshot created from a different route.
This seems to tell me that replaceUrl is indeed removing the page from the route table.
However, the page isn't destroyed yet and so the app is trying to show a page that it shouldn't.
replaceUrl is not yet supported by Page Router Outlet, there is an open feature request, you might want to register your vote on the feature and follow up there for further updates.

JSP includes and MVC pattern

I am new to JSP/Servlets/MVC and am writing a JSP page (using Servlets and MVC pattern) that displays information about recipies, and want the ability for users to "comment" on it too.
So for the Servlet, on doGet(), it grabs all the required info into a Model POJO and forwards the request on to a JSP View for rendering. That is working just fine.
I'd like the "comment" part to be a separate JSP, so on the RecipeView.jsp I can use to separate these views out. So I've made that, but am now a little stuck. The form in the CommentOnRecipe.jsp posts to a CommentAction servlet that handles the recording of the comment just fine. So when I reload the Recipe page, I can see the comment I just made.
I'd like to:
Reload the page automatically after commenting (no AJAX for now)
Block the user from making more than one comment on each Recipe over a 1 day timeframe (via a Cookie). So I store a cookie indicating the product ID whenever the user makes a comment, so we can check this later? How would it work in a MVC context?
Show a message to the user that they have already commented on the Recipe when they visit one
which they have commented on
I'm confused about using beans/including JSPs etc on how to achieve this.
I know in ASP.NET land, it would be a UseControl that I would place on a page, or in ASP.NET MVC, it would be a PartialView of some sort. I'm just confused with the way this works in a JSP/Servlets/MVC context.
you can use response.sendRedirect() or forward APIs in javax.servlet to redirect to a new page or refresh the same page (redirect to the same page/path so that the beans/data gets refreshed)
about restricting to one comment per day - yes you can use cookie but the problem is that user might use another browser type (chrome, FF, Safari) and will be able to make multiple comments.
Ideally you should store the lastCommentTime in the model/persistent store and tie it to the user information - this way your model object can expose an API that checks the last comment time and returns true/false depending on whether user can comment or not.
You can use this API in your servlet/JSP to show/hide the comment button, for example and also show a message

Alfresco share page state history

How can I manage page state history in share (surf?) so that I remember for example which yui tab was active and on which page the pager was on?
I noticed that alfresco share does something like that after form submit. You get redirected to the exact same page url where you were before. If any "ajax state" (don't know what they are called) parameters are in url like #something=asdf you get the same url.
But when using manual navigation like moving through site pages those parameters aren't saved.
Is this even a good idea to do? To save page state in session for example?
Some pages have support for URL parameters that are passed in. In those cases the browser history is used, e.g. we editing metadata in the full page meta data view the user is send back to the page he is coming from. This is done in javascript by calling window.history.go(-1) after form submit but only works when parameters are set/retrieved by URL. The document library implements page specific javascript for setting the URL and parsing parameters from it.
I some places Alfresco uses the preference service to store user settings between different pages permanently. For example this is used in the document library for the "show folders" and "simple/thumbnail view" buttons. Here is some sample code from the document library javascript setting a preference option:
var PREFERENCES_DOCLIST = "org.alfresco.share.documentList",
PREF_SHOW_FOLDERS = PREFERENCES_DOCLIST + ".showFolders";
var preferences = new Alfresco.service.Preferences();
this.services.preferences.set(PREF_SHOW_FOLDERS, true);
The evaluation of the properties is usually done in the Share component webscripts, you can have a look in share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\documentlibrary\include\documentlist.lib.js for an example.
In any case you have to dig into Alfresco's javascript code in the browser and the share tier to see how to implement it.
You could check parameters sended to the server side after form submiting in the firebug (firefox plugin) and then you could use the same parameters.
Also perhaps you should use yui history manager:

MVC3 and IIS6 RedirectToAction redirects to wrong URL

This is weird. I have a virtual directory setup for an MVC3 application called (for the sake of this question) I'll call 'foobar'. The full URL to this site is:
http://localservername.domainname.com/foobar
In my logon form, I have the following line that is supposed to redirect to the main/home page of the application after logon.
return RedirectToAction("Index", "Home");
However, when this line executes, I get redirected to the wrong location - so instead of redirecting me back to:
http://localservername.domainname.com/foobar
I get redirected back to:
http://localservername.domainname.com/foobar/foobar
Which of course gets me a resource not found error. Also, any links in my views seem to do the opposite - for example if I have a link like this:
Widget Search
I would expect the following URL to open:
http://localservername.domainname.com/foobar/WidgetSearch
Instead, I get redirected to
http://localservername.domainname.com/WidgetSearch
Which of course also gets me a resource not found error. I've never encountered this type of behaviour before. I've gone over the basic and advanced settings and created a new application pool. Fiddler also shows me that (of course) the URLs listed above return 404 responses.
Any suggestions would be greatly appreciated.
Thanks!
The first issue shouldn't really happen. RedirectToAction should take into account your virtual directory path (you haven't hard coded an extra /foobar into your route setup have you?).
The second problem has nothing to do with MVC, it's just that you're using a vanilla HTML link that is pointing directly to the root of the server (that's what saying /blah implies). You should change your link to use one of the MVC helper methods to generate the URL instead to make sure it adds the virtual directory for you. So one of the following (the first is probably the best way, unless you need to heavily customise what the anchor tag looks like):
#Html.ActionLink("Widget Search", "Index", "WidgetSearch")
or
Widget Search

MVC Deployment Problem - Site Loads but Links (Routes) do not

Having a problem deploying an MVC application.
Basically the site loads correctly, the home page appears. However anything which needs to access a controller action does not. So all the links just throw up 404 errors.
Does anyone have an Idea why the site loads but after that the controller actions appear not to?
Thanks
Are you running your app in IIS 6? If so you'll need to configure the .mvc extension or configure wildcard mapping. Steve Sanderson has a good post on it.
The fact that the home page appears indicates that you have at least one controller working properly. Namely, the HomeController.
You should check that you are following the default conventions (if you have it set up that way)
Controllers belong in the Controllers folder and follow the naming convention [Name]Controller.
Also, every action in the controller must be public and must return an ActionResult of some kind. Returning a View will cause a particular View to be rendered.
Also, Views follow the folder structure View/[ControllerName]/[Action].aspx
The fact that the first page loads means you probably have Home/Index set up properly for both your Controller and your View. You should take a look at those and see what the difference between that is and the other controllers/actions/views that you've set up.

Resources