[ 
https://issues.jboss.org/browse/RF-12257?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12693691#comment-12693691
 ] 

Bernard Labno edited comment on RF-12257 at 5/17/12 10:32 AM:
--------------------------------------------------------------

This is how we defined listener in 3.x:
{code:xml}
<listener>
    <name>itemSelectListener</name>
    <property existintag="true" exist="true" el="true" elonly="true">
        <name>binding</name>
        <classname>org.richfaces.scheduleItemSelectListener</classname>
        <description>The attribute takes a value-binding expression for a 
component property of
                            a backing bean
        </description>
    </property>
    <listenerclass>
        org.richfaces.component.event.ScheduleItemSelectListener
    </listenerclass>
    <componentclass>
        org.richfaces.component.event.ScheduleListenerEventsProducer
    </componentclass>
    <eventclass>
        org.richfaces.component.event.ScheduleItemSelectEvent
    </eventclass>
    <taghandler generate="true">
        <classname>
                org.richfaces.taglib.ScheduleItemSelectListenerTagHandler
        </classname>
    </taghandler>
    <tag generate="true">
        <classname>
                org.richfaces.taglib.ItemSelectListenerTag
        </classname>
    </tag>

    <property existintag="true" exist="true" el="false">
        <name>type</name>
        <classname>java.lang.String</classname>
        <description>The fully qualified Java class name for the 
listener</description>
    </property>
</listener>{code}
 
This would result in following output:

{code:xml|title=Part of schedule.tld}
<tag>
        <name>itemSelectListener</name>
        <tag-class>org.richfaces.taglib.ItemSelectListenerTag</tag-class>
        <body-content>JSP</body-content>

        <attribute>
            <description>The attribute takes a value-binding expression for a 
component property of
                a backing bean
            </description>
            <name>binding</name>
            <deferred-value>
                <type>org.richfaces.scheduleItemSelectListener</type>
            </deferred-value>
        </attribute>
        <attribute>
            <description>The fully qualified Java class name for the 
listener</description>
            <name>type</name>
            <rtexprvalue>false</rtexprvalue>
            <type>java.lang.String</type>
        </attribute>

    </tag>{code}

{code:xml|title=Part of schedule.taglib.xml}
<tag>
        <tag-name>itemSelectListener</tag-name>
        <handler-class>
            org.richfaces.taglib.ScheduleItemSelectListenerTagHandler
        </handler-class>

    </tag>{code}


{code:java|title=ItemSelectListenerTag.java}
public class ItemSelectListenerTag extends TagSupport {

        private static final long serialVersionUID = -274448680242671987L;

        private String type;
        private String binding;

                // Fields
                                        

        public int doStartTag() throws JspException {

                UIComponentTag parentTag = UIComponentTag
                                .getParentUIComponentTag(pageContext);

                if (parentTag == null) {
                        throw new JspException(Messages.getMessage(
                                        
Messages.NO_UI_COMPONENT_TAG_ANCESTOR_ERROR, this
                                                        .getClass().getName()));
                }

                if (type == null && binding == null) {
                        throw new JspException("Either of the following 
attributes is "
                                        + "required: type binding");
                }

                // Process only newly created components
                if (parentTag.getCreated()) {

                        FacesContext context = 
FacesContext.getCurrentInstance();
                        Application application = context.getApplication();

                        
org.richfaces.component.event.ScheduleItemSelectListener listener = null;

                        UIComponent component = 
parentTag.getComponentInstance();

                        // First try to access listener binding
                        if (binding != null) {
                                ValueBinding valueBinding = application
                                                .createValueBinding(binding);

                                try {
                                        listener = 
(org.richfaces.component.event.ScheduleItemSelectListener) valueBinding
                                                        .getValue(context);
                                } catch (EvaluationException e) {
                                        throw new JspException(e);
                                }
                        }

                        // Then try to instantiate it by type attribute
                        if (listener == null) {

                                String className = null;

                                if (UIComponentTag.isValueReference(type)) {

                                        try {
                                                className = (String) 
application.createValueBinding(
                                                                
type).getValue(context);
                                        } catch (EvaluationException e) {
                                                throw new JspException(e);
                                        }

                                } else {
                                        className = type;
                                }

                                if (className == null) {
                                        throw new JspException("Type attribute 
resolved to null.");
                                }

                                try {
                                        listener = 
(org.richfaces.component.event.ScheduleItemSelectListener) 
Class.forName(className)
                                                        .newInstance();
                                } catch (Exception e) {
                                        throw new 
JspException(Messages.getMessage(
                                                        
Messages.INSTANTIATE_LISTENER_ERROR, className,
                                                        component.getId()), e);
                                }

                        }

                                                                                
                                        
                        // If listener was found/created, append it to component
                        if (listener != null) {
                                
((org.richfaces.component.event.ScheduleListenerEventsProducer) component)
                                                
.addItemSelectListener(listener);
                        }


                }

                return SKIP_BODY;
        }

        public String getType() {
                return type;
        }

        public void setType(String type) {
                this.type = type;
        }

        public String getBinding() {
                return binding;
        }

        public void setBinding(String binding) {
                this.binding = binding;
        }

        public void release() {
                type = null;
                binding = null;
                                                                }


}{code}


{code:java|title=ScheduleItemSelectListenerTagHandler.java}
public class ScheduleItemSelectListenerTagHandler extends TagHandler {

