public boolean addEventListener(String evtnm, EventListener<? extends Event> listener) { if (evtnm == null || listener == null) throw new IllegalArgumentException("null"); if (!Events.isValid(evtnm)) throw new IllegalArgumentException("Invalid event name: " + evtnm); if (_listeners == null) _listeners = new HashMap<String, List<EventListener<? extends Event>>>(2); List<EventListener<? extends Event>> l = _listeners.get(evtnm); if (l != null) { if (duplicateListenerIgnored()) { for (EventListener<? extends Event> li : l) { if (listener.equals(li)) return false; } } } else { _listeners.put(evtnm, l = new LinkedList<EventListener<? extends Event>>()); } l.add(listener); return true; }
/** * A convenient method that help you remove this event listener from the * specified target component. This is a counter method of the {@link #bindComponent(Component)} * method. * * @param comp the target component to remove this event listener. * @since 3.6.3 */ public void unbindComponent(Component comp) { final Method[] metds = getController().getClass().getMethods(); for (int i = 0; i < metds.length; i++) { final String evtnm = metds[i].getName(); if (Events.isValid(evtnm)) comp.removeEventListener(evtnm, this); } }
/** * A convenient method that help you register this event listener * to the specified target component. * * <p>All public methods whose names start with "on" are considered * as event handlers and the corresponding event is listened. * For example, if the derived class has a method named onOK, * then the onOK event is listened and the onOK method is called * when the event is received. * * @param comp the target component to register this event listener. */ public void bindComponent(Component comp) { final Method[] metds = getController().getClass().getMethods(); for (int i = 0; i < metds.length; i++) { final String evtnm = metds[i].getName(); if (Events.isValid(evtnm)) comp.addEventListener(evtnm, this); } }
/** * Applies the forward condition to the specified component. * * <p>The basic format:<br/> * <code>onEvent1=id1/id2.onEvent2,onEvent3=id3.onEvent4</code> * * <p>See {@link org.zkoss.zk.ui.metainfo.ComponentInfo#setForward} * for more information. * * @since 3.0.0 */ public static final void applyForward(Component comp, String forward) { if (forward == null) return; final Map<String, Collection<String>> fwds = new LinkedHashMap<String, Collection<String>>(); //remain the order Maps.parseMultiple(fwds, forward, ',', '\'', true, true); for (Map.Entry<String, Collection<String>> me : fwds.entrySet()) { final String orgEvent = me.getKey(); if (orgEvent != null && !Events.isValid(orgEvent)) throw new UiException("Not an event name: " + orgEvent); final Collection<String> conds = me.getValue(); for (String cond : conds) applyForward0(comp, orgEvent, cond); } }
public boolean parse(Attribute attr, ComponentInfo compInfo, PageDefinition pgdef) throws Exception { if (!(compInfo instanceof NativeInfo) && "".equals(attr.getNamespaceURI())) return false; // not what we care. final String name = attr.getLocalName(); final String value = attr.getValue(); if (Events.isValid(name)) { if (value.startsWith("@command(")) { final String subValue = value.substring(9, value.lastIndexOf(')')); final String[] strings = subValue.split(","); addAttribute(compInfo, attr, name, String.format(SCRIPT, "postCommand", Strings.join(strings))); return true; } else if (value.startsWith("@global-command(")) { final String subValue = value.substring(16, value.lastIndexOf(')')); final String[] strings = subValue.split(","); addAttribute(compInfo, attr, name, String.format(SCRIPT, "postGlobalCommand", Strings.join(strings))); return true; } } return false; }
final Method md = mtds[j]; String mdname = md.getName(); if (mdname.length() >= 5 && Events.isValid(mdname)) { //onX$Y Component xcomp = comp; int k = 0;
if (orgEvent == null) orgEvent = "onClick"; else if (!Events.isValid(orgEvent)) throw new IllegalArgumentException("Illegal event name: " + orgEvent); if (targetEvent == null) targetEvent = orgEvent; else if (!Events.isValid(targetEvent)) throw new IllegalArgumentException("Illegal event name: " + targetEvent);
public boolean addEventListener(int priority, String evtnm, EventListener<? extends Event> listener) { if (evtnm == null || listener == null) throw new IllegalArgumentException("null"); if (!Events.isValid(evtnm)) throw new IllegalArgumentException("Invalid event name: " + evtnm);
if (!Events.isValid(evtnm)) throw new UiException("Not an event name: " + evtnm); return new Object[] { target, evtnm };
if (Events.isValid(name)) { boolean bZkAttr = attrns == null; if (!bZkAttr) {
el.getAttributeValue("unless")); if (elFound != null) { if (Events.isValid(attnm)) throw new UiException(message("<" + elFound + "> not allowed in an event listener", el));