You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by arne anka <do...@ginguppin.de> on 2008/04/23 15:20:27 UTC
facelets: custom component and custom converter
hi,
i got my custom component (faclets based, not tomahawk or trinidad,
extending UIOutput) working so far -- but my converter is not executed.
if i attribute the converter to, say, h:outputText it works, so it seems
to be ok.
my idea is, because i use my own rendere (getRendererType() returns null)
maybe i need to call it myself?
if so, how do i get hold of the converter?
both with
<my:component value="foo" converter="contentConverter" />
and with
<my:component value="foo">
<f:converter converterId="contentConverter"/>
</my:component>
getConverter() always returns null
thanks in advance
Re: facelets: custom component and custom converter
Posted by Andrew Robinson <an...@gmail.com>.
I didn't say to put the ID in EL, I said to put a bean in the EL. Did
you try that?
If the ID is working for h tags in facelets, then find the TagHandler
it is using and the meta ruleset that it is setting up. Then just make
sure you do the same for your component.
Andrew
Sent from my iPod
On Apr 25, 2008, at 4:10 AM, "arne anka" <do...@ginguppin.de> wrote:
> well, but (xmlns:h="http://java.sun.com/jsf/html")
>
> <h:outputText value="foobar" converter="contentConverter"/>
>
> works. and
>
> <h:outputText value="foobar" converter="#{contentConverter}"/>
>
> does not.
>
>
>> <my:component value="foo" converter="contentConverter" />
>>
>> Is definitely nod valid syntax. The converter must evaluate to a
>> converter instance, not a converter ID:
>>
>> public void setConverter(Converter converter) {...}
>>
>> So you have to use EL:
>>
>> <my:component value="foo" converter="#
>> {bean_that_implements_converter}" />
>
>
> could you post a snippet or a link for the taglib.xml part? i am not
> sure if i did it alright.
>
> thanks
Re: facelets: custom component and custom converter
Posted by arne anka <do...@ginguppin.de>.
well, but (xmlns:h="http://java.sun.com/jsf/html")
<h:outputText value="foobar" converter="contentConverter"/>
works. and
<h:outputText value="foobar" converter="#{contentConverter}"/>
does not.
> <my:component value="foo" converter="contentConverter" />
>
> Is definitely nod valid syntax. The converter must evaluate to a
> converter instance, not a converter ID:
>
> public void setConverter(Converter converter) {...}
>
> So you have to use EL:
>
> <my:component value="foo" converter="#{bean_that_implements_converter}"
> />
could you post a snippet or a link for the taglib.xml part? i am not sure
if i did it alright.
thanks
Re: facelets: custom component and custom converter
Posted by Andrew Robinson <an...@gmail.com>.
I am looking at the ComponentHandler.java from Facelets 1.1.14 and I
see no meta rules for converter. This means that converter="#{}" would
be set without any type of special handling. So:
<my:component value="foo" converter="contentConverter" />
Is definitely nod valid syntax. The converter must evaluate to a
converter instance, not a converter ID:
public void setConverter(Converter converter) {...}
So you have to use EL:
<my:component value="foo" converter="#{bean_that_implements_converter}" />
I do not know why this doesn't work though:
<f:converter converterId="contentConverter"/>
That is handled by com.sun.facelets.tag.jsf.ConvertHandler
The only requirement is that the parent component of the tag must
implement ValueHolder, which UIOutput does.
It creates the converter using:
return ctx.getFacesContext().getApplication().createConverter(this.converterId);
If you are using facelets 1.1.14 and have verified your taglib.xml
files are correct, then I would advise you to debug into the facelets
code for the classes that I have mentioned and see what is going on
first hand.
You can also try calling this manually from a bean somewhere and
making sure it works:
FacesContext.getCurrentInstance().getApplication().createConverter("contentConverter");
-Andrew
On Thu, Apr 24, 2008 at 2:43 AM, arne anka <do...@ginguppin.de> wrote:
> thought, i mentioned it already -- there is no xhtml involved. i try to do
> it entirely in java:
>
> public class FedoraObjectContentComponentUI extends UIOutput
> {
> private byte[] myObject = null;
> private String myMime, myDS, myID;
>
> @Override
> public String getFamily()
> {
> return "fedoraobjectcontent";
> }
>
> @Override
> public String getRendererType()
> {
> return null;
> }
>
> @Override
> public void encodeBegin(FacesContext context) throws IOException
> {
> super.encodeBegin(context);
> final ResponseWriter writer = context.getResponseWriter();
> writer.write("<br/>Foo</br>");
> }
>
> @Override
> public Object saveState(FacesContext context)
> {
> Object values[] = new Object[5];
> values[0] = super.saveState(context);
> values[1] = myObject;
> values[2] = myMime;
> values[3] = myDS;
> values[4] = myID;
> return ((Object) (values));
> }
>
> @Override
> public void restoreState(FacesContext context, Object state)
> {
> Object values[] = (Object[]) state;
> super.restoreState(context, values[0]);
> myObject = (byte[]) values[1];
> myMime = (String) values[2];
> myDS = (String) values[3];
> myID = (String) values[4];
> }
> }
>
> and in faces-config.xml
>
> <component>
> <component-type>component</component-type>
>
> <component-class>my.package.Components.FedoraObjectContentComponentUI</component-class>
> </component>
>
> that's my component, basically.
>
>
>
> On Wed, 23 Apr 2008 19:52:21 +0200, Andrew Robinson
> <an...@gmail.com> wrote:
>
>
> > I should have asked this earlier, what is my:component? Do you use
> > ui:component in the root of the xhtml file? Is there getConverter /
> > setConverter methods on the component?
> >
> > If you could provide a small code snippet from the facelet and the
> > component that it uses that would help.
> >
> > -Andrew
> >
> > On Wed, Apr 23, 2008 at 11:31 AM, arne anka <do...@ginguppin.de> wrote:
> >
> > > snippet from faces-config.xml:
> > > <converter>
> > > <description>
> > > </description>
> > > <display-name>contentConverter</display-name>
> > > <converter-id>contentConverter</converter-id>
> > >
> > >
> <converter-class>my.package.FaceletsElements.FedoraObjectContentConverter</converter-class>
> > > </converter>
> > >
> > > as said before -- it works with standard components. so it seems to be
> > > something trivial i do not see.
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > On Wed, 23 Apr 2008 19:21:37 +0200, Andrew Robinson
> > > <an...@gmail.com> wrote:
> > >
> > >
> > > > Have you registered the converter in faces-config.xml properly? Please
> > > > post your configuration for your converter
> > > >
> > > > On Wed, Apr 23, 2008 at 7:20 AM, arne anka <do...@ginguppin.de> wrote:
> > > >
> > > > > hi,
> > > > > i got my custom component (faclets based, not tomahawk or trinidad,
> > > > > extending UIOutput) working so far -- but my converter is not
> executed.
> > > > > if i attribute the converter to, say, h:outputText it works, so it
> > > seems to
> > > > > be ok.
> > > > > my idea is, because i use my own rendere (getRendererType() returns
> > > null)
> > > > > maybe i need to call it myself?
> > > > > if so, how do i get hold of the converter?
> > > > >
> > > > > both with
> > > > >
> > > > > <my:component value="foo" converter="contentConverter" />
> > > > >
> > > > > and with
> > > > >
> > > > > <my:component value="foo">
> > > > > <f:converter converterId="contentConverter"/>
> > > > > </my:component>
> > > > >
> > > > > getConverter() always returns null
> > > > >
> > > > > thanks in advance
> > > > >
> > > > >
> > > >
> > >
> > >
> > >
> > >
> >
>
>
>
JSF validation question?
Posted by "Zheng, Xiahong" <Xi...@FMR.COM>.
Two scenarios:
Scenario 1. Form submission:
Our security requirement mandates that we implement some sort of default
validation on fields that do not have validator attached to them. That
is, if validators are missing on the input fields, we have to do some
minimal validation. Otherwise, JSF will do the validation. How would you
go about implementing this requirement. I am thinking several options
A) Use a customized Application implementation which will override
"createComponent" method which delegates to the default ApplicationImpl
to create the component and add my default validator if there is no
validators.
createComponent(String componentType) {
UIComponent component = delegate.createComponent(componentType);
if (component instanceof UIInput &&
component.getValidators.length == 0) {
component.addValidator(new MyDefaultValidator());
}
}
B) Create a custom form component to track the input fields with a
similar logic when they are being added the form. This
Scenario 2. Get request (no form submission):
JSF does not execute validation phase for GET request. In this case,
how do I validate request parameters passed as managed properties? I
don't want to validate them explicitly in my managed beans. I want the
validation to happen before they are bound.
Thanks in advance,
Xiaohong Zheng
Re: facelets: custom component and custom converter
Posted by arne anka <do...@ginguppin.de>.
> Example, instead of:
>
> writer.write("<br>Foo</br>");
>
> do the following
> writer.beginElement("br", null);
> writer.write("Foo");
> writer.endElement("br");
well, it was only a snippet modified in the mail editor --and as usually
one introduces errors at those occasions ;-)
i assure that i am using begin/endElement for tags, it should only show
that i do writing of html tags ...
Re: facelets: custom component and custom converter
Posted by Scott O'Bryan <da...@gmail.com>.
Arne,
Can you please use the ResponseWriter.beginElement and
ResponseWriter.endElement method for handling elements? It makes things
a lot more flexible be cause the renderkit knows what kind of content
you are passing into it. The more information we have without needing
to parse the response, the better.
Example, instead of:
writer.write("<br>Foo</br>");
do the following
writer.beginElement("br", null);
writer.write("Foo");
writer.endElement("br");
It's a bit more code but is easier to read, and transform into other
markups if need be.
Plus it will prevent the typo in your code below:
<br />Foo</br>
is not a valid markup anyway. It should be:
<br>Foo</br> OR <br />Foo<br />
Scott
arne anka wrote:
> thought, i mentioned it already -- there is no xhtml involved. i try
> to do it entirely in java:
>
> public class FedoraObjectContentComponentUI extends UIOutput
> {
> private byte[] myObject = null;
> private String myMime, myDS, myID;
>
> @Override
> public String getFamily()
> {
> return "fedoraobjectcontent";
> }
>
> @Override
> public String getRendererType()
> {
> return null;
> }
>
> @Override
> public void encodeBegin(FacesContext context) throws IOException
> {
> super.encodeBegin(context);
> final ResponseWriter writer = context.getResponseWriter();
> writer.write("<br/>Foo</br>");
> }
>
> @Override
> public Object saveState(FacesContext context)
> {
> Object values[] = new Object[5];
> values[0] = super.saveState(context);
> values[1] = myObject;
> values[2] = myMime;
> values[3] = myDS;
> values[4] = myID;
> return ((Object) (values));
> }
>
> @Override
> public void restoreState(FacesContext context, Object state)
> {
> Object values[] = (Object[]) state;
> super.restoreState(context, values[0]);
> myObject = (byte[]) values[1];
> myMime = (String) values[2];
> myDS = (String) values[3];
> myID = (String) values[4];
> }
> }
>
> and in faces-config.xml
>
> <component>
> <component-type>component</component-type>
> <component-class>my.package.Components.FedoraObjectContentComponentUI</component-class>
>
> </component>
>
> that's my component, basically.
>
> On Wed, 23 Apr 2008 19:52:21 +0200, Andrew Robinson
> <an...@gmail.com> wrote:
>
>> I should have asked this earlier, what is my:component? Do you use
>> ui:component in the root of the xhtml file? Is there getConverter /
>> setConverter methods on the component?
>>
>> If you could provide a small code snippet from the facelet and the
>> component that it uses that would help.
>>
>> -Andrew
>>
>> On Wed, Apr 23, 2008 at 11:31 AM, arne anka <do...@ginguppin.de> wrote:
>>> snippet from faces-config.xml:
>>> <converter>
>>> <description>
>>> </description>
>>> <display-name>contentConverter</display-name>
>>> <converter-id>contentConverter</converter-id>
>>>
>>> <converter-class>my.package.FaceletsElements.FedoraObjectContentConverter</converter-class>
>>>
>>> </converter>
>>>
>>> as said before -- it works with standard components. so it seems to be
>>> something trivial i do not see.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Wed, 23 Apr 2008 19:21:37 +0200, Andrew Robinson
>>> <an...@gmail.com> wrote:
>>>
>>>
>>> > Have you registered the converter in faces-config.xml properly?
>>> Please
>>> > post your configuration for your converter
>>> >
>>> > On Wed, Apr 23, 2008 at 7:20 AM, arne anka <do...@ginguppin.de> wrote:
>>> >
>>> > > hi,
>>> > > i got my custom component (faclets based, not tomahawk or
>>> trinidad,
>>> > > extending UIOutput) working so far -- but my converter is not
>>> executed.
>>> > > if i attribute the converter to, say, h:outputText it works, so it
>>> seems to
>>> > > be ok.
>>> > > my idea is, because i use my own rendere (getRendererType()
>>> returns
>>> null)
>>> > > maybe i need to call it myself?
>>> > > if so, how do i get hold of the converter?
>>> > >
>>> > > both with
>>> > >
>>> > > <my:component value="foo" converter="contentConverter" />
>>> > >
>>> > > and with
>>> > >
>>> > > <my:component value="foo">
>>> > > <f:converter converterId="contentConverter"/>
>>> > > </my:component>
>>> > >
>>> > > getConverter() always returns null
>>> > >
>>> > > thanks in advance
>>> > >
>>> > >
>>> >
>>>
>>>
>>>
>
>
Re: facelets: custom component and custom converter
Posted by arne anka <do...@ginguppin.de>.
thought, i mentioned it already -- there is no xhtml involved. i try to do
it entirely in java:
public class FedoraObjectContentComponentUI extends UIOutput
{
private byte[] myObject = null;
private String myMime, myDS, myID;
@Override
public String getFamily()
{
return "fedoraobjectcontent";
}
@Override
public String getRendererType()
{
return null;
}
@Override
public void encodeBegin(FacesContext context) throws IOException
{
super.encodeBegin(context);
final ResponseWriter writer = context.getResponseWriter();
writer.write("<br/>Foo</br>");
}
@Override
public Object saveState(FacesContext context)
{
Object values[] = new Object[5];
values[0] = super.saveState(context);
values[1] = myObject;
values[2] = myMime;
values[3] = myDS;
values[4] = myID;
return ((Object) (values));
}
@Override
public void restoreState(FacesContext context, Object state)
{
Object values[] = (Object[]) state;
super.restoreState(context, values[0]);
myObject = (byte[]) values[1];
myMime = (String) values[2];
myDS = (String) values[3];
myID = (String) values[4];
}
}
and in faces-config.xml
<component>
<component-type>component</component-type>
<component-class>my.package.Components.FedoraObjectContentComponentUI</component-class>
</component>
that's my component, basically.
On Wed, 23 Apr 2008 19:52:21 +0200, Andrew Robinson
<an...@gmail.com> wrote:
> I should have asked this earlier, what is my:component? Do you use
> ui:component in the root of the xhtml file? Is there getConverter /
> setConverter methods on the component?
>
> If you could provide a small code snippet from the facelet and the
> component that it uses that would help.
>
> -Andrew
>
> On Wed, Apr 23, 2008 at 11:31 AM, arne anka <do...@ginguppin.de> wrote:
>> snippet from faces-config.xml:
>> <converter>
>> <description>
>> </description>
>> <display-name>contentConverter</display-name>
>> <converter-id>contentConverter</converter-id>
>>
>> <converter-class>my.package.FaceletsElements.FedoraObjectContentConverter</converter-class>
>> </converter>
>>
>> as said before -- it works with standard components. so it seems to be
>> something trivial i do not see.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Wed, 23 Apr 2008 19:21:37 +0200, Andrew Robinson
>> <an...@gmail.com> wrote:
>>
>>
>> > Have you registered the converter in faces-config.xml properly? Please
>> > post your configuration for your converter
>> >
>> > On Wed, Apr 23, 2008 at 7:20 AM, arne anka <do...@ginguppin.de> wrote:
>> >
>> > > hi,
>> > > i got my custom component (faclets based, not tomahawk or trinidad,
>> > > extending UIOutput) working so far -- but my converter is not
>> executed.
>> > > if i attribute the converter to, say, h:outputText it works, so it
>> seems to
>> > > be ok.
>> > > my idea is, because i use my own rendere (getRendererType() returns
>> null)
>> > > maybe i need to call it myself?
>> > > if so, how do i get hold of the converter?
>> > >
>> > > both with
>> > >
>> > > <my:component value="foo" converter="contentConverter" />
>> > >
>> > > and with
>> > >
>> > > <my:component value="foo">
>> > > <f:converter converterId="contentConverter"/>
>> > > </my:component>
>> > >
>> > > getConverter() always returns null
>> > >
>> > > thanks in advance
>> > >
>> > >
>> >
>>
>>
>>
Re: facelets: custom component and custom converter
Posted by Andrew Robinson <an...@gmail.com>.
I should have asked this earlier, what is my:component? Do you use
ui:component in the root of the xhtml file? Is there getConverter /
setConverter methods on the component?
If you could provide a small code snippet from the facelet and the
component that it uses that would help.
-Andrew
On Wed, Apr 23, 2008 at 11:31 AM, arne anka <do...@ginguppin.de> wrote:
> snippet from faces-config.xml:
> <converter>
> <description>
> </description>
> <display-name>contentConverter</display-name>
> <converter-id>contentConverter</converter-id>
>
> <converter-class>my.package.FaceletsElements.FedoraObjectContentConverter</converter-class>
> </converter>
>
> as said before -- it works with standard components. so it seems to be
> something trivial i do not see.
>
>
>
>
>
>
>
>
>
> On Wed, 23 Apr 2008 19:21:37 +0200, Andrew Robinson
> <an...@gmail.com> wrote:
>
>
> > Have you registered the converter in faces-config.xml properly? Please
> > post your configuration for your converter
> >
> > On Wed, Apr 23, 2008 at 7:20 AM, arne anka <do...@ginguppin.de> wrote:
> >
> > > hi,
> > > i got my custom component (faclets based, not tomahawk or trinidad,
> > > extending UIOutput) working so far -- but my converter is not executed.
> > > if i attribute the converter to, say, h:outputText it works, so it
> seems to
> > > be ok.
> > > my idea is, because i use my own rendere (getRendererType() returns
> null)
> > > maybe i need to call it myself?
> > > if so, how do i get hold of the converter?
> > >
> > > both with
> > >
> > > <my:component value="foo" converter="contentConverter" />
> > >
> > > and with
> > >
> > > <my:component value="foo">
> > > <f:converter converterId="contentConverter"/>
> > > </my:component>
> > >
> > > getConverter() always returns null
> > >
> > > thanks in advance
> > >
> > >
> >
>
>
>
Re: facelets: custom component and custom converter
Posted by arne anka <do...@ginguppin.de>.
snippet from faces-config.xml:
<converter>
<description>
</description>
<display-name>contentConverter</display-name>
<converter-id>contentConverter</converter-id>
<converter-class>my.package.FaceletsElements.FedoraObjectContentConverter</converter-class>
</converter>
as said before -- it works with standard components. so it seems to be
something trivial i do not see.
On Wed, 23 Apr 2008 19:21:37 +0200, Andrew Robinson
<an...@gmail.com> wrote:
> Have you registered the converter in faces-config.xml properly? Please
> post your configuration for your converter
>
> On Wed, Apr 23, 2008 at 7:20 AM, arne anka <do...@ginguppin.de> wrote:
>> hi,
>> i got my custom component (faclets based, not tomahawk or trinidad,
>> extending UIOutput) working so far -- but my converter is not executed.
>> if i attribute the converter to, say, h:outputText it works, so it
>> seems to
>> be ok.
>> my idea is, because i use my own rendere (getRendererType() returns
>> null)
>> maybe i need to call it myself?
>> if so, how do i get hold of the converter?
>>
>> both with
>>
>> <my:component value="foo" converter="contentConverter" />
>>
>> and with
>>
>> <my:component value="foo">
>> <f:converter converterId="contentConverter"/>
>> </my:component>
>>
>> getConverter() always returns null
>>
>> thanks in advance
>>
Re: facelets: custom component and custom converter
Posted by Andrew Robinson <an...@gmail.com>.
Have you registered the converter in faces-config.xml properly? Please
post your configuration for your converter
On Wed, Apr 23, 2008 at 7:20 AM, arne anka <do...@ginguppin.de> wrote:
> hi,
> i got my custom component (faclets based, not tomahawk or trinidad,
> extending UIOutput) working so far -- but my converter is not executed.
> if i attribute the converter to, say, h:outputText it works, so it seems to
> be ok.
> my idea is, because i use my own rendere (getRendererType() returns null)
> maybe i need to call it myself?
> if so, how do i get hold of the converter?
>
> both with
>
> <my:component value="foo" converter="contentConverter" />
>
> and with
>
> <my:component value="foo">
> <f:converter converterId="contentConverter"/>
> </my:component>
>
> getConverter() always returns null
>
> thanks in advance
>