Blog Archives

May 14th, 2010
6:45 pm
Javadoc creation and formatting

Posted under Java
Tags , , , ,

Some tips and gotchas on this, as follows :-

1/ the Oracle documentation pages for Javadoc complete with examples etc. may be found here

2/ An example of Javadoc applied to a project may be found in the PropertyTree project in the repository.

3/ JAutodoc is a useful Eclipse plugin. Whilst Eclipse can generate Javadoc comments at source creation time if you tick the box for it, and lets you add them afterwards one by one via ctrl/alt/J etc., using  JAutodoc allows creation, addition or replacement of a full set of Javadoc comments to an entire project at any time. It also has a better stab at guessing comments for properties etc. than Eclipse, by parsing words out of the code. Obviously there is still a lot of manual editing to be done, but I found it a useful addition. Note that JAutodoc is available for a project on the package Explorer context menu for a project, but not on the project explorer one.

4/ Package level documentation sits in package.html in the package source directory. As Javadoc is frames based, the following doctype is recommended by Oracle for this file :- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">. Simple html is the order of the day as Javadoc has simple, somewhat retro styling. You can get new style sheets for it to spice it up, but I find the standard ones perfectly readable. Javadoc has its own Stylesheet.css, but I avoided amending this, and deliberately did not add another stylesheet of my own. Therefore, I avoided heavy use of styling, and just borrowed the odd style from the built in stylesheet for my own uses such as table header styling below.

5/ For subheadings in the package doc <h3> and <h4> worked fine.

6/ It was straightforward to add simple tables. Whilst some of the attributes are rather outdated/deprecated in favour of CSS, they are also used elsewhere in the Javadoc for its own tables, so I did not lose sleep over it. I used the TableHeadingColor class from Javadoc’s own stylesheet to give a similar background colour to my own table headers.

<table border="1" cellspacing="1" width="100%">
    <tr class="TableHeadingColor">
        <th>Column 1 Header</th>
        <th>Column 2 Header</th>
    </tr>
    <tr>
        <td>Column 1 data</td>
        <td>Column 1 data</td>
    </tr>
</table>

7/ Styling code samples is a bit messy with several tags being involved. This post here on StackOverflow discusses some of the issues In the end I used the following examples, generally going with what worked well:-

<blockquote><pre>
      PropertyTree propertyTree = new PropertyTree("lan").load("Test.properties");
</pre></blockquote>

or :-

<blockquote><pre>{@code
lan.default.broadcast=10.0.0.255
lan.default.port=7

}</pre></blockquote>

