Bech on Enterprise Java
Tuesday, March 13, 2007
  About Eclipse and Tekken
Eclipse and Tekken

The keyboard shortcuts in eclipse are a bit like advanced Tekken combat moves, for those who aren't into computer games; Tekken is a very good fighting game for the Sony Play Station consoles. A lot of the cool moves can only be made using insane combinations of the controller buttons, in the right sequence. In that sense, Eclipse and the computer game has a lot in common.

So... I'm using Eclipse for the moment, and have after a long period of swearing started to adapt a way of working that is similar to what I'm used to with IntelliJ. Here are a few painkillers for other Eclipse users that are used to IntelliJ. I guess most of this will be "old news" to experienced Eclipse users, but who knows. Why might pick up a trick or two.

Before starting I have to say that I try to learn keyboard shortcuts for everything I do. Other people prefer clicking around in the interface and I respect that. However, working with mostly the keyboard has some advantages; It's faster, It's better for your health and it's faster (did I mention that?)

Even after a months of using Eclipse, I still get confused on what shortcuts that are available through CTRL+SHIFT and what is through ALT+SHIFT. A good way to remember what is what is to think of the alt+shift shortcuts as "menu shortcuts". To Illustrate; Pressing Alt+shift+s gives you about the same options as pressing "source" on the menu. The CTRL+SHIFT shortcurs are more often helper dialogues like Open resource (CTRL+SHIFT+R) or open type. (CTRL+SHIFT+T)

Anyhow; here's a compilation of my most used keyboard shortcuts for eclipse. If you use these in combination, you can probably put the mouse away entirely.

Ctrl+M (Maximise)

I try to do as much work as possible with the source code window maximised. I try to use the "Navigator", and "Package Explorer" windows as little as possible, as I have found no way to switch to them with focus, without using the mouse.


Ctrl+F7 (Switch views)

In IntelliJ U can easily hide and show windows like the project navigator using the ALT key and number in combination, when you want the window to go away, you can press the same key, or escape.

Using the Ctrl+F7 and Ctrl+M (see previous) in combination makes navigating the different windows a bit easier. This shortcut lets you switch between the editor, navigator, console and all other views. I use it a lot to quickly go to the editor and almost always follow up with a CTRL+M, to use the entire screen area for code editing.

Ctrl + . (Next problem)

This navigates you to the next "problem" (red or yellow marker in the sidebar).

Ctrl+Shift+T (Find Type)

Finding a class in the package explorer or navigator can be like finding the famous needle in the haystack. It is often faster to hit this combo, and start typing the name of your class.

The good news is that wildcards and camel-back searching works like a dream.

Ctrl+Shift+R (Find Resource)

Same as above, only for resources that is not java classes. (JSP files ,properties etc. )

Alt+Shift+T (Refactor)

This shortcut is pretty neat as it pops up all refactoring options, given the context of the cursor position. The action you want to take is available in only one more keystroke. In full "Tekken* style" the shortcut key for "rename" is the key 'n', instead of using for example 'r' (that is unused). Don't ask me why.

Ctrl+F6 (Open files)

This is probably my single most used Eclipse shortcut. It pops up a list of all the recent files you have edited. An annoying "feature" of this key is that the CTRL key has to be pressed while doing a selection, or at least for a period of time for the window to "stick". If you briefly press Ctrl+F6, you get your last window. The design idea is probably that you often swap between the two most recent files.

I always use the combo "alt+right/left key" for that, so for me this extra "intelligence" is just annoying.

Alt+Right and left Arrows

The alt key in combination with the left and right arrow keys can be used as a "back" and "forward" in the file history.


F3 (Go to declaration) and "Ctrl clicking"

The entire source code can be navigated as a hyperlinked system. If the cursor is over a class name and you press F3, you immediately go to the declaration of that class.. Pressing F3 while the cursor is over a variable takes you to the declaration of that variable.

Similar navigation can be done by holding down the ctrl key and moving the mouse around. When the mouse pointer is hovering over a class name or variable, the name of the class or variable turns into a clickable hyperlink.

other usefull shortcuts that you're probably used to from IntelliJ

Ctrl+Shift+O (Optimize Imports)

This is one of many features that IntelliJ has implemented a bit smoother than Eclipse.

In general, the "Auto import" feature doesn't work to well if your code has compilation errors. This can be impractical if you let's for example say you want to copy / paste a block into your code from somewhere, and get a lot of "red markers" in your code as a result of the unknown classes.

In Eclipse you should avoid typing entire class names, it's better to type half way through and ctri+space to auto complete. This is because it imples an automatic import.

