Announcement Announcement Module
Collapse
No announcement yet.
Share data beteween two Views Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Share data beteween two Views

    Hi,

    I want to share data between 2 Views. For exemple, I have a JList with some values in a fisrt View and I want that selected item of this JList were displayed in JList in a second View.
    To do that i use:
    list.addListSelectionListener(new ListSelectionListener(){

    public void valueChanged(ListSelectionEvent arg0) {
    getApplicationContext()
    .publishEvent(new LifecycleApplicationEvent("SELECTED_ITEM", listOnFisrtView.getSelectedValues()));

    }

    });
    and my second View implements ApplicationListener.

    public void onApplicationEvent(ApplicationEvent arg0) {
    LifecycleApplicationEvent event= (LifecycleApplicationEvent)arg0;
    if(event.getEventType().equals("SELECTED_ITEM")){
    listOnSecondView.removeAll();
    listOnSecondView.setListData((Object[])event.getSource());
    listOnSecondView.updateUI();
    }

    }


    The problem is that I must open the second view one time before making my selection. If i don't proceed like that, it doesn't work.

    Questions are:
    1) Is my solution the right way to what i want?
    2) Is it normal that all Views don't be instanciate and register with the applicationEventMulticaster at startup? How change that?
    3) I resolve my problem whit implementing a new applicationEventMulticaster

    public class CachedApplicationEventMultiCaster extends SimpleApplicationEventMulticaster
    {

    private Hashtable hTable = new Hashtable();

    public void multicastEvent(ApplicationEvent arg0) {

    if (arg0 instanceof LifecycleApplicationEvent ) {
    LifecycleApplicationEvent event = (LifecycleApplicationEvent) arg0;
    hTable.put(event.getEventType(), event.getSource());
    }
    super.multicastEvent(arg0);
    }

    public void addApplicationListener(ApplicationListener arg0) {
    super.addApplicationListener(arg0);
    Enumeration eventType = hTable.keys();
    Object type;
    while (eventType.hasMoreElements()) {
    type = eventType.nextElement();
    arg0.onApplicationEvent(new LifecycleApplicationEvent((String) type, hTable.get(type)));
    }
    }
    }

    Is someone have an other idea?
    Thanks
Working...
X