javax.faces.event.ActionListener Java Examples

The following examples show how to use javax.faces.event.ActionListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsfActionHelper.java    From javamelody with Apache License 2.0 6 votes vote down vote up
static void initJsfActionListener() {
	// cette indirection entre FilterContext et JsfActionListener est probablement nécessaire pour la JVM IBM J9
	// afin de ne pas dépendre des classes FacesContext et ActionListenerImpl et afin de ne pas avoir de ClassNotFound dans J9
	try {
		final FacesContext facesContext = FacesContext.getCurrentInstance();
		if (facesContext != null && facesContext.getApplication() != null) {
			// ceci est a priori équivalent à l'ajout d'un action-listener dans WEB-INF/faces-config.xml de l'application :
			// <application><action-listener>net.bull.javamelody.JsfActionListener</action-listener></application>
			// et on ne peut pas avoir un fichier META-INF/faces-config.xml dans le jar de javamelody avec cet action-listener
			// car dans Apache MyFaces, cela ferait certainement une ClassNotFoundException rendant javamelody inutilisable
			final ActionListener delegateActionListener = facesContext.getApplication()
					.getActionListener();
			final JsfActionListener jsfActionListener = new JsfActionListener(
					delegateActionListener);
			facesContext.getApplication().setActionListener(jsfActionListener);
		}
	} catch (final Exception e) {
		// issue 204: initialisation du JsfActionListener échouée, tant pis, il n'y aura pas les statistiques pour JSF.
		// no stack-trace, because in JBoss 7 because in some cases the class com.sun.faces.application.ActionListenerImpl is available but the ApplicationFactory isn't (issue 393)
		LOG.info("initialization of jsf action listener failed, skipping");
	}
}
 
Example #2
Source File: JsfActionListener.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * Constructeur.
 * @param delegateActionListener ActionListener
 */
public JsfActionListener(ActionListener delegateActionListener) {
	super();
	// quand cet ActionListener est utilisé, le compteur est affiché
	// sauf si le paramètre displayed-counters dit le contraire
	JSF_COUNTER.setDisplayed(!COUNTER_HIDDEN);
	JSF_COUNTER.setUsed(true);
	LOG.debug("jsf action listener initialized");
	this.delegateActionListener = delegateActionListener;
}
 
Example #3
Source File: TestJsf.java    From javamelody with Apache License 2.0 5 votes vote down vote up
@Test
public void testInitJsfActionListener() throws NoSuchMethodException, SecurityException,
		InvocationTargetException, IllegalAccessException {
	final ServletContext servletContext = createNiceMock(ServletContext.class);
	expect(servletContext.getInitParameter("com.sun.faces.enableTransitionTimeNoOpFlash"))
			.andReturn(null).anyTimes();
	final Enumeration<String> initParameterNames = Collections.emptyEnumeration();
	expect(servletContext.getInitParameterNames()).andReturn(initParameterNames).anyTimes();
	replay(servletContext);
	final InitFacesContext facesContext = new InitFacesContext(servletContext);
	final Method setter = FacesContext.class.getDeclaredMethod("setCurrentInstance",
			FacesContext.class);
	setter.setAccessible(true);
	setter.invoke(null, facesContext);
	FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, AppFactory.class.getName());
	verify(servletContext);

	final ActionListener delegateActionListener = createNiceMock(ActionListener.class);
	FacesContext.getCurrentInstance().getApplication()
			.setActionListener(delegateActionListener);

	JsfActionHelper.initJsfActionListener();

	final UIComponent uiComponent = createNiceMock(UIComponent.class);
	final ActionEvent actionEvent = new ActionEvent(uiComponent);
	final ActionListener actionListener = FacesContext.getCurrentInstance().getApplication()
			.getActionListener();
	actionListener.processAction(actionEvent);
	MonitoringProxy.getJsfCounter().setDisplayed(false);
	actionListener.processAction(actionEvent);
	MonitoringProxy.getJsfCounter().setDisplayed(true);
}
 
Example #4
Source File: DeltaSpikeActionListener.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private ActionListener getWrappedActionListener()
{
    //TODO re-visit it
    //was:
    //SecurityViolationAwareActionListener securityViolationAwareActionListener =
    //        new SecurityViolationAwareActionListener(this.wrapped);

    return new ViewControllerActionListener(this.wrapped);
}
 
Example #5
Source File: FileAdapter.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
public ActionListener exportFile()
{
	return new FileDownloadActionListener();
}
 
Example #6
Source File: ExceptionActionListener.java    From development with Apache License 2.0 4 votes vote down vote up
public ExceptionActionListener(ActionListener delegate) {
    this.delegate = delegate;
}
 
Example #7
Source File: ApplicationStub.java    From development with Apache License 2.0 4 votes vote down vote up
@Override
public ActionListener getActionListener() {
    throw new UnsupportedOperationException();
}
 
Example #8
Source File: ApplicationStub.java    From development with Apache License 2.0 4 votes vote down vote up
@Override
public void setActionListener(ActionListener arg0) {
    throw new UnsupportedOperationException();
}
 
