Hjem   |   Kontakt   |   Sitemap
Hvem er vi Hvad kan vi Vores kunder Ledige stillinger Kontakt os Blog

Posts Tagged ‘Java’

Dependent dropdowns in Seam and Richfaces

Published Friday, April 17th, 2009 by AN

It is not uncommon to want to make a combobox with choices that depend on another combobox. But it often seems very complicated to actually do this. So here is a piece of example code that I use with Seam and Richfaces. Imagine we have different vendors Vendors each with different Models of something.

The somewhat large blurb of Richfaces markup is to make two ordinary input textfields feel like two ajaxy comboboxes. It sucks a bit, but on the other hand the Java code is nice and clean.

How do you make dependent gui elements?


xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j">
<div class="dialog">
Vendor</div>
<div class="dialog">
Model

<br class="clear" /></div>
package test;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Remove;
import javax.ejb.Stateful;

import org.jboss.labs.seam.guice.Guice;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.log.Log;

import com.google.inject.Inject;

import dk.telenor.tacs.api.DBApi;
import dk.telenor.tacs.db.Model;
import dk.telenor.tacs.db.Vendor;

@Stateful
@Scope(ScopeType.SESSION)
@Name("vendormodelselector")
@Guice
public class VendorModelSelectorBeanImpl implements VendorModelSelectorBean {

@Inject	private DBApi dbApi;

@Out(required = false, value="model")
private Model model = new Model();

@Out(required = false, value="vendor")
private Vendor vendor = new Vendor();

public List autocompleteVendor(){
return dbApi.getMatches(new Vendor());
}

public List autocompleteModel(){
if (vendor == null || vendor.getName() == null) {
return new ArrayList();
}
return dbApi.getMatches( new Model(vendor, null) );
}

public void setVendor(final Vendor vendor){
this.vendor = vendor;
}

public void setModel(final Model Model){
this.model = model;
}

public Model getModel(){
return model;
}

public boolean isReady(){
return model.getId() != null;
}

@Remove
public void destroy(){}
}

Serialize java objects

Published Wednesday, March 18th, 2009 by AN

For my current project I want to serialize some plain old java objects and store them in a database. That’s easy. However, for debugability I would like the serialized data to be human readable, and I figure that there should be plenty of libs that supply drop in replacement functionality for ObjectInputStream/ObjectOutputStream.

Well, it was a bit more difficult than I thought. From my first go at the problem I concluded to myself.

I can’t seem to find an XML serialization framework that works the same way as the plain old java serialization.

1) java.beans.Encoder : requires no-arg constructor, but doesn’t seem to handle collections properly (fails, returns null)

2) XStream : has too many dependencies.

3) Simple : requires annotations, and requires knowing the Class that we want to deserialize to (ugly but workable). Best candidate.

4) Betwixt : requires knowing the Class that we want to deserialize to, fails to handle collections without silly naming conventions or extra code.

5) Castor : requires knowing the Class that we want to deserialize to, not tried yet.

Fortunately I was too fast in my judgement of XStream (and maybe the other libs too?). Anyway, all of the dependencies for XStream are optional. And it has a plesantly simple API. Yay, XStream…


Creating, consuming and testing SOAP webservices on Grails

Friday, February 12th, 2010
We are currently making a backend system, that has its services exposed as webservices. Since ...

My first patch to Grails accepted

Monday, November 23rd, 2009
I recently wrote a patch for Grails to support dateCreated and lastUpdated when using mockDomain ...
 
© 2008 Code3 ApS  |  Rådmandsgade 45A, 1.  |  2200 København N  |  +45 7020 3383  |  kontakt@code3.dk