SCdF
SCdF

Reputation: 59428

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

Here's the sit:

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?

Upvotes: 2

Views: 700

Answers (3)

Priyank
Priyank

Reputation: 14387

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?

Upvotes: 1

branchgabriel
branchgabriel

Reputation: 4251

ValueChangeEvent

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();

        doDocViewer1DisplayMethod(selectedDocument);
                doDocViewe2DisplayMethod(selectedDocument);


    }   

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

 <f:componentTag 
   attr=xxx 
   attr=xxx 
   valueChangeListener="#{pc_BackingBean.handleDocumentSelect}"
   onChange=submit();>

Upvotes: 0

user7094
user7094

Reputation:

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.

Upvotes: 1

Related Questions