You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rafael Nami <ra...@gmail.com> on 2005/11/03 14:32:36 UTC

Writing my own Tags

Sorry about this silly question, but I have this simple problem.
When I write my own component, I do essentially what corejsf book says,
and it works nicely. But when I try to jar this component and use it, it
isn't finding the UI class.
(I'm putting in the JAR all the sources, excluding of course the libs and
the resources(tld)).
What are the steps to write my own component and pack it nicely in a jar
file?

Thanks and best regards

Rafael Mauricio Nami

Re: Writing my own Tags

Posted by Rafael Nami <ra...@gmail.com>.
Thanks for the detailed clarification, Mike.:)

Best Regards

Rafael Mauricio Nami

2005/11/3, Mike Kienenberger <mk...@gmail.com>:
>
> 1 - It's obsolete. This data used to be used by a code generator to
> create the tld and faces-config, and possibly other files.
>
> 2 - That's the purpose of the renderer, not the component. The
> component isn't tied to any particular presentation format (like html,
> xml, wap, or so forth).
>
> > attribute best practice
>
> Well, if you want to insure the widest possible audience, do the least
> amount possible with the Tag class. Essentially, make it a
> pass-through setter. This allows other non-JSF ViewHandlers (like
> Facelets and Shale/Clay) to seemlessly use your component. In fact,
> most components can be used in facelets without writing any tag
> handler support.
>
> On 11/3/05, Rafael Nami <ra...@gmail.com> wrote:
> > Ah, the META-INF thing was missing. And about the source thing, if I
> include
> > the source folder in eclipse to generate the jar, it will of course
> generate
> > the classes ;). Sorry, my bad.
> > Still in the subject, is there any utils to avoid writing ugly render
> code
> > in the component, like doing
> > encodeInputField,encodeXXXButton, etc..., like in the
> > corejsf book??? I've seen the code in myfaces, is SOOOOOOOOOOOOOOOOOO
> much
> > cleaner and elegant, but I couldn't understood a thing :(. I have
> basically
> > two
> > questions:
> > 1 - What is the purpose of the <Component>.xml, like HtmlInputText.xml
> ???
> > It overrides dinamically the default component
> > with the attributes added in it (and the generateStateMethods="true" and
> > generateUserRoleMethods="true" attributes in the component node exists
> for
> > what purpose???)?
> > 2 - Why the hell isn't any writer, or encode, or even decode code in
> faces
> > components (I've searched for this kind of code in the components, but
> in
> > the four that I've searched, there were no code like this)???
> >
> > Another thing is that the code insid HtmlInputText, for example, has
> > valueBinding, something that in corejsf book is inside the Tag class.
> What's
> > the "best practice" to write components in JSF? For my newbie point of
> view,
> > your code(myfaces) is "THE" best example to follow. ;)
> >
> > Thanks and Best Regards
> >
> > 2005/11/3, Bruno Aranda <br...@gmail.com>:
> > > Apart from including the classes, you have to include the tld and the
> > > faces-config.xml (where you define the component and the renderer) in
> > > the META-INF folder of your jar package,
> > >
> > > Regards,
> > >
> > > Bruno
> > >
> > > 2005/11/3, Martin Marinschek <ma...@gmail.com>:
> > > > source? I hope you are packaging the classes ;)
> > > >
> > > > regards,
> > > >
> > > > Martin
> > > >
> > > > On 11/3/05, Rafael Nami <ra...@gmail.com> wrote:
> > > > > Sorry about this silly question, but I have this simple problem.
> > > > > When I write my own component, I do essentially what corejsf book
> > says,
> > > > > and it works nicely. But when I try to jar this component and use
> it,
> > it
> > > > > isn't finding the UI class.
> > > > > (I'm putting in the JAR all the sources, excluding of course the
> libs
> > and
> > > > > the resources(tld)).
> > > > > What are the steps to write my own component and pack it nicely in
> a
> > jar
> > > > > file?
> > > > >
> > > > > Thanks and best regards
> > > > >
> > > > > Rafael Mauricio Nami
> > > > >
> > > >
> > > >
> > > > --
> > > >
> > > > http://www.irian.at
> > > > Your JSF powerhouse -
> > > > JSF Trainings in English and German
> > > >
> > >
> >
> >
>

Re: Writing my own Tags

Posted by Mike Kienenberger <mk...@gmail.com>.
1 - It's obsolete.   This data used to be used by a code generator to
create the tld and faces-config, and possibly other files.

