Archive for June, 2011

June 14th, 2011
6:28 pm
Passing an enum as an argument to a JSF 2 EL method expression

Posted under JSF
Tags ,

It is useful to be able to pass an enum rather than a string value as this introduces additional error checking by JSF.

JSF has a built in enum converter, so that all you need to do is pass a literal string which must then be one of the enum fields. JSF detects that the method argument is an enum and does the appropriate conversion and error checking. This will not occur until run time, but you will at the very least get a JSF error on your browser page and in the log, for example:-

javax.faces.el.EvaluationException: java.lang.IllegalArgumentException:
  
No enum const class uk.co.salientsoft.view.Workspace$PageType.LOGOUT

See here for the StackOverflow post detailing this issue  – BalusC to the rescue again!

No Comments »

June 11th, 2011
9:22 am
Cannot disable Java Auto Updates under Windows 7 64bit

Posted under Java
Tags , ,

As I am running a Java development machine I want precise manual control of the versions of Java and all the related tools.

The Java auto updater runs regularly and nags about updating, but I want to turn it off. There is a control panel applet  – “Java (32-bit)” – with an option under the updates tab to do this, however it does not work – if you uncheck the “check for updates automatically” tick box, it appears to save OK but when you close and re-open the applet and look again the value has not changed.

This is due to an apparently long standing Java bug – it does not run with admin privileges and so cannot change the value. It would be nice if it gave an error telling you that it did not work due to a permissions problem, but unfortunately it just fails completely silently.

This post here outlines various solutions to the problem. The accepted answer, which worked for me, is to find javacpl.exe, right click it, and run with admin privileges. The location of it in my case was not where the post suggested, even though I had done a default install, so you will probably need to search for it. In my case I had a couple of versions of it, one was for an old version of Java. The path for mine which I used successfully was C:\Program Files (x86)\Java\jre6\bin

This fixed the problem, and upon reopening the control panel applet (with or without admin privileges) the box was unticked.

No Comments »

June 7th, 2011
12:58 pm
Theme Manager and Theme switcher

Posted under JSF
Tags ,

Primefaces uses the theming capability of jQuery, including the ability to create your own themes using ThemeRoller. This powerful facility separates theme specific CSS from structural CSS which defines the layout of UI components such as tables. At the time of writing, Primefaces has 32 different themes. It does also have a themeSwitcher component, but this has some issues which make it less than ideal for many environments. In addition, the structure of the themes has changed as of version 2.2 – they are now deployed in jars rather than as bare resource files. The following lists the salient issues and desirable features regarding the theme switcher:-

  • When switching themes, rather than using a theme deployed with the application, the Primefaces themeSwitcher downloads the new theme from the internet and installs it directly, which is undesirable in many environments.
  • Ideally, as well as using the themes deployed with the application, the themeSwitcher should be configurable dynamically to allow new themes to be easily added.
  • The theme switcher should also, as far as possible, derive its theme list presented to the user dynamically from the themes that have actually been deployed. Failing this, it should be possible to configure this list as a deployment configuration option, i.e. in web.xml
  • It would be desirable to isolate the theme Switcher from any further changes to the Primefaces theming structure. For example, if a plug-in architecture is used, a new theming interface can be incorporated simply by adding a new plug-in.

 

The Theme Manager attempts to address all of the above issues to provide a flexible and upgradeable solution to Primefaces theming. The Theme Manager including PDF documentation will be found  in the repository here.

No Comments »

June 3rd, 2011
2:14 pm
Version Manager Facility

Posted under Java
Tags , , ,

This utility was developed to allow JSF and Java software to dynamically manage dependency issues caused by interface changes across differing versions of dependant libraries, by querying the utility at runtime with rule based match checks about the versions actually deployed. Typically interfaces to software are consistent for a range of versions, and then change whereupon they remain the same for a further range of versions. The Version
Manager thus allows rule based checks to match a contiguous range of versions, as well as matching a single specific version.

