myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Kienenberger" <>
Subject Re: custom outputText
Date Wed, 29 Aug 2007 15:36:15 GMT
Since the most likely place for an error to occur is dealing with
creating and populating the attribute on the component, I'd recommend
writing the renderer first, and hardcoding the value for the
matchingValue at first.  For example, in your custom renderer,

public String getMatchingValue(UIComponent component) { return "lamb"; }

Once you have the custom renderer working, then it's just a matter of
doing the busywork and debugging to provide the matching value to the
renderer by replacing "lamb" with "component.getMatchingValue()"

On 8/29/07, Mike Kienenberger <> wrote:
> Yes, I think you're on the right track.  You don't need to create a
> custom OutputText component; you just need to create a custom
> OutputText renderer.
> If you're using facelets, you can probably do this by using a generic
> attribute, so you really only need to create a new renderer.
> If you're using jsp, you'll have to subclass OutputText and the
> OutputTextTag to store the matchingValue attribute on your component,
> and in that case, you might as well use a concrete attribute.   You'll
> also want to probably do a saveState/restoreState on that attribute as
> well so it's preserved.   I don't remember if generic attributes get
> saveState/restoreState, so you might even want to do this with
> facelets.
> Once the component.getMatchingValue() method is available, then you
> should simply be able to make use of it from your custom
> OutputTextRenderer.     To install your renderer, I think you simply
> need to register it in a faces-config.xml file with a matching
> component.
> I'm not much help on the details as I haven't tried creating a custom
> renderer recently.   I think it's all pretty straight-forward, though,
> from what I remember.   You can always look at the MyFaces & Tomahawk
> code as examples.
> On 8/29/07, kewldude <> wrote:
> >
> >
> > Okay, I have no experience whatsoever in creating a custom component, but I
> > just finished reading this
> > guide  on creating custom
> > components.
> >
> > What I want to achieve is to customize the outputText component wherein any
> > value of the outputText component will be compared to a string that is a
> > value of a new attribute called matchString. Lets say the value in your
> > outputText is "Mary had a little lamb." and the value of the matchString
> > attribute is "lamb" (or it can be value binding also), what I would like to
> > do is to change the color of the word "lamb" found in the "Mary had a little
> > lamb" kinda value of the outputText (so when it is displayed the lamb word
> > is hihglighted).
> >
> > My question is where do i place this code all together? I've read about
> > having a Tag Class and a Component class and Im still trying to digest the
> > idea. Where do you put the code(what method of the class) that takes care of
> > outputting the value of outputText? My idea is to get the value of the value
> > attribute then do some match and compare with the matchString vlaue, maybe
> > via regex, then specifically write the html that will produce the different
> > color for that match...I hope someone out there is generous enough to
> > produce just a pseudocode that could guide me in creating this custom
> > component...thanks...
> > --
> > View this message in context:
> > Sent from the MyFaces - Users mailing list archive at
> >
> >

View raw message