2 - That's the purpose of the renderer, not the component.  The
component isn't tied to any particular presentation format (like html,
xml, wap, or so forth).

> attribute best practice

Well, if you want to insure the widest possible audience, do the least
amount possible with the Tag class.   Essentially, make it a
pass-through setter.   This allows other non-JSF ViewHandlers (like
Facelets and Shale/Clay) to seemlessly use your component.   In fact,
most components can be used in facelets without writing any tag
handler support.

On 11/3/05, Rafael Nami <ra...@gmail.com> wrote:
> Ah, the META-INF thing was missing. And about the source thing, if I include
> the source folder in eclipse to generate the jar, it will of course generate
> the classes ;). Sorry, my bad.
>  Still in the subject, is there any utils to avoid writing ugly render code
> in the component, like doing
> encodeInputField,encodeXXXButton,  etc..., like in the
> corejsf book??? I've seen the code in myfaces, is SOOOOOOOOOOOOOOOOOO much
> cleaner and elegant, but I couldn't understood a thing :(. I have basically
> two
>  questions:
>  1 - What is the purpose of the <Component>.xml, like HtmlInputText.xml???
> It overrides dinamically the default component
>  with the attributes added in it (and the generateStateMethods="true" and
> generateUserRoleMethods="true" attributes in the component node exists for
> what purpose???)?
>  2 - Why the hell isn't any writer, or encode, or even decode code in faces
> components (I've searched for this kind of code in the components, but in
> the four that I've searched, there were no code like this)???
>
>  Another thing is that the code insid HtmlInputText, for example, has
> valueBinding, something that in corejsf book is inside the Tag class. What's
> the "best practice" to write components in JSF? For my newbie point of view,
> your code(myfaces) is "THE" best example to follow. ;)
>
>  Thanks and Best Regards
>
> 2005/11/3, Bruno Aranda <br...@gmail.com>:
> > Apart from including the classes, you have to include the tld and the
> > faces-config.xml (where you define the component and the renderer) in
> > the META-INF folder of your jar package,
> >
> > Regards,
> >
> > Bruno
> >
> > 2005/11/3, Martin Marinschek <ma...@gmail.com>:
> > > source? I hope you are packaging the classes ;)
> > >
> > > regards,
> > >
> > > Martin
> > >
> > > On 11/3/05, Rafael Nami <ra...@gmail.com> wrote:
> > > > Sorry about this silly question, but I have this simple problem.
> > > >  When I write my own component, I do essentially what corejsf book
> says,
> > > >  and it works nicely. But when I try to jar this component and use it,
> it
> > > > isn't finding the UI class.
> > > >  (I'm putting in the JAR all the sources, excluding of course the libs
> and
> > > > the resources(tld)).
> > > >  What are the steps to write my own component and  pack it nicely in a
> jar
> > > > file?
> > > >
> > > >  Thanks and best regards
> > > >
> > > >  Rafael Mauricio Nami
> > > >
> > >
> > >
> > > --
> > >
> > > http://www.irian.at
> > > Your JSF powerhouse -
> > > JSF Trainings in English and German
> > >
> >
>
>

Re: Writing my own Tags

