OpenXava does not include a complete security and navigation system, although you can easily add security and navigation in an OpenXava application if you use a Java portal, such as Liferay. Also, you can use the official solution that OpenXava team offers: XavaPro. Even though these solutions may be valid for new projects, for legacy projects you may need apply other ones. In this post we are going to customize our own solution for navigation and security starting from the standard OpenXava solution: NaviOX.
We are going to use OpenXava 5.3.2 and as an example of database, we are to going to use Classic Models which can be downloaded from this page. We are going to use the model classes created following the instructions of this post: Reverse Engineering and Code Generation.
Basically, what we want is to:
- Customize our own main menu
- Customize the first page of the application
- Apply our own security
For example, the first page of the application and the complete main menu would be:
The image above belongs to a user who has complete access. In the following image, some options of the menu are hidden after applying security:
In both images above a picture of a car is shown instead of the images of the typical FirstStep jsp of OpenXava. We have changed the first page.
Finally, depending on user, the system will show or hide fields. In the following picture, the image field of the product lines has been hidden because user has not permission.
As you can see in the pictures above, we have changed the standard menu of OpenXava NaviOX, FirstSteps page has been replaced by another one and we have improved security system. Now we are going to explain how to do this.
Basic knowledge
When you download OpenXava 5.3.2, you have a project called Addons, where NaviOX is. NaviOX is a basic system for security and navigation in OpenXava. There are several empty classes, such as DB.java or Folders.java that you can extend for implementing your own security or navegation. However, we are going to extend, modify and add other classes.
You have to know that when you create a new OpenXava project executing CreateNewProject.xml ant build, all files under Addons/web/naviox folder are copied to your project under web/naviox folder. We are going to change some of the JSPs.
Security
For this example, we have developed a very simple security system with users and roles. You can find the main classes under Addons project, under com.lostinsoftware.securty package.
The classes are prepared for implementing different security systems depending on the backend, such as database, webservices and so on. In this example, only xml file backend system are implemented under com.lostinsoftware.security.xml package.
SecurityManagerFactory is the class in charge of build a SecurityManager depending on the chosen backend security system. Backed security system is set in the property securityManagerFactoryType of the naviox.properties file.
Security is the main class which you have to use for checking permissions. This class get current user data from current thread. Review class com.openxava.util.Users for more information.
In this example, security data are stored in security.xml file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<security> <role rolename="admin"> <permission object="all" action="all"/> </role> <role rolename="hhrr"> <permission object="Offices" action="all"/> <permission object="Employees" action="all"/> </role> <role rolename="order"> <permission object="Customers" action="all"/> <permission object="Orders" action="all"/> <permission object="Productlines" action="hide-image"/> <permission object="Products" action="all"/> </role> <role rolename="payment"> <permission object="Customers" action="all"/> <permission object="Payments" action="all"/> </role> <role rolename="productline"> <permission object="Productlines" action="all"/> <permission object="Products" action="all"/> </role> <user username="ceo" password="ceo" fullname="Chief Executive Officer" roles="admin"/> <user username="vp1" password="vp1" fullname="Vice President 1" roles="payment, productline"/> <user username="vp2" password="vp2" fullname="Vice President 2" roles="hhrr, order"/> <user username="cfo" password="cfo" fullname="Chief Financial Officer" roles="payment"/> <user username="cmo" password="cmo" fullname="Chief Marketing Officer" roles="productline"/> <user username="cso" password="cso" fullname="Chief Sales Officer" roles="order"/> <user username="chro" password="chro" fullname="Chief Human Resources Officer" roles="hhrr"/> </security> |
As you can see, there are seven users; CEO user is the adminitrator of the system and has access to everything. The others users have limited permissions. Objects, in this example, are OpenXava modules and, in turn, are the tables of the database. You will have noticed that for the role order, the object Productlines has assigned the action hide-image. That means that the system must hide image of product lines if the user belongs to order role.
In order to load the new system security, we will have to modify the method isAuthorized of the class SignInHelper, under com.openxava.naviox.impl package, in Addons project. The new class SignInHelper is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
package com.openxava.naviox.impl; import java.io.*; import java.util.*; import javax.servlet.http.*; import org.apache.commons.logging.*; import org.openxava.util.*; import org.openxava.view.*; import com.lostinsoftware.security.Security; import com.openxava.naviox.*; /** * * @author Javier Paniza * @author lostinsoftware */ public class SignInHelper { private final static String PROPERTIES_FILE = "naviox-users.properties"; private static Log log = LogFactory.getLog(SignInHelper.class); private static Properties users; public static void init(HttpServletRequest request, View view) { } public static String refineForwardURI(HttpServletRequest request, String forwardURI) { return forwardURI; } public static void signIn(HttpSession session, String userName) { session.setAttribute("naviox.user", userName); Modules modules = (Modules) session.getAttribute("modules"); // Added by lostinsofware Users.setCurrent(userName); // end change by lostinsoftware modules.reset(); } public static boolean isAuthorized(String user, String password) { // String storedPassword = getUsers().getProperty(user, null); // return password.equals(storedPassword); return Security.validUser(user, password); } private static Properties getUsers() { if (users == null) { PropertiesReader reader = new PropertiesReader( Users.class, PROPERTIES_FILE); try { users = reader.get(); } catch (IOException ex) { log.error(XavaResources.getString("properties_file_error", PROPERTIES_FILE), ex); users = new Properties(); } } return users; } } |
Customizing main menu
The goal of this section is to have our own navigation bar fixed at the top of every pages. We also want to remove the left sidebar.
As it is explained in Main JSPs in OpenXava the main container is index.jsp, under web/naviox folder. So you will have to change this file.
For removing the left sidebar, you have to comment out the following lines:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<!-- <td id="modules_list"> <div id="modules_list_popup" > <img id="modules_list_corner" src="<%=request.getContextPath()%>/naviox/images/corner.png"/> <div id="modules_list_outbox"> <table id="modules_list_box"> <tr id="modules_list_content"> <td> <jsp:include page="modulesMenu.jsp"/> </td> </tr> </table> </div> </div> </td> --> |
For the navigation bar at the top, we are going to use a standard solution with Bootstrap (v3.3.5). Because we want a navigation bar with height less than the Bootstrap’s default, you have to change the property @navbar-height with a value, for example, 15px, and then download the modified classes. This operation of modification you can do it at http://getbootstrap.com/customize/ or at http://bootstrap-live-customizer.com/. You have to put these modified Bootstrap’s files under web/naviox folder.
You have to add a few lines for activating Bootstrap just below <head> tag, and a couple of lines above <body> tag. Your index.jsp would be now:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
<% Servlets.setCharacterEncoding(request, response); %> <%@include file="../xava/imports.jsp"%> <%@page import="org.openxava.web.servlets.Servlets"%> <%@page import="org.openxava.util.Locales"%> <%@page import="com.openxava.naviox.web.NaviOXStyle"%> <jsp:useBean id="context" class="org.openxava.controller.ModuleContext" scope="session"/> <jsp:useBean id="modules" class="com.openxava.naviox.Modules" scope="session"/> <% String app = request.getParameter("application"); String module = context.getCurrentModule(request); Locales.setCurrent(request); String sretainOrder = request.getParameter("retainOrder"); boolean retainOrder = "true".equals(sretainOrder); modules.setCurrent(request.getParameter("application"), request.getParameter("module"), retainOrder); String oxVersion = org.openxava.controller.ModuleManager.getVersion(); %> <!DOCTYPE html> <head> <!-- Bootstrap --> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/naviox/css/bootstrap.css"> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> <![endif]--> <!-- end Bootstrap --> <title><%=modules.getCurrentModuleDescription(request)%></title> <link href="<%=request.getContextPath()%>/naviox/style/naviox.css" rel="stylesheet" type="text/css"> <script type='text/javascript' src='<%=request.getContextPath()%>/xava/js/dwr-engine.js?ox=<%=oxVersion%>'></script> <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Modules.js?ox=<%=oxVersion%>'></script> <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Folders.js?ox=<%=oxVersion%>'></script> </head> <body <%=NaviOXStyle.getBodyClass(request)%>> <!-- <div id="main_navigation"> --> <div role="navigation" class="navbar navbar-inverse navbar-fixed-top"> <jsp:include page="mainNavigation.jsp"/> </div> <!-- end main navigation --> <table width="100%"> <tr> <!-- <td id="modules_list"> <div id="modules_list_popup" > <img id="modules_list_corner" src="<%=request.getContextPath()%>/naviox/images/corner.png"/> <div id="modules_list_outbox"> <table id="modules_list_box"> <tr id="modules_list_content"> <td> <jsp:include page="modulesMenu.jsp"/> </td> </tr> </table> </div> </div> </td> --> <td valign="top"> <div class="module-wrapper"> <% if ("SignIn".equals(module)) { %> <jsp:include page='signIn.jsp'/> <% } else { %> <div id="module_description"> <%=modules.getCurrentModuleDescription(request)%> <!-- <a href="javascript:naviox.bookmark()" title="<xava:message key='<%=modules.isCurrentBookmarked()?"unbookmark_module":"bookmark_module"%>'/>"> <img id="bookmark" src="<%=request.getContextPath()%>/naviox/images/bookmark-<%=modules.isCurrentBookmarked()?"on":"off"%>.png"/> </a> --> </div> <jsp:include page='<%="../xava/module.jsp?application=" + app + "&module=" + module + "&htmlHead=false"%>'/> <% } %> </div> </td> </tr> </table> <script type='text/javascript' src='<%=request.getContextPath()%>/naviox/js/typewatch.js'></script> <script type='text/javascript' src='<%=request.getContextPath()%>/naviox/js/naviox.js'></script> <script> $(function() { naviox.init(); }); </script> <!-- Bootstrap --> <script src="<%=request.getContextPath()%>/naviox/js/jquery.js"></script> <script src="<%=request.getContextPath()%>/naviox/js/bootstrap.js"></script> <!-- End Bootstrap --> </body> </html> |
The next step for setting up the main bar navegation is to modify mainNavigation.jsp. You have to add main menu, menus, submenus and items using <ul<, <li;> and Bootstrap classes. You also have to call methods of Security class to hide or shown menus and items depending on the user’s rol. An example of mainNavigation.jsp could be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
<%@include file="../xava/imports.jsp"%> <%@page import="java.util.Iterator"%> <%@page import="org.openxava.application.meta.MetaModule"%> <%@page import="org.openxava.util.Users"%> <%@page import="org.openxava.util.Is"%> <%@page import="com.openxava.naviox.Modules"%> <%@page import="com.openxava.naviox.util.NaviOXPreferences"%> <%@page import="com.lostinsoftware.security.Security"%> <jsp:useBean id="modules" class="com.openxava.naviox.Modules" scope="session"/> <!-- <div role="navigation" class="navbar navbar-inverse navbar-fixed-top"> --> <div class="container-fluid"> <!-- Toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-navbar-collapse" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="main-navbar-collapse"> <% if (modules.hasModules()) { %> <ul class="nav navbar-nav"> <% if (Security.hasAnyObject(Security.OBJ_OFFICES, Security.OBJ_EMPLOYEES, Security.OBJ_ALL)) { %> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><xava:message key="hhrr"/></a> <ul class="dropdown-menu"> <% if (Security.hasAnyObject(Security.OBJ_OFFICES, Security.OBJ_ALL)) { %> <li><a href='<%=modules.getModuleURI(request, "Offices")%>?retainOrder=true'><xava:message key="offices"/></a></li> <% } if (Security.hasAnyObject(Security.OBJ_EMPLOYEES, Security.OBJ_ALL)) { %> <li><a href='<%=modules.getModuleURI(request, "Employees")%>?retainOrder=true'><xava:message key="employees"/></a></li> <% } %> </ul> </li> <% } // Human resources if (Security.hasAnyObject(Security.OBJ_PRODUCTLINES, Security.OBJ_PRODUCTS, Security.OBJ_ALL)) { %> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><xava:message key="products"/></a> <ul class="dropdown-menu"> <% if (Security.hasAnyObject(Security.OBJ_PRODUCTLINES, Security.OBJ_ALL)) { %> <li><a href='<%=modules.getModuleURI(request, "Productlines")%>?retainOrder=true'><xava:message key="productlines"/></a></li> <% } if (Security.hasAnyObject(Security.OBJ_PRODUCTS, Security.OBJ_ALL)) { %> <li><a href='<%=modules.getModuleURI(request, "Products")%>?retainOrder=true'><xava:message key="products"/></a></li> <% } %> </ul> </li> <% } // Products if (Security.hasAnyObject(Security.OBJ_CUSTOMERS, Security.OBJ_ORDERS, Security.OBJ_ALL)) { %> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><xava:message key="orders"/></a> <ul class="dropdown-menu"> <% if (Security.hasAnyObject(Security.OBJ_CUSTOMERS, Security.OBJ_ALL)) { %> <li><a href='<%=modules.getModuleURI(request, "Customers")%>?retainOrder=true'><xava:message key="customers"/></a></li> <% } if (Security.hasAnyObject(Security.OBJ_ORDERS, Security.OBJ_ALL)) { %> <li><a href='<%=modules.getModuleURI(request, "Orders")%>?retainOrder=true'><xava:message key="orders"/></a></li> <% } %> </ul> </li> <% } // End Products if (Security.hasAnyObject(Security.OBJ_PAYMENTS, Security.OBJ_ALL)) { %> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><xava:message key="payments"/></a> <ul class="dropdown-menu"> <li><a href='<%=modules.getModuleURI(request, "Payments")%>?retainOrder=true'><xava:message key="payments"/></a></li> </ul> </li> <% } // End Payments %> </ul> <% if (Is.emptyString(NaviOXPreferences.getInstance().getAutologinUser())) { String userName = Users.getCurrent(); %> <ul class="nav navbar-nav navbar-right"> <li><a href="<%=request.getContextPath()%>/naviox/signOut.jsp" class="sign-in"><xava:message key="signout"/> (<%=userName%>)</a></li> </ul> <% } %> <!-- no modules --> <% } else { if (Is.emptyString(NaviOXPreferences.getInstance().getAutologinUser())) { %> <ul class="nav navbar-nav navbar-right"> <li> <a href="<%=request.getContextPath()%>/m/SignIn" > <xava:message key="signin"/> </a> </li> </ul> <% } } %> </div> <!-- end div .navbar-collapse --> </div> <!-- end div .ncontainer-fluid --> <!-- </div> end div main navbar --> |
Some styles (css classes) of OpenXava are affected by Bootstrap. To fix this problem, you have to create a custom.css file under web/xava/style. The code in this file is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/* Put here your own style */ body { padding-top: 35px; } * { box-sizing: content-box; } select { box-sizing: border-box; } |
Customizing the first page of the application
By default, the first page of an OpenXava is FirstSteps. This first page is set in Modules class, under com.openxava.naviox package and is designed in firstSteps.jsp.
The code of the first page is decided in getCurrent method of Modules class.
In this example, our first page is mainmenu.jsp and its code is MainMenu. In order to active this new code, you have to change init method in Modules class. Besides, a good practice is to add a new method, createMainMenuModule, to register this new dummy module.
The code of Modules.java is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
package com.openxava.naviox; import java.io.*; import java.util.*; import java.util.prefs.*; import javax.servlet.http.*; import org.apache.commons.logging.*; import org.openxava.application.meta.*; import org.openxava.util.*; import com.openxava.naviox.impl.*; import com.openxava.naviox.util.*; /** * * @author Javier Paniza * @author lostinsoftware */ public class Modules implements Serializable { private static final long serialVersionUID = -6153839281230999314L; public final static String FIRST_STEPS = "FirstSteps"; public final static String MAIN_MENU = "MainMenu"; private static Log log = LogFactory.getLog(Modules.class); private final static int MODULES_ON_TOP = 20; private final static int BOOKMARK_MODULES = 100; private final static ModuleComparator comparator = new ModuleComparator(); private static String preferencesNodeName = null; private HashMap<String, MetaModule> modules; private List<MetaModule> all; private List<MetaModule> topModules = null; private List<MetaModule> bookmarkModules = null; private MetaModule current; public static void init(String applicationName) { MetaModuleFactory.setApplication(applicationName); DB.init(); // createFirstStepsModule(applicationName); createMainMenuModule(applicationName); } private static void createFirstStepsModule(String applicationName) { MetaApplication app = MetaApplications.getMetaApplication(applicationName); MetaModule firstStepsModule = new MetaModule(); firstStepsModule.setName(FIRST_STEPS); firstStepsModule.setModelName("SignIn"); // The model does not matter firstStepsModule.setWebViewURL("/naviox/firstSteps.jsp"); firstStepsModule.setModeControllerName("Void"); app.addMetaModule(firstStepsModule); } private static void createMainMenuModule(String applicationName) { MetaApplication app = MetaApplications.getMetaApplication(applicationName); MetaModule mainMenuModule = new MetaModule(); mainMenuModule.setName(MAIN_MENU); mainMenuModule.setModelName("SignIn"); // The model does not matter mainMenuModule.setWebViewURL("/naviox/mainmenu.jsp"); mainMenuModule.setModeControllerName("Void"); app.addMetaModule(mainMenuModule); } public void reset() { all = null; modules = null; topModules = null; bookmarkModules = null; current = null; if (!NaviOXPreferences.getInstance().isStartInLastVisitedModule()) { try { // getPreferences().remove("current"); Preferences preferences = getPreferences(); preferences.remove("current"); preferences.flush(); } catch (BackingStoreException ex) { log.warn(XavaResources.getString("current_module_problem"), ex); } } } public boolean hasModules() { return !getAll().isEmpty(); } // private MetaModule createWelcomeModule(MetaApplication app) { // MetaModule result = new MetaModule(); // result.setName("Welcome"); // result.setWebViewURL("naviox/welcome"); // return result; // } public void setCurrent(String application, String module, boolean retainOrder) { this.current = MetaModuleFactory.create(application, module); if (topModules == null) loadTopModules(); int idx = indexOf(topModules, current); if (idx < 0) { if (topModules.size() >= MODULES_ON_TOP) { topModules.remove(topModules.size() - 1); } topModules.add(0, current); } else if (!retainOrder) { topModules.remove(idx); topModules.add(0, current); } storeTopModules(); } public String getCurrent() { try { // return getPreferences().get("current", FIRST_STEPS); return getPreferences().get("current", MAIN_MENU); } catch (Exception ex) { log.warn(XavaResources.getString("current_module_problem"), ex); // return FIRST_STEPS; return MAIN_MENU; } } public String getCurrentModuleDescription(HttpServletRequest request) { try { String organization = Organizations.getCurrentName(request); String prefix = organization == null?"":organization + " - "; return prefix + current.getMetaApplication().getLabel() + " - " + current.getLabel(); } catch (Exception ex) { log.warn(XavaResources.getString("module_description_problem"), ex); return XavaResources.getString("unknow_module"); } } public void bookmarkCurrentModule() { if (bookmarkModules == null) loadBookmarkModules(); int idx = indexOf(bookmarkModules, current); if (idx < 0) { bookmarkModules.add(current); } storeBookmarkModules(); } public void unbookmarkCurrentModule() { if (bookmarkModules == null) loadBookmarkModules(); int idx = indexOf(bookmarkModules, current); if (idx >= 0) { bookmarkModules.remove(idx); } storeBookmarkModules(); } public boolean isCurrentBookmarked() { return isBookmarked(current); } public boolean isBookmarked(MetaModule module) { if (bookmarkModules == null) loadBookmarkModules(); return indexOf(bookmarkModules, module) >= 0; } private void loadTopModules() { topModules = NaviOXPreferences.getInstance().isRememberVisitedModules()? loadModulesFromPreferences("", MODULES_ON_TOP):new ArrayList<MetaModule>(); } private void loadBookmarkModules() { bookmarkModules = loadModulesFromPreferences("bookmark.", BOOKMARK_MODULES); } private List<MetaModule> loadModulesFromPreferences(String prefix, int limit) { List<MetaModule> modules = new ArrayList<MetaModule>(); try { Preferences preferences = getPreferences(); for (int i = 0; i < limit; i++) { String applicationName = preferences.get(prefix + "application." + i, null); if (applicationName == null) break; String moduleName = preferences.get(prefix + "module." + i, null); if (moduleName == null) break; try { MetaModule module = MetaModuleFactory.create(applicationName, moduleName); if (isModuleAuthorized(module)) { modules.add(module); } } catch (Exception ex) { log.warn(XavaResources.getString("module_not_loaded", moduleName, applicationName), ex); } } } catch (Exception ex) { log.warn(XavaResources.getString("loading_modules_problem"), ex); } return modules; } public boolean isModuleAuthorized(HttpServletRequest request) { try { if (request.getRequestURI().contains("module.jsp")) return false; if (Users.getCurrent() == null && request.getRequestURI().contains("/phone/")) return false; if (!(request.getRequestURI().startsWith(request.getContextPath() + "/m/") || request.getRequestURI().startsWith(request.getContextPath() + "/p/") || request.getRequestURI().startsWith(request.getContextPath() + "/modules/"))) return true; String [] uri = request.getRequestURI().split("/"); if (uri.length < 4) return false; return isModuleAuthorized(MetaModuleFactory.create(uri[1], uri[3])); } catch (Exception ex) { log.warn(XavaResources.getString("module_not_authorized"), ex); return false; } } public String getModuleURI(HttpServletRequest request, String moduleName) { MetaModule module = getModuleByName(moduleName); if (module==null) return "#"; String organization = Organizations.getCurrent(request); String prefix = organization == null?"":"/o/" + organization; return "/" + module.getMetaApplication().getName() + prefix + "/m/" + module.getName(); } public String getModuleURI(HttpServletRequest request, MetaModule module) { String organization = Organizations.getCurrent(request); String prefix = organization == null?"":"/o/" + organization; return "/" + module.getMetaApplication().getName() + prefix + "/m/" + module.getName(); } boolean isModuleAuthorized(MetaModule module) { if (module.getName().equals(FIRST_STEPS)) return true; return Collections.binarySearch(getAll(), module, comparator) >= 0; } private void storeTopModules() { storeModulesInPreferences(topModules, "", MODULES_ON_TOP, true); } private void storeBookmarkModules() { storeModulesInPreferences(bookmarkModules, "bookmark.", BOOKMARK_MODULES, false); } private void storeModulesInPreferences(Collection<MetaModule> modules, String prefix, int limit, boolean storeCurrent) { try { Preferences preferences = getPreferences(); int i=0; for (MetaModule module: modules) { preferences.put(prefix + "application." + i, module.getMetaApplication().getName()); preferences.put(prefix + "module." + i, module.getName()); i++; } for (; i < limit; i++) { preferences.remove(prefix + "application." + i); preferences.remove(prefix + "module." + i); } // changed by lostinsoftware // if (storeCurrent && !"SignIn".equals(current.getName()) ) { // preferences.put("current", current.getName()); // } if (storeCurrent && !"SignIn".equals(current.getName()) && NaviOXPreferences.getInstance().isStartInLastVisitedModule() ) { preferences.put("current", current.getName()); } // end of change by lostinsoftware preferences.flush(); } catch (Exception ex) { log.warn(XavaResources.getString("storing_modules_problem"), ex); } } private Preferences getPreferences() throws BackingStoreException { return Users.getCurrentPreferences().node(getPreferencesNodeName()); } private static String getPreferencesNodeName() { if (preferencesNodeName == null) { Collection<MetaApplication> apps = MetaApplications.getMetaApplications(); for (MetaApplication app: apps) { preferencesNodeName = "naviox." + app.getName(); break; } if (preferencesNodeName == null) preferencesNodeName = "naviox.UNKNOWN"; } return preferencesNodeName; } public Collection<MetaModule> getTopModules() { return topModules; } public Collection<MetaModule> getBookmarkModules() { if (bookmarkModules == null) loadBookmarkModules(); return bookmarkModules; } public List<MetaModule> getAll() { if (all == null) { all = ModulesProvider.getAll(); Collections.sort(all, comparator); // Build map if (all!=null && all.size()>0) { modules = new HashMap<String, MetaModule>(); for (MetaModule module: all) { modules.put(module.getName(), module); } } } return all; } private int indexOf(Collection<MetaModule> topModules, MetaModule current) { int idx = 0; for (MetaModule module: topModules) { if (module.getName().equals(current.getName()) && module.getMetaApplication().getName().equals(current.getMetaApplication().getName())) return idx; idx++; } return -1; } public MetaModule getModuleByName(String moduleName) { if (modules==null) return null; return modules.get(moduleName); } private static class ModuleComparator implements Comparator<MetaModule> { public int compare(MetaModule a, MetaModule b) { return a.getName().compareTo(b.getName()); } } } |
mainmenu.jsp is:
1 2 3 4 5 6 |
<%@include file="../xava/imports.jsp"%> <div id="main_menu"> <p class="screenshot"><img src="../naviox/images/buggati.jpg"/></p> <p class="screenshot"><a href="https://www.flickr.com/photos/andyread2012/10137544096/" target="_blank">https://www.flickr.com/photos/andyread2012/10137544096/</a></p> </div> |
As you can see, a new image file, buggati.jsp, has be added under naviox/images folder to be shown in the middle of the main page.
Finally, you have to set false the navigation options properties, startInLastVisitedModule and rememberVisitedModules, in naviox.properties, because in this example it does not make sense to be set true.
Applying our own security
So far you have used the new security system only for the main navigation bar. What you want now is to use this security system, for example, to hide or show a field in a module. In this section, you are going to hide/show field image of the table productlines depending on the user’s rol. This field will be hidden/shown in detail mode and list mode.
What you have to do is:
- Define a new action in which you will be able to show/hide a property image of the productlines module.
- Define a new controller with the new action created in the previous point
Due to the fact that you want hide/show properties in detail and list mode, you have to create a new action class extending from TabBaseAction. The source of the new action class, HideProductImageAction, is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package com.lostinsoftware.classicmodels.actions; import org.openxava.actions.TabBaseAction; import com.lostinsoftware.security.Security; /** * @author lostinsoftware * */ public class HideProductImageAction extends TabBaseAction { @Override public void execute() throws Exception { boolean hideImage = Security.hasPermission(Security.OBJ_PRODUCTLINES , Security.ACT_HIDE_IMAGE); getView().setHidden("image", hideImage); // Hide in detail mode getTab().getMetaProperty("image").setHidden(hideImage); // Hide in list mode } } |
Then you have to define a new controller, with the same name that the module where action has to be executed. The definition must be done in controllers.xml file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?xml version = "1.0" encoding = "ISO-8859-1"?> <!DOCTYPE controllers SYSTEM "dtds/controllers.dtd"> <controllers> <!-- Environment variable: <env-var name="ClassicModelsOX_DEFAULT_YEAR" value="2015"/> --> <!-- Session object: <object name="ClassicModelsOX_activeYear" class="java.lang.Integer" value="2015" scope="global"/> --> <!-- Controller: <controller name="Teacher"> <extends controller="Typical"/> <action name="new" image="new.gif" keystroke="Control N" class="actions.CreateTeacher"> </action> </controller> --> <controller name="Productlines"> <extends controller="Typical"/> <action name="hideProductImage" on-init="true" hidden="true" class="com.lostinsoftware.classicmodels.actions.HideProductImageAction"> </action> </controller> </controllers> |
The action must be executed when the module is initiated (on-init=”true”) and must no be executed by user (hidden=”true”).
By default, listEditor.jsp is the editor used for lists. This editor does not take into account if a property must be hidden (perhaps, this behaviour is an error). For that reason, you have to define a new editor (listEditorHidingProperties.jsp) in which properties to be hidden are taken into account.
The new editor is definied in editors.xml.
1 2 3 4 5 6 7 8 9 |
<?xml version = "1.0" encoding = "ISO-8859-1"?> <!DOCTYPE editors SYSTEM "dtds/editors.dtd"> <editors> <editor url="listEditorHidingProperties.jsp"> <for-tabs /> </editor> </editors> |
The new editor is applied to all modules (<for-tabs />).
listEditorHidingProperties.jsp is exactly equal to listEditor.jsp, except that there are some lines similar to
if (property.isHidden()) continue;
at strategic points.
The complete code of listEditorHidingProperties.jsp is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 |
<%@ include file="../imports.jsp"%> <%@ page import="java.util.Collection"%> <%@ page import="java.util.Map"%> <%@ page import="org.openxava.util.Labels"%> <%@ page import="org.openxava.tab.impl.IXTableModel" %> <%@ page import="org.openxava.tab.Tab"%> <%@ page import="org.openxava.util.Strings" %> <%@ page import="org.openxava.util.XavaPreferences" %> <%@ page import="org.openxava.model.meta.MetaProperty" %> <%@ page import="org.openxava.web.WebEditors" %> <%@ page import="org.openxava.util.Is" %> <%@ page import="org.openxava.web.Ids" %> <%@ page import="org.openxava.controller.meta.MetaAction" %> <%@ page import="org.openxava.controller.meta.MetaControllers" %> <%@ page import="org.openxava.web.Actions" %> <%@ page import="org.openxava.util.Users" %> <%@ page import="java.util.prefs.Preferences" %> <%@ page import="org.openxava.util.XavaResources"%> <jsp:useBean id="errors" class="org.openxava.util.Messages" scope="request"/> <jsp:useBean id="context" class="org.openxava.controller.ModuleContext" scope="session"/> <jsp:useBean id="style" class="org.openxava.web.style.Style" scope="request"/> <% org.openxava.controller.ModuleManager manager = (org.openxava.controller.ModuleManager) context.get(request, "manager", "org.openxava.controller.ModuleManager"); String collection = request.getParameter("collection"); String id = "list"; String collectionArgv = ""; String prefix = ""; String tabObject = request.getParameter("tabObject"); String scrollId = "list_scroll"; tabObject = (tabObject == null || tabObject.equals(""))?"xava_tab":tabObject; if (collection != null && !collection.equals("")) { id = collection; collectionArgv=",collection="+collection; prefix = tabObject + "_"; scrollId = "collection_scroll"; } org.openxava.tab.Tab tab = (org.openxava.tab.Tab) context.get(request, tabObject); tab.setIgnorePageRowCount(!style.isChangingPageRowCountAllowed()); String action=request.getParameter("rowAction"); action=action==null?manager.getEnvironment().getValue("XAVA_LIST_ACTION"):action; String viewObject = request.getParameter("viewObject"); String actionArgv = viewObject != null && !viewObject.equals("")?",viewObject=" + viewObject:""; viewObject = (viewObject == null || viewObject.equals(""))?"xava_view":viewObject; org.openxava.view.View view = (org.openxava.view.View) context.get(request, viewObject); String sonlyOneActionPerRow = request.getParameter("onlyOneActionPerRow"); java.util.Collection rowActions = null; if (sonlyOneActionPerRow == null || !Boolean.parseBoolean(sonlyOneActionPerRow)) { rowActions = view.isRepresentsCollection()?view.getRowActionsNames():manager.getRowActionsNames(); } else { rowActions = java.util.Collections.EMPTY_SET; } String sfilter = request.getParameter("filter"); boolean filter = !"false".equals(sfilter); String displayFilter = tab.isFilterVisible()?"":"none"; String displayFilterButton = tab.isFilterVisible()?"none":""; String lastRow = request.getParameter("lastRow"); boolean singleSelection="true".equalsIgnoreCase(request.getParameter("singleSelection")); String onSelectCollectionElementAction = view.getOnSelectCollectionElementAction(); MetaAction onSelectCollectionElementMetaAction = Is.empty(onSelectCollectionElementAction) ? null : MetaControllers.getMetaAction(onSelectCollectionElementAction); String selectedRowStyle = style.getSelectedRowStyle(); String rowStyle = "border-bottom: 1px solid;"; int currentRow = ((Number) context.get(request, "xava_row")).intValue(); String cssCurrentRow = style.getCurrentRow(); int totalSize = -1; if (request.getAttribute(org.openxava.tab.Tab.TAB_RESETED_PREFIX + tab) == null) { tab.setRequest(request); tab.reset(); request.setAttribute(org.openxava.tab.Tab.TAB_RESETED_PREFIX + tab, Boolean.TRUE); } boolean resizeColumns = style.allowsResizeColumns() && tab.isResizeColumns(); String browser = request.getHeader("user-agent"); boolean scrollSupported = !(browser != null && (browser.indexOf("MSIE 6") >= 0 || browser.indexOf("MSIE 7") >= 0)); String styleOverflow = org.openxava.web.Lists.getOverflow(browser, tab.getMetaProperties()); %> <input type="hidden" name="xava_list<%=tab.getTabName()%>_filter_visible"/> <% if (collection == null || collection.equals("")) { %> <table width="100%" class=<%=style.getListTitleWrapper()%>> <tr><td class=<%=style.getListTitle()%>> <% if (style.isShowModuleDescription()) { %> <%=manager.getModuleDescription()%> <% } %> <% if (tab.isTitleVisible()) { %> <% if (style.isShowModuleDescription()) { %> - <% } %> <span id="list-title"><%=tab.getTitle()%></span> <% } %> <% if (style.isShowRowCountOnTop()) { totalSize = tab.getTotalSize(); int finalIndex = Math.min(totalSize, tab.getFinalIndex()); %> <span class="<%=style.getHeaderListCount()%>"> <%=XavaResources.getString(request, "header_list_count", new Integer(tab.getInitialIndex() + 1), new Integer(finalIndex), new Integer(totalSize))%> </span> <% } %> </td></tr> </table> <% } %> <% if (resizeColumns && scrollSupported) { %> <div class="<xava:id name='<%=scrollId%>'/>" style="<%=styleOverflow%>"> <% } %> <table id="<xava:id name='<%=id%>'/>" class="xava_sortable_column <%=style.getList()%>" <%=style.getListCellSpacing()%> style="<%=style.getListStyle()%>"> <tr class="<%=style.getListHeader()%>"> <th class="<%=style.getListHeaderCell()%>" style="text-align: center"> <nobr> <% if (tab.isCustomizeAllowed()) { %> <a id="<xava:id name='<%="customize_" + id%>'/>" href="javascript:openxava.customizeList('<%=request.getParameter("application")%>', '<%=request.getParameter("module")%>', '<%="customize_" + id%>')" title="<xava:message key='customize_list'/>"><img align='absmiddle' src='<%=request.getContextPath()%>/<%=style.getImagesFolder()%>/<%=style.getCustomizeListImage()%>' border='0' /></a> <% if (tab.isCustomizeAllowed()) { %> <span class="<xava:id name='<%="customize_" + id%>'/>" style="display: none;"> <a id="<xava:id name='<%="show_filter_" + id%>'/>" style="display: <%=displayFilterButton%>" href="javascript:openxava.setFilterVisible('<%=request.getParameter("application")%>', '<%=request.getParameter("module")%>', '<%=id%>', '<%=tabObject%>', true)" title="<xava:message key='show_filters'/>"><img id="<xava:id name='<%="filter_image_" + id%>'/>" align='middle' src='<%=request.getContextPath()%>/<%=style.getImagesFolder()%>/<%=style.getShowFilterImage()%>' border='0' /></a> <xava:image action="List.addColumns" argv="<%=collectionArgv%>"/> </span> <% } } %> </nobr> </th> <th class="<%=style.getListHeaderCell()%>" width="5"> <% if (!singleSelection){ String actionOnClickAll = Actions.getActionOnClickAll( request.getParameter("application"), request.getParameter("module"), onSelectCollectionElementAction, viewObject, prefix, selectedRowStyle, rowStyle, tabObject); %> <INPUT type="CHECKBOX" name="<xava:id name='xava_selected_all'/>" value="<%=prefix%>selected_all" <%=actionOnClickAll%> /> <% } %> </th> <% java.util.Collection properties = tab.getMetaProperties(); java.util.Iterator it = properties.iterator(); int columnIndex = 0; Preferences preferences = Users.getCurrentPreferences(); while (it.hasNext()) { MetaProperty property = (MetaProperty) it.next(); if (property.isHidden()) continue; String align = ""; if (style.isAlignHeaderAsData()) { align =property.isNumber() && !property.hasValidValues()?"vertical-align: middle;text-align: right":"vertical-align: middle"; } int columnWidth = tab.getColumnWidth(columnIndex); String width = columnWidth<0 || !resizeColumns?"":"width: " + columnWidth + "px"; %> <th class="<%=style.getListHeaderCell()%>" style="<%=align%>; padding-right: 0px" data-property="<%=property.getQualifiedName()%>"> <nobr> <div id="<xava:id name='<%=id%>'/>_col<%=columnIndex%>" class="<%=((resizeColumns)?("xava_resizable"):("")) %>" style="overflow: hidden; <%=width%>" > <% if (tab.isCustomizeAllowed()) { %> <span class="<xava:id name='<%="customize_" + id%>'/>" style="display: none;"> <img class="xava_handle" align='absmiddle' src='<%=request.getContextPath()%>/<%=style.getImagesFolder()%>/<%=style.getMoveColumnImage()%>' border='0' /> </span> <% } %> <% String label = property.getQualifiedLabel(request); if (resizeColumns) label = label.replaceAll(" ", " "); if (property.isCalculated()) { %> <%=label%> <% } else { %> <span class="<%=style.getListOrderBy()%>"> <xava:link action='List.orderBy' argv='<%="property="+property.getQualifiedName() + collectionArgv%>'><%=label%></xava:link> </span> <% if (tab.isOrderAscending(property.getQualifiedName())) { %> <img src="<%=request.getContextPath()%>/xava/images/<%=style.getAscendingImage()%>" border="0" align="middle"/> <% } %> <% if (tab.isOrderDescending(property.getQualifiedName())) { %> <img src="<%=request.getContextPath()%>/xava/images/<%=style.getDescendingImage()%>" border="0" align="middle"/> <% } %> <% if (tab.isOrderAscending2(property.getQualifiedName())) { %> <img src="<%=request.getContextPath()%>/xava/images/<%=style.getAscending2Image()%>" border="0" align="middle"/> <% } %> <% if (tab.isOrderDescending2(property.getQualifiedName())) { %> <img src="<%=request.getContextPath()%>/xava/images/<%=style.getDescending2Image()%>" border="0" align="middle"/> <% } %> <% } if (tab.isCustomizeAllowed()) { %> <span class="<xava:id name='<%="customize_" + id%>'/>" style="display: none;"> <a href="javascript:openxava.removeColumn('<%=request.getParameter("application")%>', '<%=request.getParameter("module")%>', '<xava:id name='<%=id%>'/>_col<%=columnIndex%>', '<%=tabObject%>')" title="<xava:message key='remove_column'/>"><img align='absmiddle' src='<%=request.getContextPath()%>/<%=style.getImagesFolder()%>/<%=style.getRemoveColumnImage()%>' border='0' /></a> </span> <% } %> </div> </nobr> </th> <% columnIndex++; } %> </tr> <% if (filter) { %> <tr id="<xava:id name='<%="list_filter_" + id%>'/>" class=<%=style.getListSubheader()%> style="display: <%=displayFilter%>"> <td class="<%=style.getFilterCell()%> <%=style.getListSubheaderCell()%>"> <% if (tab.isCustomizeAllowed()) { %> <span class="<xava:id name='<%="customize_" + id%>'/>" style="display: none;"> <a id="<xava:id name='<%="hide_filter_" + id%>'/>" href="javascript:openxava.setFilterVisible('<%=request.getParameter("application")%>', '<%=request.getParameter("module")%>', '<%=id%>', '<%=tabObject%>', false)" title="<xava:message key='hide_filters'/>"><img id="<xava:id name='<%="filter_image_" + id%>'/>" src='<%=request.getContextPath()%>/<%=style.getImagesFolder()%>/<%=style.getHideFilterImage()%>' border='0' style='vertical-align:text-top;'/></a> </span> <% } %> <xava:action action="List.filter" argv="<%=collectionArgv%>"/> </td> <td class=<%=style.getListSubheaderCell()%> width="5"> <a title='<xava:message key="clear_condition_values"/>' href="javascript:void(0)"> <img id="<xava:id name='<%=prefix + "xava_clear_condition"%>' />" src='<%=request.getContextPath()%>/xava/images/clear-right.gif' border='0' align='middle' onclick="openxava.clearCondition('<%=request.getParameter("application")%>', '<%=request.getParameter("module")%>', '<%=prefix%>')"/> </a> </td> <% it = properties.iterator(); String [] conditionValues = tab.getConditionValues(); String [] conditionValuesTo = tab.getConditionValuesTo(); String [] conditionComparators = tab.getConditionComparators(); int iConditionValues = -1; columnIndex = 0; while (it.hasNext()) { MetaProperty property = (MetaProperty) it.next(); if (property.isHidden()) continue; if (!property.isCalculated()) { iConditionValues++; boolean isValidValues = property.hasValidValues(); boolean isString = "java.lang.String".equals(property.getType().getName()); boolean isBoolean = "boolean".equals(property.getType().getName()) || "java.lang.Boolean".equals(property.getType().getName()); boolean isDate = java.util.Date.class.isAssignableFrom(property.getType()) && !property.getType().equals(java.sql.Time.class); boolean isTimestamp = property.isTypeOrStereotypeCompatibleWith(java.sql.Timestamp.class); String editorURLDescriptionsList = WebEditors.getEditorURLDescriptionsList(tab.getTabName(), tab.getModelName(), Ids.decorate(request, property.getQualifiedName()), iConditionValues, prefix, property.getQualifiedName(), property.getName()); int maxLength = 100; int length = Math.min(isString?property.getSize()*4/5:property.getSize(), 20); String value= conditionValues==null?"":conditionValues[iConditionValues]; String valueTo= conditionValuesTo==null?"":conditionValuesTo[iConditionValues]; String comparator = conditionComparators==null?"":Strings.change(conditionComparators[iConditionValues], "=", Tab.EQ_COMPARATOR); int columnWidth = tab.getColumnWidth(columnIndex); String width = columnWidth<0 || !resizeColumns?"":"width: " + columnWidth + "px"; %> <td class="<%=style.getListSubheaderCell()%>" align="left"> <div class="<xava:id name='<%=id%>'/>_col<%=columnIndex%>" style="overflow: hidden; <%=width%>; padding-right: 12px;"> <% if (isValidValues) { %> <%-- Boolean.toString( ) for base0 is needed in order to work in WebSphere 6 --%> <jsp:include page="comparatorsValidValuesCombo.jsp"> <jsp:param name="validValues" value="<%=property.getValidValuesLabels(request)%>" /> <jsp:param name="value" value="<%=value%>" /> <jsp:param name="base0" value="<%=Boolean.toString(!property.isNumber())%>" /> <jsp:param name="prefix" value="<%=prefix%>"/> <jsp:param name="index" value="<%=iConditionValues%>"/> </jsp:include> <% } else if (!Is.empty(editorURLDescriptionsList)) { %> <jsp:include page="<%=editorURLDescriptionsList%>" > <jsp:param name="value" value="<%=value%>" /> </jsp:include> <% } else if (isBoolean) { %> <jsp:include page="comparatorsBooleanCombo.jsp"> <jsp:param name="comparator" value="<%=comparator%>" /> <jsp:param name="prefix" value="<%=prefix%>"/> <jsp:param name="index" value="<%=iConditionValues%>"/> </jsp:include> <% } else { // Not boolean String idConditionValue = Ids.decorate(request, prefix + "conditionValue." + iConditionValues); String idConditionValueTo = Ids.decorate(request, prefix + "conditionValueTo." + iConditionValues); String styleConditionValueTo = "range_comparator".equals(comparator) ? "display: inline; " : "display: none;"; String labelFrom = "range_comparator".equals(comparator) ? Labels.get("from") : ""; String labelTo = Labels.get("to"); String urlComparatorsCombo = "comparatorsCombo.jsp" // in this way because websphere 6 has problems with jsp:param + "?comparator=" + comparator + "&isString=" + isString + "&isDate=" + isDate + "&prefix=" + prefix + "&index=" + iConditionValues + "&idConditionValue=" + idConditionValue + "&idConditionValueTo=" + idConditionValueTo; %> <jsp:include page="<%=urlComparatorsCombo%>" /> <br/> <nobr> <input id="<%=idConditionValue%>" name="<%=idConditionValue%>" class=<%=style.getEditor()%> type="text" maxlength="<%=maxLength%>" size="<%=length%>" value="<%=value%>" placeholder="<%=labelFrom%>" style="width: 100%; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box;"/><% if (isDate) { %><a href="javascript:showCalendar('<%=idConditionValue%>', '<%=org.openxava.util.Dates.dateFormatForJSCalendar(org.openxava.util.Locales.getCurrent(), isTimestamp)%>'<%=isTimestamp?", '12'":""%>)" style='position: relative; right: 25px;' tabindex="999"><img src="<%=request.getContextPath() %>/xava/images/calendar.gif" alt="..." style='vertical-align: middle;'/></a> <% } %> </nobr> <br/> <nobr> <input id="<%=idConditionValueTo%>" name="<%=idConditionValueTo%>" class=<%=style.getEditor()%> type="text" maxlength="<%=maxLength%>" size="<%=length%>" value="<%=valueTo%>" placeholder="<%=labelTo%>" style="<%=styleConditionValueTo%>; width: 100%; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box;"/><% if (isDate) { %><a style="position: relative; right: 25px; <%=styleConditionValueTo%>" href="javascript:showCalendar('<%=idConditionValueTo%>', '<%=org.openxava.util.Dates.dateFormatForJSCalendar(org.openxava.util.Locales.getCurrent(), isTimestamp)%>'<%=isTimestamp?", '12'":""%>)" tabindex="999"><img src="<%=request.getContextPath() %>/xava/images/calendar.gif" alt="..." style='vertical-align: middle;'/></a> <% } %> </nobr> <% } %> </div> </td> <% } else { %> <th class=<%=style.getListSubheaderCell()%>> <div class="<xava:id name='<%=id%>'/>_col<%=columnIndex%>"/> </th> <% } columnIndex++; } // while %> </tr> <% } /* if (filter) */ %> <% if (tab.isRowsHidden()) { %> <tr id="nodata"><td align="center"> <xava:link action="List.showRows" argv="<%=collectionArgv%>"/> </td></tr> <% } else { IXTableModel model = tab.getTableModel(); totalSize = totalSize < 0?tab.getTotalSize():totalSize; if (totalSize > 0) { for (int f=tab.getInitialIndex(); f<model.getRowCount() && f < tab.getFinalIndex(); f++) { String checked=tab.isSelected(f)?"checked='true'":""; String cssClass=f%2==0?style.getListPair():style.getListOdd(); String cssCellClass=f%2==0?style.getListPairCell():style.getListOddCell(); String cssStyle = tab.getStyle(f); if (cssStyle != null) { cssClass = cssClass + " " + cssStyle; if (style.isApplySelectedStyleToCellInList()) cssCellClass = cssCellClass + " " + cssStyle; } String events=f%2==0?style.getListPairEvents():style.getListOddEvents(); String cssClassToActionOnClick = cssClass; if (tab.isSelected(f)){ cssClass = "_XAVA_SELECTED_ROW_ " + cssClass; rowStyle = rowStyle + " " + selectedRowStyle; } String prefixIdRow = Ids.decorate(request, prefix); %> <tr id="<%=prefixIdRow%><%=f%>" class="<%=cssClass%>" <%=events%> style="<%=rowStyle%>"> <td class="<%=cssCellClass%>" style="vertical-align: middle;text-align: center; <%=style.getListCellStyle()%>"> <%if (resizeColumns) {%><nobr><%}%> <% if (!org.openxava.util.Is.emptyString(action)) { %> <xava:action action='<%=action%>' argv='<%="row=" + f + actionArgv%>'/> <% } if (style.isSeveralActionsPerRow()) for (java.util.Iterator itRowActions = rowActions.iterator(); itRowActions.hasNext(); ) { String rowAction = (String) itRowActions.next(); %> <xava:action action='<%=rowAction%>' argv='<%="row=" + f + actionArgv%>'/> <% } String actionOnClick = Actions.getActionOnClick( request.getParameter("application"), request.getParameter("module"), onSelectCollectionElementAction, f, viewObject, prefixIdRow + f, selectedRowStyle, rowStyle, onSelectCollectionElementMetaAction, tabObject); %> <%if (resizeColumns) {%></nobr><%}%> </td> <td class="<%=cssCellClass%>" style="<%=style.getListCellStyle()%>"> <INPUT type="<%=singleSelection?"RADIO":"CHECKBOX"%>" name="<xava:id name='xava_selected'/>" value="<%=prefix + "selected"%>:<%=f%>" <%=checked%> <%=actionOnClick%>/> </td> <% for (int c=0; c<model.getColumnCount(); c++) { MetaProperty p = tab.getMetaProperty(c); if (p.isHidden()) continue; String align =p.isNumber() && !p.hasValidValues()?"vertical-align: middle;text-align: right; ":"vertical-align: middle; "; String cellStyle = align + style.getListCellStyle(); int columnWidth = tab.getColumnWidth(c); String width = columnWidth<0 || !resizeColumns?"":"width: " + columnWidth + "px"; String fvalue = null; fvalue = WebEditors.format(request, p, model.getValueAt(f, c), errors, view.getViewName(), true); Object title = WebEditors.formatTitle(request, p, model.getValueAt(f, c), errors, view.getViewName(), true); %> <td class="<%=cssCellClass%>" style="<%=cellStyle%>; padding-right: 0px"> <% if (style.isRowLinkable()) { %> <xava:link action='<%=action%>' argv='<%="row=" + f + actionArgv%>' cssClass='<%=cssStyle%>' cssStyle="text-decoration: none; outline: none"> <div title="<%=title%>" class="<xava:id name='tipable'/> <xava:id name='<%=id%>'/>_col<%=c%>" style="overflow: hidden; <%=width%>"> <%if (resizeColumns) {%><nobr><%}%> <%=fvalue%> <%if (resizeColumns) {%></nobr><%}%> </div> </xava:link> <% } else { %> <div title="<%=title%>" class="<xava:id name='tipable'/> <xava:id name='<%=id%>'/>_col<%=c%>" style="overflow: hidden; <%=width%>"> <%if (resizeColumns) {%><nobr><%}%> <%=fvalue%> <%if (resizeColumns) {%></nobr><%}%> </div> <% } %> </td> <% } %> </tr> <% } %> <tr class="<%=style.getTotalRow()%>"> <td style="<%=style.getTotalEmptyCellStyle()%>"/> <td style="<%=style.getTotalEmptyCellStyle()%>"/> <% for (int c=0; c<model.getColumnCount(); c++) { MetaProperty p = tab.getMetaProperty(c); if (p.isHidden()) continue; String align =p.isNumber() && !p.hasValidValues()?"text-align: right; ":""; String cellStyle = align + style.getTotalCellStyle(); int columnWidth = tab.getColumnWidth(c); String width = columnWidth<0 || !resizeColumns?"":"width: " + columnWidth + "px"; if (tab.hasTotal(c)) { String ftotal = WebEditors.format(request, p, tab.getTotal(c), errors, view.getViewName(), true); %> <td class="<%=style.getTotalCell()%>" style="<%=cellStyle%>; padding-right: 0px"> <div class="<xava:id name='<%=id%>'/>_col<%=c%>" style="overflow: hidden; <%=width%>"> <nobr> <% if (!tab.isFixedTotal(c) && XavaPreferences.getInstance().isSummationInList()) { %> <xava:image action='List.removeColumnSum' argv='<%="property="+p.getQualifiedName() + collectionArgv%>' cssStyle="vertical-align: top;"/> <% } %> <%=ftotal%> </nobr> </div> </td> <% } else if (XavaPreferences.getInstance().isSummationInList() && tab.isTotalCapable(c)) { %> <td class="<%=style.getTotalCapableCell()%>" style="<%=style.getTotalCapableCellStyle() %>"> <div class="<xava:id name='<%=id%>'/>_col<%=c%>" style="overflow: hidden; <%=width%>"> <xava:action action='List.sumColumn' argv='<%="property="+p.getQualifiedName() + collectionArgv%>'/> </div> </td> <% } else if (tab.hasTotal(c + 1)) { %> <td class="<%=style.getTotalLabelCell()%>" style="<%=style.getTotalLabelCellStyle()%>"> <div class="<xava:id name='<%=id%>'/>_col<%=c%>" style="overflow: hidden; <%=width%>"> <%=tab.getTotalLabel(0, c + 1)%> </div> </td> <% } else { %> <td style="<%=style.getTotalEmptyCellStyle()%>"/> <% } } %> </tr> <% int additionalTotalsCount = tab.getAdditionalTotalsCount() + 1; for (int i=1; i<additionalTotalsCount; i++) { %> <tr class="<%=style.getTotalRow()%>"> <td style="<%=style.getTotalEmptyCellStyle()%>"/> <td style="<%=style.getTotalEmptyCellStyle()%>"/> <% for (int c=0; c<model.getColumnCount(); c++) { MetaProperty p = tab.getMetaProperty(c); if (p.isHidden()) continue; String align =p.isNumber() && !p.hasValidValues()?"text-align: right; ":""; String cellStyle = align + style.getTotalCellStyle(); int columnWidth = tab.getColumnWidth(c); String width = columnWidth<0 || !resizeColumns?"":"width: " + columnWidth + "px"; if (tab.hasTotal(i, c)) { String ftotal = WebEditors.format(request, p, tab.getTotal(i, c), errors, view.getViewName(), true); %> <td class="<%=style.getTotalCell()%>" style="<%=cellStyle%>"> <div class="<xava:id name='<%=id%>'/>_col<%=c%>" style="overflow: hidden; <%=width%>"> <nobr> <%=ftotal%> </nobr> </div> </td> <% } else if (tab.hasTotal(i, c + 1)) { %> <td class="<%=style.getTotalLabelCell()%>" style="<%=style.getTotalLabelCellStyle()%>"> <div class="<xava:id name='<%=id%>'/>_col<%=c%>" style="overflow: hidden; <%=width%>"> <%=tab.getTotalLabel(i, c + 1)%> </div> </td> <% } else { %> <td style="<%=style.getTotalEmptyCellStyle()%>"> <div class="<xava:id name='<%=id%>'/>_col<%=c%>"/> </td> <% } } %> </tr> <% } // for additionalTotalsCount } else { %> <tr id="nodata"><td class="<%=totalSize==0?style.getMessages():style.getErrors()%>"> <% if (totalSize == 0) { %> <b><xava:message key="no_objects"/></b> <% } else { %> <b><xava:message key="list_error"/></b> <% } %> </td></tr> <% } } if (lastRow != null) { %> <tr> <jsp:include page="<%=lastRow%>"/> </tr> <% } %> </table> <% if (resizeColumns && scrollSupported) { %> </div> <% } %> <% if (!tab.isRowsHidden()) { %> <table width="100%" class="<%=style.getListInfo()%>" cellspacing=0 cellpadding=0> <tr class='<%=style.getListInfoDetail()%>'> <td class='<%=style.getListInfoDetail()%>'> <% int last=tab.getLastPage(); int current=tab.getPage(); if (current > 1) { %> <span class='<%=style.getFirst()%>'><span class='<%=style.getPageNavigationArrow()%>' <%=style.getPreviousPageNavigationEvents(Ids.decorate(request, id))%>><xava:image action='List.goPreviousPage' argv='<%=collectionArgv%>'/></span></span> <% } else { %> <span class='<%=style.getFirst()%>'><span class='<%=style.getPageNavigationArrowDisable()%>'><img src='<%=request.getContextPath()%>/<%=style.getImagesFolder()%>/<%=style.getPreviousPageDisableImage()%>' border=0 align="absmiddle"/></span></span> <% } %> <span class="<%=style.getPageNavigationPages()%>"> <% for (int i=1; i<=last; i++) { if (i == current) { if (style.isShowPageNumber()) { %> <span class="<%=style.getPageNavigationSelected()%>"><%=i%></span> <% } else {%> <span class="<%=style.getPageNavigationSelected()%>"> <img src='<%=request.getContextPath()%>/<%=style.getImagesFolder()%>/<%=style.getPageNavigationSelectedImage()%>' border=0 align="absmiddle"/> </span> <% } %> <% } else { if (style.isShowPageNumber()) { %> <xava:link action='List.goPage' argv='<%="page=" + i + collectionArgv%>' cssClass="<%=style.getPageNavigation()%>"><%=i%></xava:link> <% } else { %> <span class="<%=style.getPageNavigation()%>"> <img src='<%=request.getContextPath()%>/<%=style.getImagesFolder()%>/<%=style.getPageNavigationImage()%>' border=0 align="absmiddle"/> </span> <% } } } %> </span> <% if (!tab.isLastPage()) { %> <span class='<%=style.getLast()%>'> <span class='<%=style.getPageNavigationArrow()%>' <%=style.getNextPageNavigationEvents(Ids.decorate(request, id)) %>> <xava:image action='List.goNextPage' argv='<%=collectionArgv%>'/> </span> </span> <% } else { %> <span class='<%=style.getLast()%>'> <span class='<%=style.getPageNavigationArrowDisable()%>'><img src='<%=request.getContextPath()%>/<%=style.getImagesFolder()%>/<%=style.getNextPageDisableImage()%>' border=0 align="absmiddle"/> </span> </span> <% } %> <% if (style.isChangingPageRowCountAllowed()) { %> <select id="<xava:id name='<%=id + "_rowCount"%>'/>" class=<%=style.getEditor()%> onchange="openxava.setPageRowCount('<%=request.getParameter("application")%>', '<%=request.getParameter("module")%>', '<%=collection==null?"":collection%>', this)"> <% int [] rowCounts = { 5, 10, 12, 15, 20 }; // The peformance with more than 20 rows is poor for page reloading for (int i=0; i<rowCounts.length; i++) { String selected = rowCounts[i] == tab.getPageRowCount()?"selected='selected'":""; %> <option value="<%=rowCounts[i]%>" <%=selected %>><%=rowCounts[i]%></option> <% } %> </select> <span class="<%=style.getRowsPerPage()%>"> <xava:message key="rows_per_page"/> </span> <% } // of if (style.isChangingPageRowCountAllowed()) %> </td> <td style='text-align: right; vertical-align: middle' class='<%=style.getListInfoDetail()%>'> <% if (XavaPreferences.getInstance().isShowCountInList() && !style.isShowRowCountOnTop()) { %> <xava:message key="list_count" intParam="<%=totalSize%>"/> <% } %> <% if (collection == null && style.isHideRowsAllowed()) { %> (<xava:link action="List.hideRows" argv="<%=collectionArgv%>"/>) <% } %> </td> </tr> </table> <% } %> |
Summary
This blog post has taught us how to customize our own navigation menu and how to apply our own security system and in which parts of the code you have to pay attention to carry out these modifications. In this blog post an example has been discussed as a possible solution, but other solutions can obviously be implemented.
Related posts
Reverse Engineering and Code Generation
Main JSPs in OpenXava
P.S. You can get the example of this blog post from Github.
Sorry, the comment form is closed at this time.