Using JSF 2.0 / Facelets, is there a way to attach a global listener to all AJAX calls?

Is there a way to attach a global listener to all AJAX calls in JSF? Maybe through a phase listener or something? Yes, a PhaseListener can do it. A SystemEventListener also. A Filter also. If you’re inside JSF context, then you can check as follows whether the current request is an ajax request or not. … Read more

Add multiple window.onload events

Most of the “solutions” suggested are Microsoft-specific, or require bloated libraries. Here’s one good way. This works with W3C-compliant browsers and with Microsoft IE. if (window.addEventListener) // W3C standard { window.addEventListener(‘load’, myFunction, false); // NB **not** ‘onload’ } else if (window.attachEvent) // Microsoft { window.attachEvent(‘onload’, myFunction); }

What’s the difference between Event Listeners & Handlers in Java?

There’s no formally defined difference between listeners and handlers. Some people would probably argue that they are interchangeable. To me however, they have slightly different meaning. A listener is an object that subscribes for events from a source. Cf. the observer pattern. Usually you can have many listeners subscribing for each type of event, and … Read more

jquery resize listener on a div

As the thread poelinca provided suggests, there are some nice plugins available for this functionality. If you don’t like the plugin idea, another simple solution would be to simply trigger a “resize” event on the div whenever the content is modified. Then you could monitor it with resize() as expected, utilizing an elegant observer pattern. … Read more

Trace listener to write to a text box (WPF application)

I use this for C# winforms, should be easily adjustable to wpf public class MyTraceListener : TraceListener { private TextBoxBase output; public MyTraceListener(TextBoxBase output) { this.Name = “Trace”; this.output = output; } public override void Write(string message) { Action append = delegate() { output.AppendText(string.Format(“[{0}] “, DateTime.Now.ToString())); output.AppendText(message); }; if (output.InvokeRequired) { output.BeginInvoke(append); } else { … Read more

Android long-touch event

You may implement it as in the following code. package org.me.rapidchange; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnKeyListener; import android.view.View.OnTouchListener; import android.widget.Button; import android.widget.TextView; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; public class MainActivity extends Activity implements OnKeyListener, OnTouchListener, OnClickListener { private class … Read more

Creating a custom event listener on an Android app

Define a callback interface public interface NewsUpdateListener { void onNewsUpdate(<News data to be passed>); } Provide a registration facility on the background thread which gets the RSS feed class <Background processing class name> { …. ArrayList<NewsUpdateListener> listeners = new ArrayList<NewsUpdateListener> (); …. public void setOnNewsUpdateListener (NewsUpdateListener listener) { // Store the listener object this.listeners.add(listener); } … Read more

How can I remove a JavaScript event listener?

You need to use named functions. Also, the click variable needs to be outside the handler to increment. var click_count = 0; function myClick(event) { click_count++; if(click_count == 50) { // to remove canvas.removeEventListener(‘click’, myClick); } } // to add canvas.addEventListener(‘click’, myClick); You could close around the click_counter variable like this: var myClick = (function( … Read more

Attaching A Single Action Listener To All Buttons

Something like: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class CalculatorPanel extends JPanel { private JTextField display; public CalculatorPanel() { Action numberAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { display.setCaretPosition( display.getDocument().getLength() ); display.replaceSelection(e.getActionCommand()); } }; setLayout( new BorderLayout() ); display = new JTextField(); display.setEditable( false ); display.setHorizontalAlignment(JTextField.RIGHT); add(display, BorderLayout.NORTH); JPanel … Read more

tech