The utility was developed in response to issues caused by changes between Primefaces versions. A particular case in point was that some custom Javascript and CSS was implemented for V2.2.M1 to fix common issues concerning header alignment and column width for scrolling tables. These changes were encapsulated in .css and js files in a TableCC composite component which decorates the standard Primefaces p:dataTable.
These fixes of necessity used css and jQuery selectors referring to underlying Primefaces structural css classes – this exposes such code to risk of change, but in this case the risk was justified as the code was there to fix issues.

The css in Primefaces changed late on in the V2.2 cycle – the class names changed and the HTML was simplified to remove a div container layer. These changes broke the above code. It was felt that this would in general not be an isolated issue. Primefaces is a fast moving development project, which has its upsides in that new features and new versions come onstream regularly. The downside in a fast moving environment can be issues such as the
above one. In fairness to Primefaces, it is very difficult to develop a generic Table component using current HTML standards which allows fixed column headers with a scrolling data table. Some things such as dynamic resizing of columns just cannot play ball in the current scenario, and scroll bars coming and going with different data volumes add further challenges of their own! In practice it is not possible to cover every possible use case. My approach is to narrow down a particular set of use cases I need to work with, and then come up with the necessary fixes/decorator components as above to handle those particular use cases.

In order to mitigate the effect of this kind of issue when versions change, and to avoid proliferation of a number of different code versions each matched to a set of dependant library (e.g. Primefaces) versions, a Version  Manager facility was developed.

The Version Manager including PDF documentation and an example may be found in the repository here.

No Comments »

June 2nd, 2011
3:30 pm
JSF 2–Objects as selectOneMenu items–Custom Converter/CDI issues

Posted under JSF
Tags , , ,

With JSF 2.0, it is now possible to use any class as an item in a selectOneMenu combo and related components. This is described in  “Core JavaserverFaces” p157ff. However, the book does not mention that you also need a custom JSF converter to convert between object and string.

If you then implement a custom converter as in the book on p279, e.g. with:-

<h:selectOneMenu styleClass="ss-tsw-select" id="cmbTheme"
      value="#{themeSwitcherBean.theme}" disabled="#{themeSwitcherBean.selectDisabled}"
      converter="uk.co.salientsoft.thememanager.ThemeConverter"
      immediate="true" onchange="submit()">

CDI fails to inject any references used in the converter class, as JSF 2 does not allow CDI in converters, as detailed in this Stack Overflow Post.

It does work however if you use an EL reference in the converter attribute as mentioned in this post here.

Note that the post indicates that it may require it to be an application scoped bean. In my case, it worked fine as both a request scoped and application scoped bean with no trouble. I also removed the @FacesConverter("uk.co.salientsoft.thememanager.Theme") annotation as this was no longer required due to the EL reference. The post indicates that this is perceived to be more untidy due to the use of EL and a managed bean, but I cannot see an issue with this. I cannot see why converters cannot be application scoped CDI beans, it all fits in fine. Here is the code fragment above, modified to use an EL reference instead:-

<h:selectOneMenu styleClass="ss-tsw-select" id="cmbTheme"
      value="#{themeSwitcherBean.theme}" disabled="#{themeSwitcherBean.selectDisabled}"
      converter="#{themeConverter}"
      immediate="true" onchange="submit()">

No Comments »

June 2nd, 2011
2:27 pm
Bluetooth connection issues between HTC TyTn II and windows 7 64 bit

Posted under Windows 7
Tags , , , ,

I had issues getting Activesync to connect over bluetooth during the last few days. at each attempt activeSync on the HTCgave the error “attention required, unable to connect, bluetooth port may be in use” etc.

I tried restarting both and reconnecting but this did not work.

On one occasion, Window 7/panther was unable to complete listing the devices, but this appears to have been a one of as it is fine today.

In the end, I tried deleting the pairing and repairing the devices. This solved the problem. I was concerned that it would also delete activesync related info and require reconfiguration of that, but it did not. Once the pairing was set up, I was able to connect via Bluetooth from the HTC and resync correctly with no further errors.

I have seen this before in other situations where a bluetooth pairing appears to get corrupted in someway, and generally as in this case deleting the pairing and repairing seems to resolve it.

No Comments »