struts2 中的动态(数据库驱动)菜单创建
过去几周我才开始使用 struts2。我开发了一个登录页面和一个登陆页面。但我一直在努力创建一个基于数据库(mysql)中定义的用户可访问性的动态水平菜单。 我有以下表格,例如
menu_master
id | label | parent_id | action | etc | etc ...
如果parent_id为空,则相应的标签将是父菜单,其子菜单将作为其下的子菜单。操作将是相应的前向链接
user
id | name | password | etc | etc |....
user_menu_mapping
id | user_id | menu_id
基于此映射表,我有当用户成功登录系统时创建一个菜单(在 Java 级别生成并呈现为 jsp [css+javascript])。
适用于 struts2 应用程序的动态菜单生成的最佳选项和设计程序是什么。
任何建议或建议都将受到高度赞赏。
谢谢
I have just started hanging around in struts2 for the past few weeks. I have developed a login page and a landing page. But I have been struggling in creating a dynamic horizontal-menus based on user-accessibility defined in the database(mysql).
I have the following tables , say for example
menu_master
id | label | parent_id | action | etc | etc ...
If the parent_id is null then the corresponding label would be the parent menu and its children would come as sub-menus under it.Action would be the corresponding forward links
user
id | name | password | etc | etc |....
user_menu_mapping
id | user_id | menu_id
Based on this mapping table , I have to create a menu (generated at Java level and rendered as jsp [css+javascript]) when the user successfully logs into the system.
What are the best options and design procedures for dynamic menu generation available for struts2 application.
Any suggestions or advices are highly appreciated.
Thanx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有许多单独的部分应该独立解决。
首先考虑视图...我将使用 css 创建一个 html 页面,以使用测试菜单来查看您想要的方式。
接下来使用 s2 标签从操作类获取列表来准备您的菜单。菜单就像:选择框吗?你的意思是基于 html 无序列表的 jquery 下拉列表吗?无论结果如何,都可以使用适当的 S2 表单或逻辑标记从操作类中的列表构建菜单。
当然,现在您需要在操作中动态构建列表...此时您可以直接在操作内执行此操作,但如果您有大量数据库交互,您将希望将其委托给服务层。无论如何,您现在遇到的问题相当简单,即从数据库中获取所需的列表。
为了让我们提供帮助,我们需要知道您在哪一个方面遇到问题以及您正在使用什么工具...可能最简单的方法是显示您的 jsp/action 类/和 xml(如果有)。
There are a number of separate parts that should be solved independently.
First consider the view... I would create an html page with css to look the way you want with a test menu.
Next using s2 tags get a list from an action class to prepare your menu. Is the menu just a s:select box? Do you mean a jquery drop down list based of an html unordered list? What ever it turns out to be use the appropriate S2 form or logic tags to build the menu from a List in the action class.
Now of course you need to dynamically build the List in the action... You can do this directly inside the action at this time but if you have a lot of database interaction your going to want to delegate this to a service layer. In any case you now have the rather simple problem of getting the list you need from the database.
For us to help we'll need to know which one of these areas you're having problems with and what tools you are using... Probably the easiest would be to show your jsp/action class/and xml if any.