How do I have multiple components respond to a single event in JSF?

Here's the sit:

  • I have a JSF component which is basically a list of 'documents'
  • I have any number of document viewer components on the same page.
  • None of these components "know" about each other. In other words, they cannot be configured at design time to link to each other or anything like that.

When the user clicks a document link I wish each one of the document viewer components to be notified.

Basically the idea would be to have the document viewers publish the fact that they listen for a certain type of event ("DocumentSelectedEvent" say) which the doc list component would fire.

I can think of ways of doing this that are not JSF specific, but I'm wondering if the JSF event model can handle that sort of thing.

Anyone have any ideas?

Asked by: Michelle898 | Posted: 23-01-2022

Answer 1

I don't think there's a way of doing that with the standard JSF event model.

Is there any way you can bind the components to a backing bean? That way when an event happens you can just go through your list of components and notify each of them.

Answered by: Tess851 | Posted: 24-02-2022

Answer 2

You need to just bind the components with a backing bean and use a ValueChangeListener to notify the backing bean. The listener method could change the state of the other components which are tied to respective UI components.

Are you trying to do it in a "Ajax" way without page being explicitly submitted?

Answered by: Arthur460 | Posted: 24-02-2022

Answer 3


I do not know how you implemented your document list but if it were say a dropdown or any other multi item list component you can do an Value Change Event and force a submit on change for the component. Then in the page code backing bean you can call the methods for your viewers to load whatever you like.

