Archive for January, 2010

January 27th, 2010
4:22 pm
TP-Link TL-PS110U Ethernet/USB Print Server Setup Auto Discovery Issue

Posted under Windows
Tags ,

While running the setup wizard, it auto discovers the print servers on the LAN.
They all have to be on to be seen.

Sometimes, the wizard does not discover one even if the server is on.
This is a problem as you cannot do the discovery manually by entering settings.

In my case, either the Windows Firewall or Kaspersky Antivirus was blocking the auto discovery.
I temporarily disabled both, and discovery worked ok.
Afterwards, I re-enabled them, and was still able to print a test page successfully.
Therefore, this appears to be only a setup issue.

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 22nd, 2010
5:29 pm
Lenovo 3000 N100 – cannot enable wireless Card

Posted under Windows
Tags , ,

Symptoms as follows :-

1/ LED on front edge not lit, no wireless networks seen

2/ switch on front edge toggles bluetooth but wireless stays off

3/ Tried all drivers available on Lenovo site – no joy

4/ Broadcom wireless utility has an enable box – does not work

5/ Broadcom wireless utility has a diagnostic. This runs ok AND LIGHTS THE LIGHT ON THE FRONT –
   it says all hardware working no problems (which I believe)
   However, still can’t see wireless networks afterwards

6/ Googled all the forums – lots of people with same issue, no real solution.
   Possibly a patch/update has shafted the driver, but don’t know which patch.

7/ I found another driver on Softpedia here:-
   http://drivers.softpedia.com/get/NETWORK-CARD/OTHER-NETWORK-CARDS/BROADCOM-Wireless-802-11b-and-802-11g.shtml

   This is an HP Driver, but it WORKS! Installed it and wireless working fine now!

Comments Off on Lenovo 3000 N100 – cannot enable wireless Card

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
7:40 pm
Debug Logging of Bean properties

Posted under Java
Tags , , ,

A useful tool for doing this is the apache.commons.lang.builder.ToStringBuilder using one of the reflectionToString method flavours which are designed for this job. You can easily create dumps of entity beans and bean collections with this, and you can choose the output format.

Whilst it is tempting to override the toString methods on e.g. all your entity beans, as this will automatically dump all related beans & collections just by calling toString on a parent bean, this is not recommended! It can easily cause a storm of toString calls to propagate across all the related beans, resulting in an almost instant stack overflow! This post details how to do this using the apache BeanUtils describe method, and the comments take credit for pointing me in the direction of the apache.commons.lang.ToStringBuilder. However, both methods cause stack overflows when used with JSF and JPA, even when you are not doing any logging.

A better way is to provide a utility method into which you pass any bean or collection, and get the dump string returned which you can then log. The following is an example of a utility class to do this :-

package uk.co.salientsoft.util.beans;
import java.util.Collection;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public class BeanUtil {

  private static final ToStringStyle defaultStyle = ToStringStyle.SHORT_PREFIX_STYLE;

  public static <E> String dumpProperties(Collection<E> coll) {
    return dumpProperties("", coll, defaultStyle);
  }
  public static <E> String dumpProperties(String prompt, Collection<E> coll) {
    return dumpProperties(prompt, coll, defaultStyle);
  }
  public static <E> String dumpProperties(Collection<E> coll, ToStringStyle style) {
    return dumpProperties("", coll, style);
  }
  public static <E> String dumpProperties(String prompt, Collection<E> coll,
                                          ToStringStyle style) {
    String properties = prompt;
    for (E e : coll) {
     /* Use the apache.commons.lang.builder toStringBuilder
      * to list all this bean's properties
      */
     properties += "\n" + ToStringBuilder.reflectionToString(e, style);
    }
    return properties;
  } 

  public static <E> String dumpProperties(E e) {
    return dumpProperties("", e, defaultStyle);
  }
   public static <E> String dumpProperties(String prompt, E e) {
     return dumpProperties(prompt, e, defaultStyle);
   }
   public static <E> String dumpProperties(E e, ToStringStyle style) {
     return dumpProperties("", e, style);
   }
   public static <E> String dumpProperties(String prompt, E e, ToStringStyle style) {
     return prompt + ToStringBuilder.reflectionToString(e, style);
   }
}

No Comments »

January 8th, 2010
5:35 pm
ICEfaces ice:form tag adds extra auto margin in IE7

Posted under JSF
Tags , , , ,

The ice:form tag renders a stateSavingMarker div which declares a couple of hidden fields for use by ICEfaces.

In IE7, (or IE8 in IE& compatibility mode), this div has its margin to auto which can cause an extra 10px or so margin to be added in between any elements outside the form and those inside.

This can be eliminated by adding a style to the form, either by adding a StyleClass attribute to refer to a CSS class, or by using the Style attribute to code an inline style. As this is a ‘one off’ just to clear a margin, the following example uses an inline style :-

<ice:form style=”margin:0″>

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 »