Ctrl+Shift+F (Format code)

This key combo formats your code according to default of project specific format.

Alt+Shift+X, T (Run as unit test)

This is one of many Tekken moves in Eclipse. Press Alt+shift+X after a while, a hint-box should appear with your choices. Press T to run the current class as a unit test . A disadvantage of using this shortcut is that the class currently in the editor has to be the unit test. This shortcut is best used in combination with the CTRL+F11 shortcut explained later.

Ctrl+F11 (Run last launch config)

If you run your unit test once using alt+shift+X (something that can and will break your fingers over time) there is no need to press the same combo again. Just use Ctrl+F11 to re-execute your last "run" or "debug" configuration.

Alt+Shift+Z

The nifty surround with functionality, also the home of the automatic collection iterator shortcut.

Alt+Shift+S (source)

Here you'll find shortcuts to all the nifty things like implement/override methods, generate getters/setters etc.

Ctrl+F8

Working with perspectives is important in eclipse. The whole editor changes it's window layout when working in debug mode. The Ctri+F8 shortcut enables you to switch back to java view (where I usually work) after a debugging session.

Ctrl + T

View Implementation/type hierarchy. If your editor is showing an interface, and you want to know all available implementations, this shortcut is handy. It also works if your cursor is located over an interface declaration.
 
Monday, November 06, 2006
  Working with JSF & MyFaces ; java.lang.IllegalStateException: Client-id : xxx is duplicated in the faces tree.
If you're working with JSF using Myfaces nad Tomahawk, and you are getting a stacktrace like this, you have probably just changed the internal structure of your JSP page. For some strange reason, that doesn't work too well in all cases.

What you need to do, is to make sure a new browser session is started, and access the page again.

java.lang.IllegalStateException: Client-id : xxx is duplicated in the faces tree. Component : _idJsp0:minus, path: {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /cars/default/jsp/agreement/bets/doors/viewd........
 
Tuesday, October 24, 2006
  Being an innocent victim of software development communism
I like Analogies from the construction industry.

A carpenter comes to the house you are building. You welcome him, but ask him to leave his tools in the car; all carpenters and craftsmen working on your house have to use the exact same tools! You hand him, not crappy tools, but different ones than he's used to. Now watch this guy fumble, stumble and ask around.

I started writing, and I am probably going to finish a lengthy post about Eclipse annoyances, and how much I love IntelliJ. After being "force fed" Eclipse for the last 3 weeks, I've got some fuel for the fire so to speak. But, that's another story.

What I was thinking the other day, was how crippled I get when someone take away the tools I'm used to and give me new ones. Standardisation may be a good thing, but I say stop when it comes to my personal tools.

Continuous build systems (including reporting tools). CMS (Code management systems like CVS, Subversion etc), Test frameworks etc of course needs to be common for a development team.

However, IMO Developer's choice of container for development and IDE must be a personal choice. It's like dictating what kind of deodorant people should put on in the morning!

Disclaimer; this is my personal view, and not one of my employer. I respect the decisions taken by my current customer to standardize, even if disagree.
 
Thursday, October 19, 2006
  Poke 53281,0
I recently heard the "Last ninja 2" soundtrack in a breakfast show on a Norwegian radio show. One thing lead to the other, And before I knew anyting of it I had a c64 emulator installed. To my great amusement, my fingers just automaticly typed in the command poke 53281,0 and poke 53280,0.....

Honour and respect to those who can reply with the result of theese commands on a C64 system .)

... And If this blog entry doesn't make any sense at all to you you're just not old enough :-)
 
Monday, August 07, 2006
  More on the BEA 8.1 Servlet Filter & RequestDispatcher issue
After doing some more research, it seems that the BEA developers found the Servlet 2.3 specification to be "ambigous", and decided to create an implementation that executes filters on both incoming http requests from cleients, and on request dispatcher requests.

This issue is resolved in the Servlet 2.4 spec. and there is a "dispatcher" element in the "filter" tag in web.xml

The valid values are:

- REQUEST: (default) only when the request comes directly from the client
- FORWARD
- INCLUDE

Please notice that the default behaviour has changed. Upgrading to Weblogic 9.2 or or doing a manual check in the filter for repeated requests solves the problem.
 
Thursday, August 03, 2006
  The BEA 8.1 Servlet Container implementation is causing problems for Jakarta Struts applications using filters.
I just discovered some strange behavior in a struts based application that uses Hibernate, and a mechanism based on Thread local variables to hold Hibernate Sessions.

