myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephane Grenier" <stephane.gren...@innovapost.com>
Subject RE: How to create a custom component with a non-string data model
Date Thu, 04 Jan 2007 22:00:50 GMT
Btw, I just noticed in the code, the line: 

    component.setValueBinding("value", binding);

should read:

    component.setValueBinding("address", binding);

Regards,
Steph

-----Original Message-----
From: Stephane Grenier 
Sent: Thursday, January 04, 2007 4:59 PM
To: users@myfaces.apache.org
Subject: How to create a custom component with a non-string data model


Hi all,

I'm trying to create a custom component and I've got it working when the 
input value is a String type parameter from my backend bean. However my 
problem is that it's not working when the parameter is anything but a String 
object, say a data model object. I've tried a number of options, and I know 
it's possible, but I can't seem to get it. I've even seen a post that said 
to look at the schedule tag, but I can't seem to isolate the right snippet. 
Therefore you're assistance would be immensely appreciated. So far here's 
what I have:

public class AddressTag extends UIComponentTag
{
	private String address;

... set/getAddress(String address);

	@Override
	protected void setProperties(UIComponent component)
	{
		/* you have to call the super class */
		super.setProperties(component);
		((AddressComponent)component).setValue(address);

		FacesContext context = FacesContext.getCurrentInstance();
		Application application = context.getApplication();
    ValueBinding binding = application.createValueBinding(address);
    component.setValueBinding("value", binding);
	}

	... // other methods.
}

The address component is really simple:

public class AddressComponent extends UIInput
{
	private String address;

	@Override
	public void encodeBegin(FacesContext context) throws IOException
	{
		ResponseWriter writer = context.getResponseWriter();
        writer.startElement("label", this);
        writer.write("test custom component: " + address);
        writer.endElement("label");
        writer.flush();
	}

	... // other methods.
}

And in the JSP I have:

<cpc:address value="#{backendBean.address}"/>

Now when I try to change the backendBean.address property from String to an 
Address object (data model object), there are two issues.

1. In the AddressTag class the following line:

ValueBinding binding = application.createValueBinding(address);

Only seems to allow a String object, and not a generic Object.

2. Assuming I remove those lines of code, I get 
jsp.error.beans.property.conversion error.

Now I've also tried to add the <deferred-value> to the tld definition (I 
have to admit I don't yet understand what this property does), but that 
hasn't helped.

You're assistance is greatly appreciated as I've already wracked my brain 
enough on this issue! I'm just trying to send the data model object to the 
custom component because we're continuing to render it over and over and 
over on many screens in a special format.

Regards,
Steph

Mime
View raw message