Example #9
Source File: BootsFacesAJAXActionListenerEvent.java    From BootsFaces-OSP with Apache License 2.0 4 votes vote down vote up
public BootsFacesAJAXActionListenerEvent(UIComponent component, String event, ActionListener l) {
	super(component);
	listener = l;
}
 
Example #10
Source File: AJAXRenderer.java    From BootsFaces-OSP with Apache License 2.0 4 votes vote down vote up
public static void generateBootsFacesAJAXAndJavaScript(FacesContext context, ClientBehaviorHolder component,
		ResponseWriter rw, String specialEvent, String specialEventHandler, boolean isJQueryCallback,
		boolean suppressAJAX) throws IOException {
	boolean generatedAJAXCall = false;
	Collection<String> eventNames = component.getEventNames();
	Map<String, String> jQueryEvents = ((IAJAXComponent) component).getJQueryEvents();
	if (null != eventNames) {
		for (String keyClientBehavior : eventNames) {
			if (null != jQueryEvents)
				if (jQueryEvents.containsKey(keyClientBehavior))
					continue;
			generatedAJAXCall |= generateAJAXCallForASingleEvent(context, component, rw, null, specialEvent,
					specialEventHandler, isJQueryCallback, keyClientBehavior, null, null);
		}
	}
	if (generatedAJAXCall) {
		assertComponentIsInsideForm((UIComponent)component, "Please put every component triggering AJAX in a form tag.", true);
	}
	if (!generatedAJAXCall) {
		// should we generate AJAX nonetheless?
		boolean ajax = ((IAJAXComponent) component).isAjax();
		ajax |= null != ((IAJAXComponent) component).getUpdate();

		if (ajax) {
			// before generating an AJAX default handler, check if there's an jQuery handler
			// that's generated later
			if (null != jQueryEvents) {
				Set<String> events = jQueryEvents.keySet();
				for (String event : events) {
					String nameOfGetter = "getOn" + event;
					try {
						Method[] methods = component.getClass().getMethods();
						for (Method m : methods) {
							if (m.getParameterTypes().length == 0) {
								if (m.getReturnType() == String.class) {
									if (m.getName().equalsIgnoreCase(nameOfGetter)) {
										String jsCallback = (String) m.invoke(component);
										if (jsCallback != null && jsCallback.contains(AJAX_EVENT_PREFIX)) {
											ajax = false;
										}
										break;
									}

								}
							}
						}
					} catch (Exception e) {

					}
				}
			}
			if (ajax) {
				assertComponentIsInsideForm((UIComponent)component, "Please put every component triggering AJAX in a form tag.", true);
				StringBuilder s = generateAJAXCallForClientBehavior(context, (IAJAXComponent) component,
						(ClientBehavior) null);
				String script = s.toString() + ";";
				String defaultEvent = ((IAJAXComponent) component).getDefaultEventName();
				if (component instanceof CommandButton)
					if (script.length() > 0 && "click".equals(defaultEvent))
						script += ";return false;";
				rw.writeAttribute("on" + defaultEvent, script, null);
			}
		} else if (component instanceof CommandButton) {
			encodeFormSubmit((UIComponent) component, rw, false);
		} else {
			// b:navCommandLink doesn't submit the form, so we need to use
			// AJAX
			boolean generateNonAJAXCommand = false;
			if (component instanceof ActionSource) {
				ActionSource b = (ActionSource) component;
				ActionListener[] actionListeners = b.getActionListeners();
				if (null != actionListeners && actionListeners.length > 0) {
					generateNonAJAXCommand = true;
				}
			}
			if (component instanceof ActionSource2) {
				MethodExpression actionExpression = ((ActionSource2) component).getActionExpression();
				if (null != actionExpression) {
					generateNonAJAXCommand = true;
				}
			}
			if (generateNonAJAXCommand && component instanceof IAJAXComponent) {
				assertComponentIsInsideForm((UIComponent)component, "Please put every component triggering AJAX in a form tag.", true);
				generateOnClickHandler(rw, (IAJAXComponent) component, suppressAJAX);
			}
		}
		// TODO: what about composite components?
	}
}
 
Example #11
Source File: DeltaSpikeActionListener.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor for wrapping the given {@link ActionListener}
 * @param wrapped action-listener which should be wrapped
 */
public DeltaSpikeActionListener(ActionListener wrapped)
{
    this.wrapped = wrapped;
    this.activated = ClassDeactivationUtils.isActivated(getClass());
}
 
Example #12
Source File: ViewControllerActionListener.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor for wrapping the given {@link ActionListener}
 * @param wrapped action-listener which should be wrapped
 */
public ViewControllerActionListener(ActionListener wrapped)
{
    this.wrapped = wrapped;
    this.activated = ClassDeactivationUtils.isActivated(getClass());
}
 
Example #13
Source File: ResetInputAjaxActionListener.java    From ctsms with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Construct a new reset input ajax action listener around the given wrapped action listener. This constructor
 * will be used when registering as <code>&lt;action-listener&gt;</code> in <code>faces-config.xml</code>.
 * @param wrapped The wrapped action listener.
 */
public ResetInputAjaxActionListener(ActionListener wrapped) {
	super(PhaseId.INVOKE_APPLICATION);
	this.wrapped = wrapped;
}