A Hyperlink Field

I am using a derived FormFieldFactory to customize the appearance of fields on a form. I’ve overridden the createField and it is working well:


	@Override
	public Field createField(Item item, Object propertyId, Component uiContext) {
		Field field = DefaultFieldFactory.get().createField(item, propertyId, uiContext);
		if (propertyId.equals("exportProps"))
			field = null;
		else if (propertyId.equals("exportProps.jobName")) {
			field.setCaption("Job Name");
		} else if (propertyId.equals("exportProps.email")) {
			field.setCaption("Email");
		} else if (propertyId.equals("DL_URL")) {
			String tt = (String) item.getItemProperty("DL_URL").getValue();
			field.setDescription(tt);
			field.setCaption("Download URL");
		} else if (propertyId.equals("log_URL")) {
			String tt = (String) item.getItemProperty("log_URL").getValue();
			field.setDescription(tt);
			field.setCaption("Log URL");
		}

		if (field != null) {
			field.setReadOnly(true);
			field.setWidth("100%");
		}
		return field;
	}

For the URLs, I’d like to display them in Link … but Link does not derive from Field. I’m about to implement a CustomField to do this… but I’m having a hard time convincing myself that I’m not missing something fundamental: Is it really the case that everyone re-invents this everytime s/he needs a data-bound hyperlink? What should I do?

I’m Vaadin 6.

FWIW, Here’s how we ended up getting the hyperlinks. Rather trivial once you get used to it …


        } else if (propertyId.equals("DL_URL")) {
            field = new LinkField(item, propertyId);
            String tt = (String) item.getItemProperty("DL_URL").getValue();
            field.setDescription(tt);
            field.setCaption("Download URL");
        } else if (propertyId.equals("log_URL")) {
            field = new LinkField(item, propertyId);
            String tt = (String) item.getItemProperty("log_URL").getValue();
            field.setDescription(tt);
            field.setCaption("Log URL");

public class LinkField  extends CustomField {
    private Link link;

    public LinkField(Item item, Object propertyId) {

        String url = (String)item.getItemProperty(propertyId).getValue();
        link = new Link(url, new ExternalResource(url));
        link.setTargetName("_blank");
        setCompositionRoot(link);
    }
    @Override
    public Class<?> getType() {
        return LinkField.class;
    }
}

I wouldn’t say this is a very typical case; never seen it before, in fact. I just wanted to confirm that your solution is a very good one.