Skip to main content

Customizing navigation and security in OpenXava

· 28 min read

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:

  1. Customize our own main menu
  2. Customize the first page of the application
  3. 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.

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:

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:

<!-- 
<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 tag, and a couple of lines above tag. Your index.jsp would be now:

<% 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:

<%@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:

/*
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:

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:

<%@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:

  1. Define a new action in which you will be able to show/hide a property image of the productlines module.
  2. 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

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.

<?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.

<?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 ().

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:

<%@ 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(" ", "&nbsp;");
if (property.isCalculated()) {
%>
<%=label%>&nbsp;
<%
} else {
%>
<span class="<%=style.getListOrderBy()%>">
<xava:link action='List.orderBy' argv='<%="property="+property.getQualifiedName() + collectionArgv%>'><%=label%></xava:link>&nbsp;
</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%>&nbsp;
<%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%>&nbsp;
<%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%>&nbsp;
</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%>'/>&nbsp;
</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)%>&nbsp;
</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%>&nbsp;
</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)%>&nbsp;
</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()) { %>
&nbsp;
<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

P.S. You can get the example of this blog post from Github.