Spring: Best way to select a customized view at runtime - spring-mvc

I am looking to borrow someone's brains (& experience) to figure out an optimum way to implement the below.
I am currently working on an application which will be used by many of our clients and will require UI customizations according to each client's requirements. Although the underlying java code as well as business logic will be the same, at runtime I would like to figure out (via some property) which client the application is running for and thus, choose the corresponding view and display the web page.
Currently, all I could think of is to create a custom ViewResolver (extending InternalResourceViewResolver) that will read the client name property and use this to resolve a view (eg: WEB-INF/jsp//account/myAccount.jsp) or default to another view (eg: WEB-INF/jsp/default/account/myAccount.jsp) if client property not present.
The issue I see here is that I might not want to overwrite all my JSPs for a particular client where the default view should be rendered. This will require an I/O Call to check the existence of the JSP file in the client's folder before reverting to the default. To counter the I/O I can even create a Map of overwritten JSPs at application startup but this will require an application restart on addition of new customized JSPs which again can be handled by exposing some service to refresh this Map.
So what do you guys think? Also, how will it affect redirects? Plz let me know if you need any further information about our setup or requirement.
Regards,
Sumit

You can use tiles to control the rendering of your view it has a default view resolver bundled with spring and you can extend that.
Define custom layouts, extend them and change it in case you want another behavior.
http://tiles.apache.org/

After waiting for more comments / suggestions, as JB suggested, going with my own solution as described in the question itself.
Thanks all for your help.

Related

Meteor.js - Template Permissions

This has been asked in similar forms here and here but it seems pretty important, and the framework is under rapid development, so I'm going to raise it again:
Assuming your login page needs to face the public internet, how do you prevent Meteor from sending all of the authenticated user templates to a non-authenticated client?
Example use case: You have some really unique analytics / performance indicators that you want to keep secret. You've built templates to visualize each one. Simply by visiting the login page, Meteor will send any rando the templates which, even unpopulated, disclose a ton of proprietary information.
I've seen two suggestions:
Break admin into a separate app. This doesn't address the issue assuming admin login faces the public internet, unless I'm missing something.
Put the templates in the public folder or equivalent and load them dynamically. This doesn't help either, since the file names will be visible from other templates which will be sent to the client.
The only thing I can think of is to store the template strings in the server folder and have the client call a Meteor.method after login to retrieve and render them. And if you want them to behave like normal client templates, you'd have to muck around with the internal API (e.g., Meteor._def_template).
Is there any more elegant way to do this?
I asked a similar question here:
Segmented Meteor App(s) - loading only half the client or two apps sharing a database
Seems to be a common concern, and I certainly think it's something that should be addressed sometime.
Until then, I'm planning on making a smaller "public" app and sharing the DB with an admin app (possibly in Meteor, possibly in something else, depending on size/data for my admin)
These 2 packages try to address this issue:
https://atmospherejs.com/numtel/publicsources
https://atmospherejs.com/numtel/privatesources
It uses an iron-router plug-in to load your specific files on every route.
The main drawback I see here is that you must change your app structure, as the protected files need to be stored in /public or /private folder.
Also you are supposed to use iron-router.

Detect browser when site is accessed

Is there anyway to detect browser version in symfony prior to loading any pages and then run a corresponding action? I was thinking of using modernizr, but I was hoping to not have to rewrite all my views.
Basically what I was hoping I could accomplish is that before the framework attempts to match the url to a route it would first check to see if the user has a particular browser version and if not run another controller instead of the the controller defined in the route.
I think what your suggesting is not a "best practice". I'm assuming you want to route a mobile request to a unique Action method in a Controller. You really shouldn't have a separate controller based client device. This is the job of the (V)view in MVC.
Modernizr is a client side solution with css,js but if youre using symfony, i would prefer server side and that requires the title of this question.. "Detecting browser on request".
While you can custom configure your app to detect the device(and its not to hard), there's also an easier option. Try this bundle. https://github.com/suncat2000/MobileDetectBundle . It does everything and allows for you to make both controller modifications or make twig aware of the browser so you can make smaller changes.

asp.net - Developing web application with features enabled based on configuration

I need to develop a web based product. Features of this will be available to users based on subscription categories like Basic Version /Premium Version / Enterprise Version. I would like to maintain single source for these subscription categories.
Here my question is,
How to design web application, which has features enabled based on configuration / subscription categories?
Thanks in Advance
This is very general question, and I will answer generally.
You can assign Roles to your registered users, and then you check using the IsUserInRole to
see what you going to show and what not.
To gain speed you can assign the permission to the user session and not always call the IsUserInRole
You can open and close some part of your page using the Panel and the Visible of it. Also close the Viewstate of the Panels that are hidden.
Alternative you can use UserControls that inside of them you check if the user have permission to see it or not, and you hide it OnInit, and also disable the ViewState of it.
And of course if a full page is not permitted you can always make a full redirect.
So a full page can have Panels, and UserControls, and the views of it depend from the user level.
You will not be able to get this readymade , you have to design the application based on the technology you are using.
I had similar kind of project going on in which we store the list of feature in database and when the page initializes loads the feature list in session.
On various pages we are showing/hiding controls based on the feature availability.
Offcourse Single feature can also have category based on the User Roles that we can check using FormAuthentication methods and change the page server side accordingly.
Let me know if you have any specific approach in mind and have question related with it.

Application_AuthenticateRequest hit for all requests, including images and js files

In my MVC3 application, I'm using Application_AuthenticateRequest to create my custom user context and create the session. However, I notice that this is getting fired for every file per page request, including images, js, css, etc.
Is this the right method to do what I'm trying to do, or should I be doing this somewhere else (i.e. action filter)? Or, is this the right place, I just need to put some checks and/or configuration to ensure this method (or my block of code) is just executed for page requests instead of requests for static files?
I searched for a while trying to find the answer, and found one specific to IIS7, but this is happening for me on my ASP.NET dev server (debugging) on WinXP. Other than that, I couldn't find much, which leads me to think I may be way off on something here, possibly overlooking something simple.
Thanks in advance.
Jerad,
You are correct that you would be better off creating an action filter to handle your user context. You can decorate those controllers where the user context is required.
This is a better solution than using code to investigate the request, just so you can ignore particular requests.
counsellorben

Embedded image in external component?

I am developing a drop-in component for our company's websites. This component allows users to send messages to each other.
Making this, I've hit several problems during development, such as LoadControl() not working (as it seems to be relative to the project including the module, not the module itself).
I managed to fix this using an approach I found online, but now the next problem emerges - images.
To make the component look somewhat nice, images would be appreciated by the users for icons.
But, again, I am stuck at the same problem.
For instance, if I want an ImageButton, I would set it's ImageUrl property to "~/images/message.png", but this really references something inside my DLL and as such obviously doesn't work!
Is there a standard, good solution for this kind of problem?
Thanks!
You could use WebResources, look at
http://www.aspcode.net/Including-WebResource-in-ASPNET-server-control.aspx
or embedd image in control assembly as resource and serve it with http module, but you will have to declare that http module in web config of application that is using your control.

Resources