Archive

Posts Tagged ‘NetBeans’

HowTo: Code folding in NetBeans IDE source code editor

As explained near the end of https://ui.netbeans.org/docs/ui/code_folding/cf_uispec.html, the NetBeans IDE source code editor supports custom code folding tags for any language, like below (here defining the code folding tag in a Java comment, obviously need to use specific comment syntax for the respective language).

// <editor-fold desc="isUserStudent"> —————————————-

public static boolean isUserStudent(PortletRequest request)
   throws NamingException, PortletServiceUnavailableException,  PumaException, SQLException
{
   return isUserStudent(new DbAccess().getConnection(), request);
}

public static boolean isUserStudent(Connection connection, PortletRequest request)
   throws NamingException, PortletServiceUnavailableException,  PumaException, SQLException
{
   return !StringUtils.isNotPresent(getUserStudentId(connection, request));
}
 
public static boolean isUserStudent(int studentId, PortletRequest request)
   throws NamingException, PortletServiceUnavailableException,  PumaException, SQLException
{
   return isUserStudent(studentId, new DbAccess().getConnection(), request);
}

public static boolean isUserStudent(int studentId, Connection connection, PortletRequest request)
   throws NamingException, PortletServiceUnavailableException,  PumaException, SQLException
{
   return (String.valueOf(studentId).equals(getUserStudentId(connection, request)));
}
 
public static String getUserStudentId(Connection connection, PortletRequest request)
   throws NamingException, PortletServiceUnavailableException,  PumaException, SQLException
{
   return DbStudent.getStudentId(connection, Puma.getUserName(request)); 
}

// </editor-fold>————————————————————-

 

This shows up in NetBeans like below when folded:

image

You can also optionally specify defaultstate="collapsed" at the code folding tag so that when the file is opened that region appears collapsed.

Categories: Posts Tags: , , , , , , ,

Fix: Java ServletException: IncompatibleClassChangeError

was getting an error like the following at your JavaEE Servlet (Portlets are also Servlets under the hood btw):

javax.servlet.ServletException: javax.portlet.PortletException: java.lang.Throwable: java.lang.IncompatibleClassChangeError: : incorrect call to interface method

 

at first I thought the issue was with:

  <bean:message class=”someCSSstyleClass” key="someMsgKey"/>

 

and used instead:

  <span class="someCSSstyleClass"><bean:message key="someMsgKey"/></span>

 

in case the “class” attribute at bean:message tag was meaning a Java class instead of a CSS class

But, kept  on getting the same error…

Then I tried a “Clean and Build” instead of just “Build” action at NetBeans IDE and errors poped up. Had refactored an abstract class to an interface and seems NetBeans was only compiling parts of my code which can cause tricky to debug errors.

So whenever you see strange runtime errors, especially when refactoring some older project, make sure you use “Clean and Build” (sometimes called “Rebuild”) in your IDE to be safe.

%d bloggers like this: