myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yaniv David <yan_...@hotmail.com>
Subject Re: How to create a custom component with a non-string data model
Date Thu, 11 Jan 2007 11:47:53 GMT

Hello,

I have the same problem, did you find a solution?
My parameter is an ArrayList.

Yaniv.


Stephane Grenier-2 wrote:
> 
> 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
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-create-a-custom-component-with-a-non-string-data-model-tf2922326.html#a8275636
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Mime
View raw message