Custom component/tag class:  ---which setters/getters do what?

Hi
I'm trying to create a custom component, but, there is a major concept that I do not understand...
---What are the setters/getters in the "component" class used for?...
---What are the setters/getters in the "tag" class used for?
Another way of asking is...
---Which setters/getters are used simply to keep track of attribute name/id/key?
---Which setters and getters refer to the actual objects that the attribute names point to?
The reason for my confusion is that nearly all "custom component" examples I've seen thus far, utilize attributes that point to "String" objects... (i.e., as opposed to ArrayList, HashMap, etc)...
This makes it difficult for me to distinguish whether the String values in the getters/setters are referring to the String name/"id" of the attribute...or, the String "value" of the attribute...
I have not been able to verify how I should code the getter/setters (and type casts) for other kinds of objects like ArrayLists, HashMaps, etc
For example, a typical logic mechanism Ive seen in the custom "tag" examples is as follows...
in a "tag" class...
        if( tabledata != null )
            if (isValueReference (tabledata))
                FacesContext context = FacesContext.getCurrentInstance ();
                Application app = context.getApplication ();
                ValueBinding vb = app.createValueBinding (tabledata);
                component.setValueBinding ("tabledata", vb);
            else
                component.getAttributes ().put ("tabledata", tabledata);
in the "component" class...
    public void setTabledata (List tabledata)
        this.tabledata = tabledata;
    public List getTabledata ()
        if(null != tabledata)
            return tabledata;
        ValueBinding _vb = getValueBinding ("tabledata");
        if(_vb != null)
            return (List)_vb.getValue (getFacesContext ());
        else
            return null;
    }...considering the above code,
---when/where should the "tabledata" variable be referring the "name/id" of the attribute?...
---when/where should the "tabledata" variable be referring to the "value" of the attribute?...
...as, I need to change the type casting to adjust to what it should be...
***NOTE: This is one error that I'm getting, and I believe it is because I do not understand how getter/setter is used in "component" and "tag" classe, i.e., :
"org.apache.jasper.JasperException: jsp.error.beans.property.conversion
     org.apache.jasper.runtime.JspRuntimeLibrary.getValueFromPropertyEditorManager(JspRuntimeLibrary.java:885)"...
Thanks for any help on this!
sd

The "tabledata" variable always refers the local value of the attribute.
When using a value binding to some backing bean,
the local value is null and the model value is owned by the bean.
You don't need any casting in the tag class nor the component class.
The setters/getters in the component class specify the type of the attributes.
Conversion from/to String to/from the type is done automatically if possible.
When the automatic conversion is impossible, you should specify f:converter
for the attribute.

