« Return to Thread: Help with custom tag attribute
Actually the problem is that f:attribute is not evaluating the the EL. If I pass the value literally it accepts, but if I pass #{maxlength} it is trying to set the string "#{maxlength}" as maxleght, so thats why the I get the ClassCastException.
<h:outputLabel value="#{label}" />
<h:inputText
label="#{label}"
value="#{value}"
>
<c:if test="#{! empty id}">
<f:attribute
name="id"
value="#{id}"
/>
</c:if>
<ui:insert />
</h:inputText>
The id attribute is a better exemple of what I'm trying to do. When it's not set in the custom tag I'd like that it is not set in the h:inputText tag so that JSF generates the id. Otherwise always when I use the custom tag I'll have to set the id or write some crazy workaround to generate it so that I don't get a duplicated id exception.
Any ideias? Does f:attribute only accepts literals?
Thanks,
Felipe2009/5/6 joseph j marini <josephjmarini@...>
Try mapping value to a backing bean #{foo.maxLength}
in your backing if max length is optional return null, else return
Integer object with value set. It will get converted automatically.
/Joe
--------------------------------------------------
From: "Zarar Siddiqi" <zarars@...>
Sent: Wednesday, May 06, 2009 11:26 AM
To: <users@...>
Subject: Re: Help with custom tag attribute
There's a difference between saying something is optional by passing
in a null, entirely another to pass in a string and expect it to be
ignored just because its not an integer.
What is the value of maxlength when you pass it in? Is it null or a string?
On Fri, Apr 24, 2009 at 1:16 PM, Felipe Jaekel <fkjaekel@...> wrote:
I have a custom tag that is composed by a <h:outputLabel /> + <h:inputText
/>. I need the maxlength attribute to be optional. The problem is that when
I use <f:attribute /> I get a class cast exception.
Tag:
<ui:composition
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:outputLabel value="#{label}" />
<h:inputText
label="#{label}"
value="#{value}"
>
<c:if test="#{! empty maxlength}">
<f:attribute
name="maxlength"
value="#{maxlength}"
/>
</c:if>
<ui:insert />
</h:inputText>
</ui:composition>
Exception:
java.lang.ClassCastException: java.lang.String cannot be cast to
java.lang.Integer
Any ideas?
Thanks,
Felipe
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...
« Return to Thread: Help with custom tag attribute
| Free embeddable forum powered by Nabble | Forum Help |