        private Class listenerType;

    private final TagAttribute type;

    private final TagAttribute binding;

        public ScheduleItemSelectListenerTagHandler(TagConfig config) {
            super(config);
                this.binding = this.getAttribute("binding");
        this.type = this.getAttribute("type");
        if (type != null) {
            if (!type.isLiteral()) {
                throw new TagAttributeException(this.tag, this.type, "Must be 
literal");
            }
            try {
                this.listenerType = Class.forName(type.getValue());
            } catch (Exception e) {
                throw new TagAttributeException(this.tag, this.type, e);
            }
        }
        }

         public void apply(FaceletContext ctx, UIComponent parent)
            throws IOException, FacesException, FaceletException, ELException {
        if (parent instanceof 
org.richfaces.component.event.ScheduleListenerEventsProducer) {
            // only process if parent was just created
            if (parent.getParent() == null) {
                org.richfaces.component.event.ScheduleListenerEventsProducer 
src = (org.richfaces.component.event.ScheduleListenerEventsProducer) parent;
                org.richfaces.component.event.ScheduleItemSelectListener 
listener = null;
                ValueExpression ve = null;
                if (this.binding != null) {
                    ve = this.binding.getValueExpression(ctx,
                            
org.richfaces.component.event.ScheduleItemSelectListener.class);
                    listener = 
(org.richfaces.component.event.ScheduleItemSelectListener) ve.getValue(ctx);
                }
                if (listener == null) {
                    try {
                        listener = 
(org.richfaces.component.event.ScheduleItemSelectListener) 
listenerType.newInstance();
                    } catch (Exception e) {
                        throw new TagAttributeException(this.tag, this.type, 
e.getCause());
                    }
                    if (ve != null) {
                        ve.setValue(ctx, ve);
                    }
                }
                                                                                
                                                                                
                src.addItemSelectListener(listener);
            }
        } else {
            throw new TagException(this.tag,
                    "Parent is not of type 
org.richfaces.component.event.ScheduleListenerEventsProducer, type is: " + 
parent);
        }
    }
        
}{code}
                
      was (Author: blabno):
    This is how we defined listener in 3.x:
<listener>
    <name>itemSelectListener</name>
    <property existintag="true" exist="true" el="true" elonly="true">
        <name>binding</name>
        <classname>org.richfaces.scheduleItemSelectListener</classname>
        <description>The attribute takes a value-binding expression for a 
component property of
                            a backing bean
        </description>
    </property>
    <listenerclass>
        org.richfaces.component.event.ScheduleItemSelectListener
    </listenerclass>
    <componentclass>
        org.richfaces.component.event.ScheduleListenerEventsProducer
    </componentclass>
    <eventclass>
        org.richfaces.component.event.ScheduleItemSelectEvent
    </eventclass>
    <taghandler generate="true">
        <classname>
                org.richfaces.taglib.ScheduleItemSelectListenerTagHandler
        </classname>
    </taghandler>
    <tag generate="true">
        <classname>
                org.richfaces.taglib.ItemSelectListenerTag
        </classname>
    </tag>

    <property existintag="true" exist="true" el="false">
        <name>type</name>
        <classname>java.lang.String</classname>
        <description>The fully qualified Java class name for the 
listener</description>
    </property>
</listener>
 
This would result in following output:

{code:title:Part of schedule.tld|borderStyle=solid}
<tag>
        <name>itemSelectListener</name>
        <tag-class>org.richfaces.taglib.ItemSelectListenerTag</tag-class>
        <body-content>JSP</body-content>

        <attribute>
            <description>The attribute takes a value-binding expression for a 
component property of
                a backing bean
            </description>
            <name>binding</name>
            <deferred-value>
                <type>org.richfaces.scheduleItemSelectListener</type>
            </deferred-value>
        </attribute>
        <attribute>
            <description>The fully qualified Java class name for the 
listener</description>
            <name>type</name>
            <rtexprvalue>false</rtexprvalue>
            <type>java.lang.String</type>
        </attribute>

    </tag>{code}


{code:title:Part of schedule.taglib.xml|borderStyle=solid}
<tag>
        <tag-name>itemSelectListener</tag-name>
        <handler-class>
            org.richfaces.taglib.ScheduleItemSelectListenerTagHandler
        </handler-class>

    </tag>{code}

{code:title:ItemSelectListenerTag.java|borderStyle=solid}
public class ItemSelectListenerTag extends TagSupport {

        private static final long serialVersionUID = -274448680242671987L;

        private String type;
        private String binding;

                // Fields
                                        