Servlet filters are a great tool to handle aspects of your web application like custom Authorization & Authentication logging, modification of requests etc. The servlet 2.3 specs say the following in Section 6.2.1

"When the container receives an incoming request, it takes the first filter instance in the list and calls its doFilter method, passing in the ServletRequest and ServletResponse, and a reference to the FilterChain object it will use. "

The BEA developers have obviously interpreted this to mean incoming request from clients, i.e. "regular" http requests, and requests coming in via the RequestDispatcher class. The Oracle OC4J does not execute the filter chain for incoming RequestDispatcher calls. This is where it gets interesting for Struts based applications.

There are two types of "forwards" in struts, those with redirect="true", and redirect="false". When the redirect attribute of the forward tag in struts-config.xml is set to "true", a response is sent to the client, forcing it to send a new request to the server.

The actual HTTP Response going to the web browser may look something like this ;

HTTP/1.x 302 Moved Temporarily
Date: Thu, 03 Aug 2006 08:37:07 GMT
Server: Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)
Content-Length: 222
Connection: Keep-Alive
Keep-Alive: timeout=15, max=100
Content-Type: text/html
Location: http://localhost:9999/adminssytem/viewEmployees.do



In this case, the filter chain should- and is, executed twice per client transaction. The user does not notice both requests though. This practice is quite common when using the HTTP Post method, so that the user can "reload" the page in his browser without re-posting the form data.

The forwards with redirect="false", uses a RequestDispatcher to forward requests internally. This is sometimes also called "Server Side redirect", and is very useful since you can chain struts actions together in a "Chain of responsibility pattern". By creating small reusable actions, you can easily use them as building blocks in your application.

The fact that BEA chooses to execute the filter chain, between struts actions has a huge impact on code relying on this mechanism. Taking the example of Authorization, a costly verification of user credentials will be executed between each Struts action. With long action chains, this can be a huge performance penalty.

In this Example;

<action path="/deletePhoneNumber"

type="DeletePhoneNumberAction"

name="PhoneForm"

scope="request">

<forward name="success" path="/viewPhoneNumbers.do"/>

</action>


<action path="/viewPhoneNumbers"

type="ViewPhoneNumbersAction"

name="PhoneForm"

scope="request">

<forward name="success" path="/WEB-INF/jsp/displayNumbers.jsp"/>

</action>

A filter with a .do mapping, will be executed two times in the Weblogic server.

1) On the initial HTTP Request hits the deletePhoneNumberAction.
2) After the DeletePhoneNumberAction is finished, and before the viewPhoneNumbers Action is executed.

This can impact design, cause bugs, and slow down the system significantly. If anyone has a workaround, or know of an entry in the weblogic.xml that solves this, please feel free to comment. It would also be interesting to know the rationale behind the decision to implement the Servlet container with a very “creative” interpretation of the specification in this case.

 
Tuesday, July 25, 2006
  Struts 1.2: Why is not the reset, validate or even execute invoked?
Here is another one of those stupid mistakes that can keep you wondering what's going on;

As you probably know, Struts lets you override methods in the ActionForm class. It's quite common to override both the validate(), and reset() method.

It's however very important to notice that there exists two of each ;

public void reset(ActionMapping mapping,
javax.servlet.ServletRequest request)

public void reset(ActionMapping mapping,
javax.servlet.http.HttpServletRequest request)


and

public ActionErrors validate(ActionMapping mapping,
javax.servlet.ServletRequest request)

public ActionErrors validate(ActionMapping mapping,
javax.servlet.http.HttpServletRequest request)


If you override the wrong method (the ones with the ServletRequest signature, instead of HttpServletRequest), you'll soon notice that you code is not getting executed.

The JavaDoc claims for the generic methods "The default implementation attempts to forward to the HTTP version of this method." What "Attemts" means beats me. In the cases where I've made this mistake uptil now, that "attemt" has not succeeded.

Please note that this fact also applies to the Action class itself. There exists one execute() method for the Generic Servlet Class, and one for the HTTP Servlet.

I'm not sure why the design is like this; I havn't heard of anyone using Struts to SIP Servlets, or any other kinds of servlet other than HTTP.

If you googled for the problem, and found my page; Please let me know and add a comment ! :-)
 
I hereby promise to blog my thoguhts and views on Enterprise java, design patterns, frameworks and all other things that make life as a software developer interesting.

Name:
Location: Oslo, Oslo, Norway

www.glennbech.com

ARCHIVES
May 2005 / June 2005 / July 2005 / January 2006 / February 2006 / June 2006 / July 2006 / August 2006 / October 2006 / November 2006 / March 2007 /


Powered by Blogger