Skip to main content

Seam s:convertEntity + glassfish + toplink

.... doesn't go very well together, since Seam wants to access your entityManager, and would want it to be a Hibernate instance...

This is a simple workaround, by replacing s:convertEntity with a custom tag that gives the same result. By remembering the entities displayed to the s:selectItems, using the value of entity.toString() (which is className + hashCode() (which should be unique).).

You might want to tune it maybe not to use hashcode (in case of non uniqueness), and maybe access your entitymanager (toplink) - instead of storing entities in memory.. But in any case this is a good starting point:

package com.petersalomonsen.jsf.persistence.EntityConverter
import java.util.HashMap;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

public class EntityConverter implements Converter {
static HashMap<String,Object> entitiesToRemember = new HashMap<String,Object>();

public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
return entitiesToRemember.get(arg2);
}

public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
entitiesToRemember.put(arg2.toString(), arg2);
return arg2.toString();
}
}


This goes into your faces-config.xml:

<converter>
<converter-id>EntityConverter</converter-id>
<converter-class>com.petersalomonsen.jsf.persistence.EntityConverter</converter-class>
</converter>


And here in your xhtml, s:convertEntity is replaced by the custom converter (<f:converter converterId="EntityConverter" />):

<h:selectOneMenu value="#{myItem}">
<s:selectItems value="#{myItemTypes}" var="mit" label="#{mit.name}" />
<f:converter converterId="EntityConverter" />
<!-- <s:convertEntity /> -->
</h:selectOneMenu>

Comments

Popular posts from this blog

My VNC based development environment with Visual Studio Code running on Ubuntu

I've used this setup for my development environment for several years - giving me a developer desktop I can access anywhere. Even from my mobile phone. I've been fixing bugs, writing code and deployed emergency fixes from the bus, train and mountain tops. The setup is based on a lightweight desktop environment. There are lot of alternatives, but I've chosen fluxbox. From a plain AWS Amazon Ubuntu 16.04 ec2 instance I've started like this: sudo apt-get update sudo apt-get install fluxbox Download and extract tigervnc from https://github.com/TigerVNC/tigervnc/releases (I downloaded the binary file from https://bintray.com/tigervnc/stable/tigervnc/1.7.0 named tigervnc-1.7.0.x86_64.tar.gz ) then extract: tar -xvzf tigervnc-1.7.0.x86_64.tar.gz You need to install: sudo apt-get install x11-xkb-utils You need to edit .vnc/xstartup: nano .vnc/xstartup last line replace "twm &" with: fluxbox & Then you can start the...

Angular components not reloading on route change

Spent a long time wondering why route changes caused strange effects on my component, and found out that it was because my component wasn't reloading at all. I had this assumption that when a route parameter changed (e.g. /projects/1 changed to /projects/2 ) the component for the route would be reloaded. But this is not the default behaviour of the Angular router. The default behaviour of the Angular router is to reuse the route if the configuration is the same (and not reload the component). But we can override this by providing a RouteReuseStrategy to our @NgModule: providers: [ { provide: RouteReuseStrategy, useClass: AARouteReuseStrategy } ] The full custom implementation of the RouteReuseStrategy will then be like this (and it's the shouldReuseRoute method that changes the behaviour so that the component is reloaded on route parameter change): export class AARouteReuseStrategy extends RouteReuseStrategy { shouldDetach(route: ActivatedRou...

Webassembly and audioworklet

Have been playing a lot recently with webassembly and the upcoming audioworklet web standard. This is exciting and powerful technology, opening up for serious use of the web in production of audio and music. Follow the links from my homepage petersalomonsen.com for live demo and more resources.