简体   繁体   中英

JSP/Spring MVC application

I am writing a web application using JSP/Spring MVC and would need to customize the UI based on the customer using it. I would need to hide/show certain sections of the screen, hide show certain labels and their text boxes and also modify labels based on different customers. Currently we are controlling the hide/show in the JSPs by elements and divs based on the logged in customer. For example:

if (customer= "A")

show this

else 

hide this

The code gets cluttered and the JSP will get bloated as we add more customers. Another alternative I have thought is split a page into sections and control the sections in the same way, but might end up in code repetition accross the JSPs.

For example

if (customer = "A")

jsp:include headerA.jsp

else

jsp:include genericheader.jsp

Another alternative would be to write different JSPs and route based on the client.

Is there a better way to handle this kind of situations. Can someone suggest the best practices to implement such a solution?

Thanks.

A UI that chooses what to do for each user can't possibly scale beyond your users A and B. You need a role-based authentication and authorization system.

Since you're already using Spring, I'd recommend looking at Spring Security and its role based capabilities. There are tags that can help you.

Another way to look at it is that role-based logic like this does not belong in tags. I'd recommend putting it in controllers and let them assemble pages for you.

Another possibility is something like SiteMesh, which allows you to create composite views.

One more: jQuery was born to manipulate the DOM. Use it along with CSS.

First thing it should be based on Role and not based on customer, and each customer will have certain role. It may possible that many customers will have same role and screen access and UI.

Based on role, you can use Spring Secutiry for Authentication and Authorization.

If you need to use Layout differently as per customer role, preferably you should use some Layout Manager such as Tiles, SiteMesh etc.

or use portlets for different login views to different customers

You just stated if person A logs in from one store, vs person B logs in from another. Hate to say it, but that's a role, no matter how you want to spin it, this is related to user authorization.

In terms of how you want to implement it, you could do a variety of things, you could intercept the login request and set a session variable which prepends a string to determine the correct view (ie when user a logs in you get customerA, vs customerB, so when rendering the view you'd retrieve the value and render "customerA/index" vs. "customerB/index", etc.

You could also determine the person's roles within the controller and render the appropriate view, although this couples your user roles to your controller logic, which wouldn't be recommended in my opinion.

If this app is going to have a lot of different backends, I'd recommend portlets that way you can write a new backend for each app, rather than bloating your web application with every new store backend.

Those are just a couple ways, hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM