tags:

views:

248

answers:

3

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?

A: 

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.

Phill Sacre
So, when an event occurs you can run some code written which has access to the backing bean that could iterate through items on the page (backing bean) and possible do things to them, fire methods on them etc..? Cause that might work..
SCdF
A: 

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();>
mugafuga
A: 

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?

Priyank
WRT Ajax, At the time I was yeah. Basically we did a spike to look at using JSF as a component framework in an almost portal / portlet-like scenario. So we want components to 'publish' events that they consume and have other components produce those events, transparently without linking up components.
SCdF
http://blogs.sun.com/rlubke/entry/jsf_2_0_new_feature1Is this what you are looking for?
Priyank