0

Property bind in zul view not happening when event registered by eventlistner is called and changes the property of view model

asked 2019-12-14 23:20:16 +0800

Pramil gravatar image Pramil
1 2

updated 2019-12-15 03:18:04 +0800

I am new zk framework. In my zul file there is a notification count indicator, which is a property of view model and indicates the notification count. When I click on notification indicator it opens a toggle window containing notifications. Here I want to implement that when I read a notification , the count will be reduced by one.

    <div class="notification_popup"
         viewModel="@id('vm') @init('com.stoneriver.portal.zk.viewmodels.ViewAnnouncementViewModel')">
        <a sclass="activity-dropdown" id="announcement_notification" iconSclass="z-icon-bell" popup="ann_notification,position=after_end,type=toggle" tooltiptext="Notifications">
         <span class="num"><label value="@bind(vm.announcementCount)"/></span></a>
        <popup id="ann_notification" class="header-top-dropdown notification-dropdown">
            <vlayout id="vl" sclass="notify-popup">
            </vlayout>
        </popup>
    </div>
@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class)
public class ViewAnnouncementViewModel {

    private long announcementCount = 0; 
    @NotifyChange({".", "announcementCount"})
    public void setAnnouncementCount(long announcementCount) {
        this.announcementCount = announcementCount;
    }

    @SuppressWarnings("unchecked")
    @AfterCompose
    public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
    super.afterCompose(view);
    Selectors.wireComponents(view,this,false);
    Html h1 = new Html();
    h1.setContent("<h4>Notifications</h4>");
    vl.appendChild(h1);
    div = new Div();
    div.setId("announcementList");
        div = updateAnnouncement(div);  
        vl.appendChild(div);    
      }

    public Div updateAnnouncement(Div div){

        private Collection<AnnouncementResultDTO> searchResults = 
          announcementService.retrieveAnnouncement(instanceInfo);       
        announcementCount = searchResults.size();

        setAnnouncementCount(announcementCount);
    postNotifyChange(this,"announcementCount"); 

        for(final AnnouncementResultDTO pasrDTO:searchResults){
        A s1 = new A();
        Label l1 = new Label();         
        l1.setValue("Annoncements");            
        s1.appendChild(l1);
        div.appendChild(s1);
        s1.addEventListener("onClick", new EventListener() {
                 public void onEvent(Event event) throws Exception {
                    Map<String, Object> map = new HashMap<String,Object>();
                    announcementCount=announcementCount-1;
                    setAnnouncementCount(announcementCount);
                    postNotifyChange(this,"*");
                    Window window = (Window) Executions.getCurrent().createComponents("announcement_popup.zul",null,map);
                    window.doModal();
                }                
          });   
   }

}

But announcementCount is reducing when event fires but it is not reflected in view model. I think the problem is that if we debug and try to find the value 'this', it will contain object with two inner object , one is view model. Here we can understand that postnotify method receives not a view model, but a wrapper class. I dont know my assumption is true. Please help me

delete flag offensive retag edit

1 Answer

Sort by » oldest newest most voted
0
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2019-12-14 23:20:16 +0800

Seen: 10 times

Last updated: Dec 16 '19

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More