The code tag (“{@code …}” was supposed to be the one to use here (particularly when Generics are involved) but was a bit mixed in its usefulness, and I found some variations in the tabbing, and closing braces in the code can be an issue as the code tag also uses this for its own closure. I did not therefore always use it. Interestingly the above StackOverflow post cites that String.java in the JRE just uses <p><blockquote><pre>,  so I often followed suit.

8/ Individual code or data identifiers such as class and method names looked good in a fixed font when framed with <code></code>, which seemed to be the preferred way to highlight them. Sometimes I made them links as follows, but I did not do this all the time when there was already a link on the comment, as it was tedious and unnecessary. Links can be added, and you can link to a method, a class or a package (which links to package.html) by just linking to the desired level. The first parameter after {@link is the hyperlink, and the second parameter is the clickable description that appears for the hyperlink. Eclipse does code completion for the tags when you are entering them. The following example links to a property (which is specified after the “#”):-

{@link  uk.co.salientsoft.util.propertytree.TagTree#getProperty() TagTree.getProperty()}

9/ One gotcha is that for overriden methods, the Javadoc always comes from the inherited method, and the Javadoc method comments in the subclass are ignored. However, you can add additional comments by using the Javadoc documentation comment syntax (prefixed “/**” i.e. with the extra asterisk on the first line) in the subclass, and these will be added in and not ignored:-

/**
  * For the <code>NullIterator</code> this will always return <code>false</code>.
  */

10/ In Eclipse, you can create Javadoc via the Project/Create Javadoc menu bar option (this is not available on the package explorer context menu). There are a number of options when doing so, but these are not all defaulted to your previous settings when you go back next time round. You can therefore create and save an Ant build file for the Javadoc which you can then re-run much more easily. Javadoc.exe needs to be on the path for this – it should be anyway if you have Java SE installed and on the path, and for me I did not have to add it. You can then open the Ant view in Eclipse. In the view pane, right click and select Add Buildfiles… and browse for the Ant build file which you saved at Javadoc creation time. This then stays pinned to the Ant pane and you can double click it any time to recreate your Javadoc with all the saved settings.

No Comments »

March 1st, 2010
11:40 am
Multiple Versions of Office Under Windows 7 64 bit

Posted under 64 Bit
Tags , , , , ,

According to Microsoft here you can do this if you install them in increasing order, i.e. you must install the earliest first.

In my case, Office 2000 would not play ball at all, as Word 2000 froze on startup.

Office XP ran ok, and does seem to coexist with Office 2007, but there are some issues.
I had to mess around with compatibility mode for XP, but ended up taking it off as it appeared to try to run Word XP in administrator mode even though this was not enabled – strange. I ended up not needing it and Word XP started OK but was initially a bit flakey as said.

Two issues remain outstanding, but they are possible to live with:-

1/ Double clicking a .doc document always opens Word 2007, even if you try to change the file association. I had it working correctly for a little while (loading up Word XP for .docs and Word 2007 for .docx, but Word 2007 ended up taking over. This may have had something to do with the next point – ‘re-registering’

2/ Both versions wanted to reconfigure themselves each time you switched from running one version to the other one. Even on a fast PC this takes 10-20 seconds of thrashing with a conifiguration dialog displayed – not nice, although Microsoft say that this is normal behaviour if you have multiple versions (Word XP did its configuration a lot quicker). This post  describes the way around this by telling both versions of Word not to ‘rereg’ themselves, by setting the following registry keys :-

HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options\NoReReg = 1 (DWord) – for Word 2007
HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Word\Options\NoReReg = 1 (DWord) – for Word XP

This fixed the problem, although it is not entirely recommended as it may cause issues during fixes/updates that may need the ReReg to be run. I would imagine that removing the keys temporarily and re-adding them would solve this.

If I was in this situation again, I would certainly try to avoid installing multiple versions on the same OS – it is clearly not supported well. It would be best to use another machine or a VM.

No Comments »

February 12th, 2010
1:06 pm
Acronis True Image Home – errors with backups to multiple removable drives

Posted under Windows
Tags , ,

I tried using Acronis TIH 2010 to backup to 2 different removable drives, to rotate them. Initially I mounted each drive as R: when used, which requires changing the drive letter each time. As a consequence of this, I was also using a single TIH backup task and a single TIH validate task for both removable drives. However, when I came to do a separate validation of the backup on the 2nd drive, having already done the first, I received the error “The operation failed” with no other detailed information. This was strange, as the backup process had just done its own validation successfully. I suspected that Acronis was confused between the 2 backups, as both had the same name (as they were done on the same date during testing) and were on the same drive letter, even though they were different volumes. Acronis keeps an internal database of its backups as detailed here, and as the post indicates, it needs to keep track of the renaming/moving of backups. The confusion on this was compounded by this post concerning Acronis Backup & Recovery 10, which states that when using multiple usb drives as rotating backups, the same drive letter should always be used. However, this is clearly not correct in my scenario. In another test, I performed a second incremental backup on each removable drive, and Acronis asked me to browse for the correct full backup when doing the validation phase of the backup – it had clearly become confused.

I switched to using a different drive letter for each volume, R: and S:. As a consequence I also created separate backup and validate tasks for each volume, as each would point to a different drive letter – this also improved clarity as  a side effect – it separated the activiy/logs for each volume which gave a clear view of what had been done. Having done this, I did a full backup with each volume in turn of the same PC, and did an additional validation as well. All of these worked correctly. Crucially, in addition I re-did a validation of the first again at the end, having backed up and validated the second. This still worked correctly – Acronis was now able to track the backups correctly.

The other advantage of separate drive letters is that Windows will try to reuse the same letter for a volume as it used previously, meaning that mostly you will only need to set them once with Disk Manager (this can get messed up if you have additional removable drives in at the time you mount one of the backup ones, as Windows may have already re-used the ‘reserved’ drive letter, but mostly it works fine).

Although I did not test it, I suspect that another solution would be to uniquely label each backup file on each volume, perhaps by incorporating the volume name (e.g. “Backup1”, “Backup2”) as part of the file name. I suspect that this also would remove the ambiguity which was tripping up Acronis. In my case, I was happy to use the same folder and file naming convention on each backup volume, and just keep the drive letters different. You should use drive letters consistently in acronis – if you do not, it will be unable to find the backups it has in its database and will end up prompting for the location of backups when asked to run tasks.

No Comments »

January 24th, 2010
7:12 pm
Cannot remove old public folders after correctly moving them

Posted under Windows
Tags , ,

e.g. Moved the Public Music and Videos folders correctly using the move button. To do this I had to temporarily disable User Account Control via control panel, as per Microsoft Instructions.
The old folders under c:\Users\Public remained there and were inaccessible even as administrator – could not list the owner, could not delete etc.

This  forum post describes the problem, but their solution did not work for me.

In the end, after a logout/reboot they seemed to be ‘magically’ accessible again – I managed to rename one of the old ones, then found I could delete them all, even after having restored UAC back to default.

This is a bit of a weird area – needed some tinkering to sort it, info on the net not fully clear. Only some of the public folders were affected, documents were not. The user folders were not affected. All very strange!

No Comments »

January 19th, 2010
1:20 pm
Windows XP Home Workgroup Remote Administration/Shutdown

Posted under Windows
Tags

Unfortunately XP home does not have a remote registry service, so remote admin is limited.
You cannot remotely view the event log for example. You can however remotely shut down an XP home computer.

XP home remote admin is governed by the ForceGuest registry setting, whereby remote connections are forced to be guest access even if the connection is with other credentials such as an administrator. for XP pro this is on by default, but for XP home it cannot be turned off – it appears to be a side effect of xp home simple file sharing, which also cannot be turned off. You can however get around this for remote shutdown, but only by making the Guest account an administrator, which carries significant risk (it will allow any PC on the workgroup to shutdown the target pc) but within a small family home workgroup may be deemed acceptable. Do this as follows :-

  1. To make Guest an administrator, enter Start/Run/Control userpasswords2. This opens the advanced user management control panel applet, from which you can open the properties for Guest and add it to the administrators group (you must also enable the account – it is disabled by default).
  2. Unfortunately, a side effect of this is that Guest then appears on the login screen, which in this case we definitely do not want. You can remove Guest from the login screen by adding the following registry value as a DWord with a value of 0 (zero) :-
    HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\Winlogon\SpecialAccounts\UserList\Guest
    Note that this forum post describes the process.
  3. Having performed these steps, you can then use the shutdown command from another machine in the workgroup. Shutdown /i  from a command prompt will open gui mode which is more friendly, but this does not appear to allow the force (/f) option which forces application shutdown if apps are running. The following example will perform an immediate forced shutdown of the pc named TargetPC with a reason of “planned hardware maintenance” :-
    shutdown /s /f /m \\TargetPC /t 0 /d p:1:1
  4. You can add the command to a batch file, but do not do as I did and name the file shutdown.bat, otherwise it will recursively call itself rather than perform the shutdown command!

Comments Off on Windows XP Home Workgroup Remote Administration/Shutdown

January 11th, 2010
9:52 am
How to Pin shortcuts to taskbar/enable quick launch bar in Windows 7

Posted under Windows
Tags , , ,

Some desktop shortcuts cannot be pinned to the new taskbar/superbar in Windows 7, for example a desktop shortcut to a url.
You can enable the old quick launch toolbar to do this as follows :-

On the taskbar, right click and pick Toolbars/new toolbar…

  1. In the Folder box at the bottom, paste in the following :-
    	%userprofile%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch
  2. Click Select Folder to save the change
  3. Note that the quick launch bar may end up to the right of the superbar. Dragging it to the left seems to be a fine art! I googled for a while and could not find out how to move it. In the end I discovered that the speed of dragging is very important here. It should be dragged by left clicking the dotted lines, or by left clicking just to the right of them so that the cross arrow appears. Click and hold and drag with a swift motion over the other bar, and drop, and this should work. If you are too slow with the drag it will not work and will just hit the adjacent bar. In my case, dragging the dotted lines seemed to work in either direction (i.e. can either drag superbar over quick launch or vice versa), but dragging with the crossed arrow only seemed to work rightwards. I did read a blog post that advocated unpinning everything from the superbar first, but this was not required, in the end it all comes down to the dragging technique. Once you have tried a few times and got it working it becomes second nature, but it is certainly very counter intuitive!
  4. You may also find that the quick launch bar disappears on reboot. You can re-add it back as in 1. above, and you should find that its contents are still there as previously. This post details how to modify the registry to remedy the disappearance problem, but this post on sevenforums states that you only need to make sure the that the current theme is saved (right click desktop, select personalize, right click and save the current theme). I’ve tried saving the theme and will see if it still disappears, and then try the registry mod.

This will also give access to the hidden 3-D Window Switcher that was in Windows Vista.

Full details of this may be found on here.

Comments Off on How to Pin shortcuts to taskbar/enable quick launch bar in Windows 7

January 8th, 2010
9:30 pm
JSF 1.2/Facelets event & state handling

Posted under JSF
Tags , , ,

The issue here came about when trying to propagate click events from a child table pair tag to its parent facelet page. The table pair contained buttons to move rows between the tables, and to reorder rows on the target table – a typical design pattern used in this case to assign roles and rights to a user. The table pair tag is responsible for all the buttons for this function – move row selection left/right, move all left/right, reorder target row selection up, reorder target row selection down.

My general design in this situation is for the backing bean structure to mirror the objects on the page. There is therefore an overall page bean which has a child table pair bean for the table pair facelet tag, which in turn has 2 child table beans for its subsidiary facelet table tags. Whilst the parent facelet page does not need to know about the above button logic (it just pulls the result rows out of the child beans e.g. when a save is done), it does need to know when the child table pair has caused the page to be dirty, i.e. to have unsaved changes, which comes about when one of the above buttons is clicked.

My ideal solution to this would be to add an additional action listener on the table pair buttons – the main one is handled by the table pair bean, and an additional one on each button calls a single method on the overall page bean to notify that the page has changed. The parent does not need to know which button was clicked or why, but merely to know that a change has occurred. However this idea is scuppered in JSF 1.2 by the fact that a secondary f:actionListener tag on a button does not accept a method binding like the primary actionListener, but takes a fully qualified class name which must implement the ActionListener interface. This is a right pain as it is a class and not even an instance – you cannot tie the event to a particular bean.

My next attempt was to simply inject a parent reference in the TablePair bean in faces-config.xml, however this fails because JSF does not allow cyclic references in faces-config.

My final solution was therefore to pass a value binding for my own ChangeListener interface on the parent bean to the TablePair tag as a parameter, and declare this on each button using f:attribute. The TablePair bean then fetches the bean reference from the attribute when its actionListener is fired and calls the notify method on the reference’s Change Listener implementation. (I could also have used setPropertyActionListener to simplify this but an ICEfaces bug prevented this working – setPropertyActionListener was being called after the actionListener so the latter only ever saw a null value). The following code fragment illustrates what was used to pull the reference out of the attribute (note that this is incomplete and imports etc. are missing) :-

// Calling code
  private static final String CHANGE_LISTENER_ATTRIBUTE = "changeListener";
  ...
  ChangeListener changeListener =
    JSFUtil.fetchComponentAttribute(actionEvent, CHANGE_LISTENER_ATTRIBUTE);
  if (changeListener != null)
    changeListener.notify(this);
...
// Utility Class
public class JSFUtil {
  public static<F> F fetchComponentAttribute(ActionEvent actionEvent, String attribute) {
    UIComponent component = actionEvent.getComponent();
    Map<String, Object> attributes = component.getAttributes();
    return (F)(attributes.get(attribute));
  }
}

When propagating changes like this, it is important that the design does not cause recursive notifications, for example where a change gets passed up from one child to a parent, back down from the parent to all its children, who send it back up and so on. To this end, I therefore distinguish between the following concepts to avoid this happening:-

  1. Action Notification Events are only propagated upwards from children to parents, and are only raised in respect of external actions,  for example when a button click in a child tag causes a change which the parent needs to know about. ActionNotifications are never raised as a result of a property change on a component which could have been initiated by a parent. For clarity, if an external action causes a property change and needs to propagate this upwards, it is the fact that an external action occurred which is being propagated, and not the fact that a property has changed, i.e. in JSF terms it is the result of an action event and not a value change event. This means that whilst such an external action will pass an event up as well as changing a property, if a parent directly changes the same property, no event will be propagated up.  A child cannot directly change properties in its parent so it needs this mechanism to tell the parent “something external such as a button or link click has happened in me which you need to be aware of”. Typically this will be because a click action on the child has made the whole page dirty and the parent therefore needs to change component state throughout the page to reflect this (for example to enable the save and discard buttons and disable navigation from the page). As notifications only travel upwards, recursive notifications cannot therefore occur.
  2. Property Changes are only performed by a component on itself or on its child components. On itself, it can change any of its internal properties. On a child component, it can change any of the publically changeable properties of the child. As stated above, such changes will never give rise to action notification event propagation. However, property changes can certainly propagate downwards as required.

The state determination of a JSF page or a custom component can become complex when a number of components need to be, for example, selectively enabled and disabled depending on various property combinations. If the logic to determine the state is scattered throughout the component’s managed bean, or even worse, is coded in value expressions on a JSF page, it is hard to make sense of the state determination logic, easy to miss logic that is required, and easy to break the state determination when the code is changed. Therefore, I always use a private changeState method on a bean to perform all the state determination and changes. Typically this will involve a ladder of if..else based logic which checks properties on the bean, and then for example sets or clears various enable/disable properties for the JSF components. In State Machine terms, the various properties of the bean are inputs to the changeState method, and the method uses these inputs to determine a new state for the bean, setting various properties for the new state. I am not fussy about the precise implementation of this – in complex cases, it may be worth using a state machine/state table driven approach to determine state, and maintain a ‘current state’ for the bean which is independant of the beans properties, but for most normal cases this is overkill. What is important is to use an implementation which is clear, correct and easy to maintain, and where the mechanism is easy to understand and flows naturally from the state change requirements. This method should be called whenever a change happens to any of the inputs which the method uses to determine state, and therefore will normally be called many times throughout the bean. If AOP is in use, this might be a good candidate for using a pointcut and advice to dynamically insert the calls, for example on various property changes. In typical cases, I end up with a dirty flag on the bean which indicates that something has changed, and the changeState method checks the flag and sets various enable/disable properties as required. It is therefore often worth having an overloaded version of changeState which allows new values of such inputs to be passed in and set, and then the state change logic performed, in a single call.

As mentioned earlier, I specifically do not perform any such logic on a JSF page. The presence of logic in value expressions on a JSF page is a warning bell as it may indicate that either MVC controller logic or worse,  business logic has been placed on the page. As an example, my TablePair bean allows the ‘move selected rows to destination’ button to be clicked if any rows have been selected in the source table – otherwise the button is disabled. It would be possible to code an ‘anyRowsSelected’ property on the bean, and call this property directly from the disable attribute on the JSF page. Whilst this is a simple example, I would contend that this effectively places a controller logic decision in the MVC view. The correct way would be for the disable property on the button to directly refer to an enable/disable flag on the bean, and for the changeState method in the bean to call anyRowsSelected as a method, and set the enable/disable flag as required. This removes all evidence of the logic from the view, and also means that if the logic changes, for example if other conditions can occur on the bean which affect the button state, the change is made in the correct place – only in the changeState method on the bean. The JSF page would not need to be touched and has no knowledge of this.

No Comments »

January 8th, 2010
9:28 pm
ICEfaces components missing from Eclipse Palette

Posted under Eclipse
Tags , , , , ,

I had an Eclipse Galileo workspace containing several projects, and for some reason some of the projects did not show a full palette of components when opening a jspx file using the Web Page Editor. The main culprit was the ICEfaces components set which was missing. The workspace as a whole was clearly OK, but some projects had become broken. I now believe that some changes I made to user library locations may have caused the problem, but not sure on this.

Firstly, I visited the JSF project facets screen by right clicking the project in the explorer and selecting Properties to open the project properties page, then opening the  Project Facets entry in the left hand pane. I removed (unticked) support for ICEfaces and saved the changes. Then I added it back and saved again. This did not fix the problem.

I looked at the JSF Tag Registry view which lists all the Tag libraries registered for a project. This can be displayed by clicking menu option Window/Show View/Other and then entering Tag in the search box at the top. Select Tag Registry under JSF and the view will open. You must select the desired project in the view as it does not default to the current project. You can then expand the entries to see the Tag libraries registered. If you select one of the top level nodes on the registry tree (in my case these were labelled Facelet Tag Registry and JSP Tag registry) you can click the refresh button adjacent to the project selection button. This refreshes the entries, and you can elect whether or not to flush the cache in the resulting dialog. Unfortunately it was of no help to me in fixing the above problem, and refreshing/clearing the cache did not clear the issue. However, this view could be useful to browse Tag Library registrations.

I was aware that the palette entries are driven by the available Tag libraries on the project Build path, so still felt that it was library related. I then revisited the project properties page, and this time expanded the Project Facets entry in the left pane rather than clicking on it. I then selected Java Server Faces. This listed the user libraries for the project in the right hand pane, including all of the ICEfaces and JSF ones. I deselected all but one of them (you cannot deselect all of them), leaving the JSF 1.2 (Sun RI) library selected. I then applied/saved the changes and closed the screen. I then re-opened it, selected all the originally selected libraries and applied/saved again. This time, when I opened a jspx file in the project with the Web Page Editor, the ICEfaces components were present on the palette.

One last glitch was that after doing this, the palette entries for ICEfaces only had icons present, no descriptions. I then  closed the web page editor window, and closed Eclipse down normally, and re-opened the same workspace in Eclipse again. I then re-opened the same jspx in the Web Page Editor, and this time the ICEfaces components were all present with both the Icons and the descriptions. Problem solved!

No Comments »

January 8th, 2010
4:22 pm
Unable to execute JSF Lifecycle – Duplicate ID tags in JSF

Posted under JSF
Tags ,

A common gotcha this one which has had me scratching my head a few times. ID tags on elements must be unique, and if you duplicate one as I did on an ICEfaces table, you get a nice big stack trace saying “Unable to execute JSF lifecycle” amongst many other things. It is not obvious that this is the cause, and the IDE does not appear to pick it up even if you do a validate, so it is worth remembering and checking for, as it gives the impression that something much nastier has happened! (Some duplicates do not appear cause the problem but should be weeded out anyway).

No Comments »

January 8th, 2010
4:21 pm
Comparing files in Eclipse

Posted under Eclipse
Tags ,

Eclipse can compare  a pair of open files. It is not obvious how to do this however.

All you need to do is select the first file in the project/package explorer, then ctrl/select the second file so that both are selected. If you then right click, you can select Compare To/Each Other and a new differences view is created.

You can also select a single file, and compare to another version in CVS by selecting Compare To/Another Branch or Version

This post also discusses the technique.

No Comments »