        public int doStartTag() throws JspException {

                UIComponentTag parentTag = UIComponentTag
                                .getParentUIComponentTag(pageContext);

                if (parentTag == null) {
                        throw new JspException(Messages.getMessage(
                                        
Messages.NO_UI_COMPONENT_TAG_ANCESTOR_ERROR, this
                                                        .getClass().getName()));
                }

                if (type == null && binding == null) {
                        throw new JspException("Either of the following 
attributes is "
                                        + "required: type binding");
                }

                // Process only newly created components
                if (parentTag.getCreated()) {

                        FacesContext context = 
FacesContext.getCurrentInstance();
                        Application application = context.getApplication();

                        
org.richfaces.component.event.ScheduleItemSelectListener listener = null;

                        UIComponent component = 
parentTag.getComponentInstance();

                        // First try to access listener binding
                        if (binding != null) {
                                ValueBinding valueBinding = application
                                                .createValueBinding(binding);

                                try {
                                        listener = 
(org.richfaces.component.event.ScheduleItemSelectListener) valueBinding
                                                        .getValue(context);
                                } catch (EvaluationException e) {
                                        throw new JspException(e);
                                }
                        }

                        // Then try to instantiate it by type attribute
                        if (listener == null) {

                                String className = null;

                                if (UIComponentTag.isValueReference(type)) {

                                        try {
                                                className = (String) 
application.createValueBinding(
                                                                
type).getValue(context);
                                        } catch (EvaluationException e) {
                                                throw new JspException(e);
                                        }

                                } else {
                                        className = type;
                                }

                                if (className == null) {
                                        throw new JspException("Type attribute 
resolved to null.");
                                }

                                try {
                                        listener = 
(org.richfaces.component.event.ScheduleItemSelectListener) 
Class.forName(className)
                                                        .newInstance();
                                } catch (Exception e) {
                                        throw new 
JspException(Messages.getMessage(
                                                        
Messages.INSTANTIATE_LISTENER_ERROR, className,
                                                        component.getId()), e);
                                }

                        }

                                                                                
                                        
                        // If listener was found/created, append it to component
                        if (listener != null) {
                                
((org.richfaces.component.event.ScheduleListenerEventsProducer) component)
                                                
.addItemSelectListener(listener);
                        }


                }

                return SKIP_BODY;
        }

        public String getType() {
                return type;
        }

        public void setType(String type) {
                this.type = type;
        }

        public String getBinding() {
                return binding;
        }

        public void setBinding(String binding) {
                this.binding = binding;
        }

        public void release() {
                type = null;
                binding = null;
                                                                }


}{code}


{code:title=ScheduleItemSelectListenerTagHandler.java|borderStyle=solid}
public class ScheduleItemSelectListenerTagHandler extends TagHandler {

        private Class listenerType;

    private final TagAttribute type;

    private final TagAttribute binding;

        public ScheduleItemSelectListenerTagHandler(TagConfig config) {
            super(config);
                this.binding = this.getAttribute("binding");
        this.type = this.getAttribute("type");
        if (type != null) {
            if (!type.isLiteral()) {
                throw new TagAttributeException(this.tag, this.type, "Must be 
literal");
            }
            try {
                this.listenerType = Class.forName(type.getValue());
            } catch (Exception e) {
                throw new TagAttributeException(this.tag, this.type, e);
            }
        }
        }

         public void apply(FaceletContext ctx, UIComponent parent)
            throws IOException, FacesException, FaceletException, ELException {
        if (parent instanceof 
org.richfaces.component.event.ScheduleListenerEventsProducer) {
            // only process if parent was just created
            if (parent.getParent() == null) {
                org.richfaces.component.event.ScheduleListenerEventsProducer 
src = (org.richfaces.component.event.ScheduleListenerEventsProducer) parent;
                org.richfaces.component.event.ScheduleItemSelectListener 
listener = null;
                ValueExpression ve = null;
                if (this.binding != null) {
                    ve = this.binding.getValueExpression(ctx,
                            
org.richfaces.component.event.ScheduleItemSelectListener.class);
                    listener = 
(org.richfaces.component.event.ScheduleItemSelectListener) ve.getValue(ctx);
                }
                if (listener == null) {
                    try {
                        listener = 
(org.richfaces.component.event.ScheduleItemSelectListener) 
listenerType.newInstance();
                    } catch (Exception e) {
                        throw new TagAttributeException(this.tag, this.type, 
e.getCause());
                    }
                    if (ve != null) {
                        ve.setValue(ctx, ve);
                    }
                }
                                                                                
                                                                                
                src.addItemSelectListener(listener);
            }
        } else {
            throw new TagException(this.tag,
                    "Parent is not of type 
org.richfaces.component.event.ScheduleListenerEventsProducer, type is: " + 
parent);
        }
    }
        
}{code}
                  
> CDK: generating listener tags
> -----------------------------
>
>                 Key: RF-12257
>                 URL: https://issues.jboss.org/browse/RF-12257
>             Project: RichFaces
>          Issue Type: Feature Request
>      Security Level: Public(Everyone can see) 
>          Components: cdk
>    Affects Versions: 4.2.0.Final
>            Reporter: Bernard Labno
>            Priority: Minor
>             Fix For: 4.3-Tracking
>
>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        
_______________________________________________
richfaces-issues mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/richfaces-issues

Reply via email to