[Logo] OLD FORUM - Use new one: https://www.CaptainCasa.online/forum
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Modal Popup Auto Close  XML
Forum Index -> Development
Author Message
vadingding

Power User
[Avatar]

Joined: 14/07/2017 13:26:37
Messages: 145
Offline

Hi Captain,

I have a button in my modal popup with some codes that will insert data to the database.

And what I want is to write a code that will automatically close the popup after the insert statements..

Can you give me some hint on how to do that?

Thanks..
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5555
Offline

Hi,

I was astonished that I could not directly point you to an example of the demo workplace... - so we added one (available with this week's update, which will roll out somewhere today...).

Here is the code:

Calling Pagebean:
Code:
 package workplace;
 
 import java.io.Serializable;
 
 import org.eclnt.editor.annotations.CCGenClass;
 import org.eclnt.jsfserver.defaultscreens.ModalPopup;
 import org.eclnt.workplace.IWorkpageDispatcher;
 import org.eclnt.workplace.WorkpageDispatchedPageBean;
 
 @CCGenClass (expressionBase="#{d.DemoPageBeanPopupOpeningClosing}")
 
 public class DemoPageBeanPopupOpeningClosing
     extends DemoBasePageBean 
     implements Serializable
 {
     // ------------------------------------------------------------------------
     // constructors & initialization
     // ------------------------------------------------------------------------
 
     public DemoPageBeanPopupOpeningClosing(IWorkpageDispatcher workpageDispatcher)
     {
         super(workpageDispatcher);        
     }
 
     public String getPageName() { return "/workplace/demopagebeanpopupopeningclosing.jsp"; }
     public String getRootExpressionUsedInPage() { return "#{d.DemoPageBeanPopupOpeningClosing}"; }
 
     // ------------------------------------------------------------------------
     // public usage
     // ------------------------------------------------------------------------
 
     public void onOpenPopupAction(javax.faces.event.ActionEvent event) 
     {
         final DemoPageBeanPopupOpeningClosingPopup popupUI = new DemoPageBeanPopupOpeningClosingPopup();
         openModalPopup(popupUI,"A nice popup",0,0,new ModalPopup.IModalPopupListener()
         {
             public void reactOnPopupClosedByUser()
             {
                 closePopup(popupUI);
             }
         });
         popupUI.prepare(new DemoPageBeanPopupOpeningClosingPopup.IListener()
         {
             public void reactOnClosed()
             {
                 closePopup(popupUI);
             }
         });
     }
 
     // ------------------------------------------------------------------------
     // private usage
     // ------------------------------------------------------------------------
 }
 


Called PageBean:

Code:
 package workplace;
 
 import java.io.Serializable;
 
 import org.eclnt.editor.annotations.CCGenClass;
 import org.eclnt.jsfserver.pagebean.PageBean;
 
 @CCGenClass (expressionBase="#{d.DemoPageBeanPopupOpeningClosingPopup}")
 
 public class DemoPageBeanPopupOpeningClosingPopup
     extends PageBean 
     implements Serializable
 {
 
     // ------------------------------------------------------------------------
     // inner classes
     // ------------------------------------------------------------------------
 
     public interface IListener
     {
         public void reactOnClosed();
     }
 
     // ------------------------------------------------------------------------
     // members
     // ------------------------------------------------------------------------
 
     private IListener m_listener;
 
     // ------------------------------------------------------------------------
     // constructors & initialization
     // ------------------------------------------------------------------------
 
     public DemoPageBeanPopupOpeningClosingPopup()
     {
     }
 
     public String getPageName() { return "/workplace/demopagebeanpopupopeningclosingpopup.jsp"; }
     public String getRootExpressionUsedInPage() { return "#{d.DemoPageBeanPopupOpeningClosingPopup}"; }
 
     // ------------------------------------------------------------------------
     // public usage
     // ------------------------------------------------------------------------
 
     public void prepare(IListener listener)
     {
         m_listener = listener;
     }
 
     public void onCloseAction(javax.faces.event.ActionEvent event) 
     {
         if (m_listener != null)
             m_listener.reactOnClosed();
     }
 }
 


This demo shows the basic code to open - and to close a popup.

In principal it is very simple: a page bean is opened as popup, there is a corresponding openModalPopup-method and a closePopup-method. So it's just an issue to call these methods the right point of time.

The pattern used here is some kind of event-pattern. The page bean that is called as popup sends an event via its IListener-interface that something happened in the bean. In the example the page bean sends an event if the user pressed the Close-button. The calling bean registers for the event and closes the popup.

Regards, Björn

Björn Müller, CaptainCasa GmbH
vadingding

Power User
[Avatar]

Joined: 14/07/2017 13:26:37
Messages: 145
Offline

Thanks for the reply captain. Works like a charm.
 
Forum Index -> Development
Go to:   
Powered by JForum 2.1.6 © JForum Team