Posted by Simon Kitching <sk...@obsidium.com>.
Rafael Nami wrote:
> 2 - Why the hell isn't any writer, or encode, or even decode code in 
> faces components (I've searched for this kind of code in the components, 
> but in the four that I've searched, there were no code like this)???
> 

JSF supports separating the "rendering" of a component into a separate 
class from the component itself.

In a component constructor the component typically calls
  this.setRendererType(stringContainingRendererName)
which defines the default renderer "name" for the component.

A JSP tag can override this by calling setRendererType on the component 
it creates.

When the JSF framework wants to render the object it calls 
component.getRendererType. If a non-null value is returned it then looks 
up in its config files to map the renderer name to an actual renderer 
class-name, instantiates the renderer class, and invokes renderer 
methods encodeBegin/encodeChildren/encodeEnd etc on the renderer object 
rather than on the component. This separates out the rendering from the 
component logic and also allows different renderers (HTML/XHTML/WAP/etc) 
to be attached to the same component.

If the JSF component calls component.getRendererType and gets null 
returned then the encodeBegin/encodeChildren/encodeEnd get called on the 
component itself. This can be useful when writing a custom component for 
a specific project where only one renderer will ever be used with it, as 
it's simpler to manage everything in one class and no 
renderertype->renderer-class mapping needs to be defined in the 
faces-config.xml file.

Note: I'm fairly new to JSF so some details may not be 100% correct!

Regards,

Simon


Re: Writing my own Tags

Posted by Rafael Nami <ra...@gmail.com>.
Ah, the META-INF thing was missing. And about the source thing, if I include
the source folder in eclipse to generate the jar, it will of course generate
the classes ;). Sorry, my bad.
Still in the subject, is there any utils to avoid writing ugly render code
in the component, like doing encodeInputField,encodeXXXButton, etc..., like
in the corejsf book??? I've seen the code in myfaces, is SOOOOOOOOOOOOOOOOOO
much cleaner and elegant, but I couldn't understood a thing :(. I have
basically two
questions:
1 - What is the purpose of the <Component>.xml, like HtmlInputText.xml??? It
overrides dinamically the default component
with the attributes added in it (and the generateStateMethods="true" and
generateUserRoleMethods="true" attributes in the component node exists for
what purpose???)?
2 - Why the hell isn't any writer, or encode, or even decode code in faces
components (I've searched for this kind of code in the components, but in
the four that I've searched, there were no code like this)???

Another thing is that the code insid HtmlInputText, for example, has
valueBinding, something that in corejsf book is inside the Tag class. What's
the "best practice" to write components in JSF? For my newbie point of view,
your code(myfaces) is "THE" best example to follow. ;)

Thanks and Best Regards

2005/11/3, Bruno Aranda <br...@gmail.com>:
>
> Apart from including the classes, you have to include the tld and the
> faces-config.xml (where you define the component and the renderer) in
> the META-INF folder of your jar package,
>
> Regards,
>
> Bruno
>
> 2005/11/3, Martin Marinschek <ma...@gmail.com>:
> > source? I hope you are packaging the classes ;)
> >
> > regards,
> >
> > Martin
> >
> > On 11/3/05, Rafael Nami <ra...@gmail.com> wrote:
> > > Sorry about this silly question, but I have this simple problem.
> > > When I write my own component, I do essentially what corejsf book
> says,
> > > and it works nicely. But when I try to jar this component and use it,
> it
> > > isn't finding the UI class.
> > > (I'm putting in the JAR all the sources, excluding of course the libs
> and
> > > the resources(tld)).
> > > What are the steps to write my own component and pack it nicely in a
> jar
> > > file?
> > >
> > > Thanks and best regards
> > >
> > > Rafael Mauricio Nami
> > >
> >
> >
> > --
> >
> > http://www.irian.at
> > Your JSF powerhouse -
> > JSF Trainings in English and German
> >
>

Re: Writing my own Tags

Posted by Bruno Aranda <br...@gmail.com>.
Apart from including the classes, you have to include the tld and the
faces-config.xml (where you define the component and the renderer) in
the META-INF folder of your jar package,

Regards,

Bruno

2005/11/3, Martin Marinschek <ma...@gmail.com>:
> source? I hope you are packaging the classes ;)
>
> regards,
>
> Martin
>
> On 11/3/05, Rafael Nami <ra...@gmail.com> wrote:
> > Sorry about this silly question, but I have this simple problem.
> >  When I write my own component, I do essentially what corejsf book says,
> >  and it works nicely. But when I try to jar this component and use it, it
> > isn't finding the UI class.
> >  (I'm putting in the JAR all the sources, excluding of course the libs and
> > the resources(tld)).
> >  What are the steps to write my own component and  pack it nicely in a jar
> > file?
> >
> >  Thanks and best regards
> >
> >  Rafael Mauricio Nami
> >
>
>
> --
>
> http://www.irian.at
> Your JSF powerhouse -
> JSF Trainings in English and German
>

Re: Writing my own Tags

Posted by Martin Marinschek <ma...@gmail.com>.
source? I hope you are packaging the classes ;)

regards,

Martin

On 11/3/05, Rafael Nami <ra...@gmail.com> wrote:
> Sorry about this silly question, but I have this simple problem.
>  When I write my own component, I do essentially what corejsf book says,
>  and it works nicely. But when I try to jar this component and use it, it
> isn't finding the UI class.
>  (I'm putting in the JAR all the sources, excluding of course the libs and
> the resources(tld)).
>  What are the steps to write my own component and  pack it nicely in a jar
> file?
>
>  Thanks and best regards
>
>  Rafael Mauricio Nami
>


--

http://www.irian.at
Your JSF powerhouse -
JSF Trainings in English and German