In your jsf you just specify the value change handler you wrote in the backing bean.

     * Handle document click value change.
     * @param valueChangedEvent the value changed event
    public void handleDocumentSelect(ValueChangeEvent valueChangedEvent) {
        String selectedDocument = valueChangedEvent.getNewValue();



Modify your jsf tag to use your new value change event handler and force the submit.


Answered by: Rafael351 | Posted: 24-02-2022

Similar questions

java - Multiple Components in a JTree Node Renderer & Node Editor

I am attempting to create a JTree where a node has several components: a JPanel that holds a JCheckBox, followed by a JLabel, then a JComboBox. I have attached the code at the bottom if one wishes to run it. Fortunately the JTree correctly renders the components. However when I click on the JComboBox, the node disappears; if I click on the JCheckBox, it works fine. It seems that I am doing something wrong with how the Tree...

java - laying out a jpanel with multiple custom components using swing

I'm trying to set up a JPanel using a BorderLayout in such a way to create a chart. For this, I have an axis component in the west &amp; south regions and the chart itself in the center region. The problem is.. when I add my 'graph' component (basic class extending Component) and draw things onto it, this overlaps with the other axis areas. I'm wondering how I can set things up in such a way that the reference for ...

java - Is this the proper way to overlay multiple components in one panel?

I'm trying to overlay a custom transparency over the top of a JPanel. I want both components to extend to the edge of the layered pane. I have overridden the paintComponent method of the top component to generally do nothing except when I want to display an overlay. Then it draws the appropriate text in the appropriate location. Here is my solution for the layout problem:

java - Use event in multiple different components

I have a JscrollPane which holds a JPanel on which I draw. I would like to use the MouseWheelEvent to: zoom the (with CTRL+Wheel) Panel content and to scroll the scrollpane (with just the wheel) Each action by itself works, but I dont't manage to make both work. As soon as I add a MouseWheelListener to the JPanel, the event does not arrive at the JScrollPanels listner. How ca...

java - Testing multiple JavaFX components using JemmyFX

I am working on a fairly large project which includes a set of custom JavaFX components. For each custom component which is meant to be reused, I have started to write a set of automated tests using JemmyFX and JUnit. During development, I run these from inside Eclipse Juno. Running the entire suite of tests at once has proven difficult. The problem seems to stem from the fact since I want to test multiple componen...

java - Jframe. Cant get multiple components to display

I am having trouble getting two different components to display at the same time. public class BandViewer { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(1000, 800); frame.setTitle("band"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BandComponent component = new BandComponent(); ConcertBackground component1 = new Co...

swing - Java - Multiple components above the other (GUI)

I want to make a JFrame with multiple components above the other - it should look like this: Everything centered GridLayout scrollable (if x is a huge number) What Layout should I use? How do I keep it as minimal as possible? Thanks in advance!

Java Swing Components Drawing Over Multiple Panels

I'm having an issue that I've been trying to solve all day. I have two panels inside a frame and in one panel I've added components. The components, however, seem to have an equal hierarchy value as the panel and as such treat the Frame as the parent instead, ignoring where the panels are located. Basically the components are added to one panel but display on top of both across the whole frame. (Unfortunately I can't post ...

java - Swing: JList holding multiple Components as a single item

Here is my problem: I'm creating a window that is responsible for listing a layer, where it displays the layer's current image (in the form of a ImageIcon as of now), layer's name, and a check box to alter the current on/off state of said layer. The entire thing is supposed to be a knock-off of Paint.NET's Layer Window

java - Layer multiple components in JFrame

I am currently creating a platformer game with classes Level and Robot. The classes are incomplete, but here is the basic structure: /** * @(#) * * Robot application * * @author * @version 1.00 2015/5/15 */ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Toolkit; import javax.swing.JComponent; import javax.swing.JFrame; public class Robot exte...

java - Swing components : vertical text question

If I have a button like the one in this image : how could I make the text display itself vertically ? As in j B u t t o n 1 I would like to know how to do the same thing for JLabel . I'm sure there has to be a better...

java - Do I need to free Swing components before letting them get garbage collected?

Wnen I use external resources such as files or DB connection I need to close them before I let them go. Do I need to do the same thing with Swing components ? If yes then how ?

user interface - Java GUI Creating Components

I hope it is correct term-wise to say that components in a GUI is like JButton, JPanel, JTextField, all that good stuff. I want to create a text field that takes in an integer. Then a submit button can be pressed and based on the integer that was inputted, create that many textfields in a popup window or whatever. I have no clue, could someone get me started in the right direction? The trouble I'm h...

swing - Java get JPanel Components

I have a JPanel full of JTextFields... for (int i=0; i&lt;maxPoints; i++) { JTextField textField = new JTextField(); points.add(textField); } How do I later get the JTextFields in that JPanel? Like if I want their values with TextField.getText(); Thanks

JAVA Swing GUI Components howto RTL view?

How can i make my Java Swing GUI Components [Right To Left] for Arabic language from NetBeans Desktop Application?

user interface - Java: How do you style Swing components?

I'm writing my first Java project. I was wondering if it's possible to style the Swing components (set a background color, remove the borders from the buttons, etc.)

java - Swing components inside HTML

Does anybody know of a pure java (ar at least cross platform) open source component/library which displays HTML which can contain swing components inside it? All I could find were either abandoned or incomplete. I am asking because I'm thinking about trying out approach to do use this combination for creating desktop application. EDIT:Seems like this question is missunderstood, so let me clarify it....

user interface - Correct way to use Actions to create menus, toolbars, and other components in Java

The naive way of writing building a menu in a Java Swing app is to do something like: JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open..."); openItem.addActionListener(new ActionListener() { /* action listener stuff */ } ) fileMenu.addMenuItem(openItem); A more experienced developer will recognize that actions can be accessed through a variety of mechanisms - me...

java - ADF Custom Components

Where is the best place to find custom compnonents? Ideally a repository, as opposed to finding a few here and there. We are currently about to re-design our look and feel UI for about 200 forms and we were hoping to find a lot of custom components... We were told they were everywhere by the pre-sales architect but even a simple

java - Testing EJB 3.0 components

I've got a couple of questions concerning the integrated testing EJB 3.0 components using JUnit. In your JUnit tests you can inject to session beans resource-local entity managers and therefore "simulate" ejb-container. But what if... What if you need to test if transaction attributes on your ejb methods are handled properly? Can this be done outside the container? If not, what is the simplest way...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)