Similar Messages

  • Problem custom component with children in RestoreView phase

    Hi there!
    I've got a problem with a custom component that I am writing. It consists of several UISelectOne and UIInputText components. Depending on the value selected in the UISelectOne components, the UISelectOne and UIInputText components may change. Therefore I attached a ValueChangeListener to the UISelectOne components. So far, so good.
    The problem is, when the event is triggered, I get an ArrayIndexOutOfBoundsException. It took me a while to track it down. The problem seems to be, that during the Restore View phase, the StateManager's restoreComponentTreeStructure method first creates the component again and later restores its tree structure.
    During creation of the component, its constructor is called in which I add the children to the component. While restoring the tree structure, the StateManager again adds the children to the component. So the list of my component's children contains each child twice.
    The exception is due to the fact that in the saved state array only the original component's states are saved (which is perfectly right). So while restoring state and iterating through the component's children, the exception is thrown for the first child which is twice in the list (which is also perfectly right).
    I hope this description is not too confusing. My question is, if anyone can give me a hint what I am doing wrong here? How can I avoid the component being initialized again? Or where should I add the children to the component?
    Thanks for any advices!

    Hi again,
    I've perpared a minimal example (which in fact is quite big, but considering it's a custom tag it's probably not possible to make it smaller):
    The UITest class (as you can see I add the child component in the constructor):
    package test;
    import java.io.IOException;
    import java.util.*;
    import java.util.ArrayList;
    import java.util.List;
    import javax.faces.application.Application;
    import javax.faces.component.*;
    import javax.faces.context.FacesContext;
    import javax.faces.context.ResponseWriter;
    import javax.faces.event.ValueChangeEvent;
    import javax.faces.model.SelectItem;
    public class UITest extends UIInput {
      public static final String COMPONENT_TYPE = "Test";
      public static final String COMPONENT_FAMILY = "Test";
      private UISelectOne selectOne;
      private UISelectItems selectItems;
      public UITest(){
        Application application = FacesContext.getCurrentInstance().getApplication();
        selectItems = (UISelectItems)application.createComponent(UISelectItems.COMPONENT_TYPE);
        List items = new ArrayList();
        items.add(new SelectItem("One", "one"));
        items.add(new SelectItem("Two", "two"));
        selectItems.setValue(items);
        selectOne = (UISelectOne)application.createComponent(UISelectOne.COMPONENT_TYPE);
        selectOne.getAttributes().put("onchange", "submit()");
        Class[] params = {ValueChangeEvent.class};
        selectOne.setValueChangeListener(application.createMethodBinding("#{TestBean.valueChange}", params));
        selectOne.getChildren().add(selectItems);
        this.getChildren().add(selectOne);
      public void encodeChildren(FacesContext context) throws IOException {
        ResponseWriter writer = context.getResponseWriter();
        Iterator children = getChildren().iterator();
        while(children.hasNext()){
          UIComponent child = (UIComponent)children.next();
          if(child.isRendered()){
            child.encodeBegin(context);
            if(child.getRendersChildren()){
              child.encodeChildren(context);
            child.encodeEnd(context);
      public boolean getRendersChildren(){
        return true;
    }The component tag class:
    package test;
    import javax.faces.webapp.UIComponentTag;
    public class TestTag extends UIComponentTag {
      public String getComponentType() {    return "Test";  }
      public String getRendererType() {    return null;  }
    }Tag registration:
      <tag>
        <name>test</name>
        <tag-class>test.TestTag</tag-class>
      </tag>The backing bean:
    package test;
    import javax.faces.event.ValueChangeEvent;
    public class TestBean {
      private String currentValue;
      public void valueChange(ValueChangeEvent event) {
        System.err.println(event.getNewValue());
      public String getCurrentValue() {
        return currentValue;
      public void setCurrentValue(String currentValue) {
        this.currentValue = currentValue;
    }And finally the definition in the faces-config:
       <component>
          <component-type>Test</component-type>
          <component-class>test.UITest</component-class>
       </component>
       <managed-bean>
        <managed-bean-name>TestBean</managed-bean-name>
        <managed-bean-class>test.TestBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>When included in the JSP and then clicked on the combobox, I get an ArrayIndexOutOfBoundsException.
    Can anyone give me a hint what the problem might be?
    Thanks in advance!

  • Custom Component Not Updating Display List

    Hi all... I've created a component which is basically a meter (extends skinnable container). The skin to the component contains two rectangles (background and the actual meter).  This component receives an arraycollection with the following fields value, max and min(the arraycollection I am passing is Bindable). When I initialize and pass the data to be used to draw It works great (keep in mind - only works the first time).  I've created a button that changes the data array and shows the current meter value.  Apparently the meter's value is changing everytime I modify the ArrayCollection I've set to be used for rendering.(dont want to say "dataProvider" because it is not a Flex dataprovider, just a variable )... here is the code...
       public class meter extends SkinnableContainer {
            [SkinPart( required = "true" )]
            public var meter:spark.primitives.Rect;
            [SkinPart( required = "true" )]
            public var meterBackground:spark.primitives.Rect;
            private var _dataProvider:ArrayCollection;
            private var _renderDirty:Boolean = false;
            public function Meter() {
                super();
            public function set dataProvider( value:Object ):void {
                if ( value )
                    if(value is ArrayCollection)
                           _renderDirty = true;
                        _dataProvider = value as ArrayCollection;
                    if(_dataProvider)
                        _dataProvider.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, propertyChanged);//used both eventlisteners but none actually ever fire off
                        _dataProvider.addEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChanged);
                    invalidateDisplayList();//only happens the first time
            private function collectionChanged(event:CollectionEvent):void
                Alert.show("In collection Change");//this never goes off when I change the "dataProvider"
                _renderDirty = true;
                invalidateDisplayList();
            private function propertyChanged(event:PropertyChangeEvent):void
                Alert.show("In property Change");//this never goes off when I change the "dataProvider"
                _renderDirty=true;
                 invalidateDisplayList();
            public function get dataProvider():Object {
                return _dataProvider;
            override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ):void {
                if(_dataProvider))
                var span:Number = unscaledWidth / _dataProvider[0].max;
                var meterWidth:Number = _dataProvider[0].value * span;
                meter.width = meterWidth;
                _renderDirty = false;
    And this is the mxml code where I change the "value" field....
    <fx:Script>
    <![CDATA[
    [Bindable]
                private var meterData:ArrayCollection = new ArrayCollection([               
                    {value:80, max:100, min:0}
                protected function mySlider_changeHandler(event:Event):void
                    meterData[0].value = Math.round(mySlider.value)*10;               
                protected function button1_clickHandler(event:MouseEvent):void
                    // TODO Auto-generated method stub
                    var array:ArrayCollection = testMeter.dataProvider as ArrayCollection;
                    var value:Number = array[0].value as Number;
                    Alert.show(value.toString());
                   // testMeter.meter.width= Math.random()*100;
            ]]>//initial value in "meterData" does get drawn...but when it's changed with the slider..nothing happens..
           <custom:Meter id="testMeter" dataProvider="{meterData}" />
            <s:HSlider id="mySlider"
                       liveDragging="true"
                       dataTipPrecision="0"
                       change="mySlider_changeHandler(event)"
                       value="3"/>
            <s:Button click="button1_clickHandler(event)"/>
    Can you help me figure out what's going on??Thanks guys!!!

    Hi.
    Now there are some serious bugs in your code:
    Put a call to super.updateDisplayList(unscaledWidth, unscaledHeight) in your overriden method (or some funky things will start happening or it won't work at all).
    Why don't you check your _renderDirty flag in the updateDisplayList() method? You should do that (personally I would go with commitProperties() instead but it's not much of a difference I guess)
    And now the reason why your events don't fire is that because you use plain objects (just generic istances of Object). Those are not IEventDispatchers and therefore do not fire any events when you change any of the properties (which are all dynamic by the way). You have to define a custom value object class which extends the EventDispatcher (or you can implement IEventDispatcher on your own). So instead of this:[Bindable]
    private var meterData:ArrayCollection = new ArrayCollection([
       {value:80, max:100, min:0}
    You should do something like this:[Bindable]
    private var meterData:ArrayCollection = new ArrayCollection([
       new MyValueObject(80, 100, 0)
    Where MyValueObject could look like this:// this instructs MXML compiler to automaticly implement IEventDispatcher
    // and make all public properties bindable
    [Bindable]
    public class MyValueObject
       public function MyValueObject(value:Number, max:Number, min:Number) {
          this.value = value;
          this.max = max;
          this.min = min;
       public var value:Number;
       public var max:Number;
       public var min:Number;

  • How to get jsp PageContext in custom component renderer

    Hi,
    How to find PageContext(javax.servlet.jsp.PageContext) form within the custom component renderer class?
    Please help?
    Thanx & Regards
    Milind

    Strictly you're looking which URL has invoked the new request? With other words, you want the referrer?
    If so, doString referrer = request.getHeader("referer"); // Yes, with the legendaric misspelling.Be careful with this, the client has full control over what he/she sends with the headers, so also the referrer. It might be null or changed while you didn't expect that. If you want to be safe, you may consider to send the current URL as a hidden parameter along with the request.

  • Custom component with additional tags

    Hi. I need to write complicated custom JSF component.
    I know how to write simple custom components, and receive String variables from tag attributes e.g.
    https://github.com/devalentino/temp/blob/master/src/main/java/net/monopolyclub/components/component/UserData.java
    But now I need to write custom component with additional tags (for example like dataTable and column tags).
    How can I write such component? How can I receive collections in my component? How can I work with additional tags in my component.
    for example I need something like:
    <m:chat>
         <m:tab value="#{UserList}" />
         <m:message value="#{MesageMap}" />
    </m:chat>
    where UserList - Collection with current users and MessageMap is Map with User as key and message as value.

    Iam using pt:ptdata.joincurrcommunitydata
    here is some code
    <pt:ptdata.joincurrcommunitydata pt:id="menutabsjoin" />
    <pt:logic.foreach pt:var="temp2" pt:data="menutabsjoin">
    <span class="CommunityPage">
    <pt:core.html href="$temp2.url" pt:tag="a">
    <pt:core.html pt:tag="img" src="$temp2.img" alt="$temp2.title" border="0" align="absmiddle" height="$temp2.imgheight"      width="$temp2.imgwidth" />
                        <pt:logic.value pt:value="$temp2.title" />
                             </pt:core.html>
                             </span>
                             </pt:logic.foreach>
    But the URL that is generated is not having the CommunityID, hence it errors out saying object not found.
    Any help would be appreciated?
    Thanks
    kartik

  • Jars in the class path of a custom component

    I am using the dom4j-1.6.1.jar library in a custom component, but my JBoss server has dom4j.jar in jboss\server\all\lib.  My custom component is throwing the following error:
    DefFoundError message:org/dom4j/xpath/DefaultXPath while invoking service XmlToCsvService and operation convert and no fault routes were found to be configured.
    This makes me suspect that the version of Dom4J in the lib directory of the server is taking precedence over the one in my component.  Any suggestions for how to deal with this?  Thanks.
    Jared Langdon

    Even Marcel's suggestion may not always work, but it certainly is worth a quick try.  I seem to remember trying that and finding that one of the LiveCycle EAR files has a version of dom4j buried inside it (I don't remember which version of LC it was).
    Of course altering an Adobe supplied EAR is not recommended and may violate your support ageement. There is an alternative, however; if changing the JBoss lib folder doesn't work.  To avoid the conflict you can use JarJar to rename the packages within the DOM4J class and deploy the renamed jar with your component to avoid the conflict.
    http://code.google.com/p/jarjar/
    You would then use the renamed classes in your component:
    import org.mypackage.dom4j.Document;
    import org.mypackage.dom4j.DocumentException;
    import org.mypackage.dom4j.DocumentHelper;
    import org.mypackage.dom4j.Element;
    import org.mypackage.dom4j.Node;
    import org.mypackage.dom4j.io.DOMReader;
    import org.mypackage.dom4j.io.DOMWriter;

  • How to resolve #{row} of af:table in custom tag class?

    Hi all,
    My customer creates custom converter tag with some attributes. When they use it outside af:table, it works as expected.
    However when they use it in af:table and set "#{row.value}" into the tag's attribute, it doesn't work because it can't resolve #{row} EL expression.
    The method they wrote is like below.
    private Object getExpressionValue(ValueExpression expression) {
    if (expression == null) {
    return null;
    final ELContext elContext =
    FacesContext.getCurrentInstance().getELContext();
    return expression.getValue(elContext);
    Does anyone know the way to do resolve #{row} expresison in custom tag class?
    If you share sample codes, it will be much appreciated.
    Regards,
    Atsushi

    Hi,
    the row variable is a temporary variables, which means that #{row} may work when the table renders but not when users edit fields in a table and then submit the change. You don't really mention what doesn't work for your customer (and wouldn't it be better your customer could post here on OTN to avoid you becoming a dispatcher?) . An expression #{row.value} for example doesn't exist unless your customer uses a POJO model that has a property "value" in which case the entity has a setValue/getValue.
    Frank

  • Building custom Component -- choice of base class...

    Hello,
    I am building a customer component. The component will be a AJAX enable Grid.
    I am not sure what base class would be the best.
    I am planning on using the "UIComponentTag" as the base class of my tag file. Here is the declaration:
    public class EbaAjaxGridTag extends UIComponentTag {
    Let me know how-you all feel about this choice.
    Cheers,
    Godfrey

    Yep, that's the right class. All JSF component tags inherit UIComponentTag (eventually in their hierarchy). I suppose there is UIComponentBodyTag, but you should make a custom renderer instead of writing the tag body from the tag class. In other words, you don't want UIComponentBodyTag.
    It would also be ok if you wanted to extend another component tag (i.e. InputTextTag). This would give you access to the pre-existing attributes of that tag class. HOWEVER, you should be warned that these tag classes can change in future versions of JSF. So make sure you are willing to maintain it in the future before doing that.
    CowKing

  • How do I tie a custom-component to a class?

    In flash there's this great way of seperating code from
    content: In the properties menu of a movieclip in your library, you
    can assign a class name to the movie. So something I very regularly
    do is:
    class MyMovieClip extends MovieClip{
    //etc..
    so I'd have all the code that manages my movies nicely tucked
    away in some .as files, no code in the fla. That's the way I like
    it.
    So I was wondering if you can do a similar thing in Flex. I
    most definitely don't want the code for my application in the .mxml
    file, I actually want to inherit the Application class. Similarly,
    I'd like to inherit the Canvas class, yet have the nice gui for
    dragging all the visuall elements in place. Is there a way?
    Regard, and thanks in advance,
    Karel

    If you look in the library panel, there should be an entry for your custom component - probably something like CustomComponent1.mxml. Drag this out onto the artboard to create a new instance of the component.
    In the case of a custom component, you can't change much on the second instance. If you have something like a text input skin though, you can change the text it is displaying for each instance.
    We are working on making this sort of thing easier in the future, so stay tuned

  • How to use a flex custom component in an AS3 Class?

    Our software team has been developing flash applications using AS3 (via the FlashDevelop IDE and the free Flex SDK).  Recently, some members of the team started exploring FlexBuilder and Flex (wow... why did we wait so long?).  The problem is that some folks continue to develop using pure Action Script 3 (FlashDevelop) while others are creating custom components in FlexBuilder.
    How do the AS3 developers use the Flex Custom components built in FlexBuilder in their AS3 Applications?

    SwapnilVJ,
    Your suggestions enabled me to make progress, but I'm still having a problem.  Based on you suggestion, I learned how to make a swc using Flex Builder.  I successfully added the swc to the lib resource in my AS3 project (FlashDevelop).  I was able to instantiate one of my new components (code hinting even picked it up from the lib).
    When I run my app, my component is not visible.  I can trace properties of it and the values are correct.  Any thought why I might not be seeing my custom component?
    package trainer.games.board.MatchThree {
    import flash.display.Sprite;
    public class Test extends Sprite{
      private var cp:MatchingGameControlPanel; // <<< this is my swc custom component created in Flex
      public function Test() {
       cp = new MatchingGameControlPanel();
       cp.visible = true;
       addChild(cp);
       trace("width: ",cp.width); // <<< works and displays valid data for the component.

  • LCES server caches the custom component classes

    I found that sometime during the (patching) deploy/undeploy install/uninstall phase of custom component LCES start 'caching the custom component or its helper classes' and any changes made to them does not get reflected.
    But after the server restarted every thing work as expected.
    i.e. If server is restarted the latest changes to component deployed previously to server restart get reflected.
    Pl. help.
    Any one had simillar issue?
    Thanks
    Yog

    Hi Paul,
    I have tried both of these frequently (many times)
    1) Component > STOP > PATCH > START
    2) Component > STOP > UNINSTALL > INSTALL > START
    but no effect after some point when server keeps the cache. (it works some time but not all the time I thought 2nd approach should always work)
    But if I restart the server it seems to show the expected result always.
    Does any Adobe teche knows how to gaurrentee 100% that chnges will reflect after new version of the component is installed without restart of the server.
    Also I seen some inside the service impl at the begining of the service method code store the classloader:
    ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader();
    and restore it at the end of service method:
    if (originalClassloader != null) {
    Thread.currentThread().setContextClassLoader(originalClassloader);
    How does this affect?
    and also if one component depends on another how does that affect?
    Thanks
    Yog

  • Error  "expected a myfaces custom component class in package"

    Can anybody help me on this?
    just copied the sandbox code on selectmanypicklist and tried in a separate package of mine.
    created a jsp page and used the selectmanypicklist component and im getting the component on my browser.
    But whn i added the javascript resource calling by "encodeJavascript(facesContext, uiComponent);" im geting an error saying tht "expected a myfaces custom component class in package org.apache.myfaces.custom". i placed the java script file in "mypackage/list/resource/pikscript.js".
    should i add anything on faces-config.xml file or anywhr else?
    Anybody can help on this?
    Thanx in Advance.

    The problem is that it calls a method validateCustomComponent in MyFacesResourceHandler to see if it can load the js file. This method controlls if the path of the js file begins with org.apache.myfaces.custom. If not throws an exception and doesn't load the file. I changed the package of the class that's trying to load the file in org.apache.myfaces.custom.xx and the package of the file js in org.apache.myfaces.custom.xx.resource. Now it's working.

  • Where to place tld,tag class files to create a small custom tag

    hi ,
    please any one help me to create a small custom plugin wothout using JSTL

    Your TLD will reside in the WEB-INF/ directory, whereas your tag class will be put into WEB-INF/classes/ directory, depending on your package it'll live in a directory somewhere under that. Of course, you could also put the TLD and tag class into a JAR file and place that under WEB-INF/lib/

  • Getting port no of UCM server in which custom component is installed

    Hi All,
    I have an requirement to get an port no of UCM server in which custom component is installed.
    Is there any way to get the port information using intradocBinder ?

    Try the following:
    SharedObjects.getEnvironmentValue("IntradocServerPort");
    http://jonathanhult.com/intradoc-api/intradoc/shared/SharedObjects.html
    Jonathan
    http://jonathanhult.com

  • Custom JSF Component tags ignored after converting to Facelets layout

    I am currently using JDeveloper 10.1.3.3.
    I have a project consisting of .jspx pages. These pages mainly use components from ADF faces core. I also created my own custom JSF component that I use in several of these pages.
    Then, I needed to use Facelets so that I could apply a standard layout to all my .jspx pages. I looked at all the tutorials, and I created a layout.xhtml for my .jspx pages to use. This worked great for my .jspx pages that don't have my custom JSF component.
    Now, when I run my page with my custom component <img:newimage ...etc >
    the tag is ignored and it appears in the page's source as is when it should render as <img.src=...etc>. Attributes of newimage are changed on the page appropriately like width and height, but my component's tag, component, and servlet java files are never accessed.
    How can I fix this? Please help!
    Thanks.

    Hi,
    did you post this issue to the Facelets open source site ? Sounds like an issue with using Facelets
    Frank

Maybe you are looking for