How to add listener attribute to component?
igorg May 27, 2010 4:26 AMI have new component, I've developed lately. It is day of week buttons with ability to select several days. Days selected are stored in value property as bit mask. Now, I try to add attribute named daySelectedListener. This attribute should call bean's action method when one of the days is clicked. There are some examples in richFaces source code, for example currentDateChangeListener of rich:calendar, but there is no explanations in richFaces CDK tutorial how to do it, besides list of the conventional names for methods and classes. I've tried to define daySelectedListener element. as it done in currentDateChangeListener attribute, but it doesn't works. The component is generated without errors, but when I try to add this attribute to component in test page I get following exception : "An error occurred at line: 25 in the jsp file: /testWeekDaysButtons.jsp $ cannot be resolved".
Debugging shows me that I have this lines in TLD for these two attributes( currentDateChangeListener and daySelectedListener):
:
<attribute> <description>MethodExpression representing an action listener method that will be notified after date selection</description> <name>currentDateChangeListener</name> <deferred-method> <method-signature>void currentDateChangeListener(org.richfaces.event.CurrentDateChangeEvent)</method-signature> </deferred-method> </attribute> <attribute> <description>MethodBinding representing an action listener method that will be notified after day clicked</description> <name>daySelectedListener</name> <deferred-method> <method-signature>void daySelectedListener(${prop.methodargs})</method-signature> </deferred-method> </attribute>
As you can see, method signature element for my attribute has wrong parameters definition, but I don't know what the reason. Is some body know what I do in wrong way, and how to define listener attribute correctly?
My way to define listener attribute:
1. Add attribute element to component XML :
<property> <name>daySelectedListener</name> <classname>javax.el.MethodExpression</classname> <description>MethodBinding representing an action listener method that will be notified after day clicked</description> </property>
2. Add listener element to component XML:
<listener> <name>daySelectedListener</name> <listenerclass>com.sintecmedia.components.event.DaySelectedListener</listenerclass> <componentclass>com.sintecmedia.components.component.UIWeekdaysButtons</componentclass> <eventclass>com.sintecmedia.components.event.DaySelectedEvent</eventclass> <taghandler generate="true"> <classname>com.sintecmedia.components.taglib.DaySelectedListenerTagHandler</classname> </taghandler> </listener>