[Logo] Enterprise Client Community
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Wait for pop-up  XML
Forum Index -> Development
Author Message
kklasen

Power User

Joined: 19/11/2020 08:33:30
Messages: 66
Offline

hello all and especially Björn,

I have a new stupid question.

I have made a popup where you can select a value in a Combo box and this value is written to a list. This popup should appear as long some values left.

Always when I try to make a loop or wait() for the next value. I get an infinite loop or nothing happens. I think the problem is that the server does not know what the client does or the other way around!

How I cane make a working break?

kind regards

Klas

kklasen

Power User

Joined: 19/11/2020 08:33:30
Messages: 66
Offline

Some Code of pop-up

Code:
 
 		// ------Pop-up-Choice------
 		List<Integer> runner = new ArrayList<>();
 		m_closeCount = 0;
 		for (String split : cData) {
 			String[] ad = split.split(" : ");
 //			int lSize = cData.size();
 
 			String check0 = ad[0]; // number for different
 
 			if (!check0.contentEquals(check1)) {
 
 				runner.add(Integer.parseInt(check0));
 				Statusbar.outputAlert(" Main excelReader popup " + runner);
 
 			}
 			check1 = check0;
 
 			// size of unique value
 //			int rSize = runner.size();
 
 //			while(m_closeCount <= rSize) {
 			// ----Thread-for Pop-up---
 				ChoicePopupExel cpe = new ChoicePopupExel(m_closeCount);
 				Thread t8 = new Thread(cpe);
 	//			cpe.run();
 				t8.start();
 				cpe.popupStart();
 				
 				try {
 	//				t1.wait();
 	//						Statusbar.outputAlert("size of ListArray: " + lSize);
 					t8.join();
 	//				t1.notifyAll();
 				} catch (InterruptedException e) {
 					Statusbar.outputAlert("Fehler beim Beenden des Threads " + e);
 					e.printStackTrace();
 				}
 			
 //			}
 
 		}
 
 



kklasen

Power User

Joined: 19/11/2020 08:33:30
Messages: 66
Offline

second part of code:

Code:
 
 	private class ChoicePopupExel implements Runnable {
 		int clCount;
 		public ChoicePopupExel(int closeCount) {
 			super();
 			clCount = closeCount;
 			
 		}
 
 		private synchronized int popupStart() {
 			PopupComboxExcelUI bean = new PopupComboxExcelUI();
 			
 
 			if (m_modPopup != null)
 				return 0;
 			m_modPopup = openModalPopup(bean, "Auswahlbereich", 300, 200, new ModalPopup.IModalPopupListener() {
 				
 				
 
 				@Override
 				public void reactOnPopupClosedByUser() {
 					BaseCloseReact(bean);
 
 				}
 			});
 			m_modPopup.setLeftTopReferenceComponentIdCentered(m_content);
 
 
 			m_modPopup.hideCloseIcon();
 			m_modPopup.hideMaximizeIcon();
 
 			bean.prepare(new managedbeans.PopupComboxExcelUI.IListener() {
 
 				@Override
 				public void onClosePopup() {
 
 					BaseCloseReact(bean);
 
 					clCount = clCount + 1;
 				}
 
 			});
 			return clCount;
 
 
 		}
 
 		private void BaseCloseReact(PopupComboxExcelUI bean) {
 
 			if (m_modPopup != null) {
 				closePopup(bean);
 				m_modPopup = null;
 			}
 
 		}
 
 		@Override
 		public void run() {
 
 			popupStart();
 
 		}
 	}
 
 


I hope it is readable

thank you in advance

CaptainCasa

Power User
[Avatar]

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

(EDIT: haven't seen you subsequent post - they arrived while I was hacking into the keyboard...)

Hi Klas,

a popup is opened by a PageBean "Opener":

Code:
 public class Opener
 {
 
     public void onXyzAction(ActionEvent event)
     {
         final MyPopupUI ui = new MyPopup();
         ui.prepare(.....);
         openModalPopup(ui);
     }
 }
 


The opener is responsible for closing the popup - when adequate. So there is typically a listener-interface in the opened page (here: MyPopupUI) that tells the opener an event so that this one knows: I can close the popup!

Example:

Code:
 public class Opener
 {
 
     public void onXyzAction(ActionEvent event)
     {
         final MyPopupUI ui = new MyPopup();
         ui.prepare(....., new MyPopup.IListener()
         {
             public void reactOnAllItemsAssigned()
             {
                 closePopup(ui);
             }
         });
         openModalPopup(ui);
     }
 }
 


So the popped up page bean (MyPopupUI) has to be defined in the following way:

Code:
 public class MyPopupUI
 {
     public interface IListener
     {
         public void  reactOnAllItemsAssigned();
     }
 
     IListener m_listener;
     
     public void prepare(...,IListener listener)
     {
         m_listener = listener;
         ...
     }
 
 
     public void ....assignmentOFItems..()
     {
         if (...allItemsAreAssigned... == true)
         {
             if (m_listener != null) m_listener.reactOnAllItemsAssigned();
         }
     }
 }
 


The java processing does not stop when opening a popup...! (Remember: the Java processing is called by a request from the browser, so the browser needs to receive a response to show the popup!...). The popup has to tell the opener - best by IListener interface - that it wants to be closed.

Hope this helps...

Kind regards! Björn

Björn Müller, CaptainCasa GmbH
kklasen

Power User

Joined: 19/11/2020 08:33:30
Messages: 66
Offline

Hello Björn,

Thank you for your quick answer!

The endless loop is gone! Why ever? I have nothing chance?

Anyway! I made a variable for that reason of counting pop-up actions.

“Int closeCount “

Code:
 
 private class ChoicePopupExel implements Runnable {
 		int clCount;
 		public ChoicePopupExel(int closeCount) {
 			super();
 			clCount = closeCount;
 			
 			// TODO Auto-generated constructor stub
 		}
 


It should count how often the popup is opened/closed and if its lower than the count of items, automatically open pop-up again.

Code:
 
 	public void onCboSelectItemAction(javax.faces.event.ActionEvent event) {
 		onClose();
 
 		maui.prepare(new MainAreaUI.PListener() {
 
 			@Override
 			public void recaivefromPopup(int popupID) {
 				// TODO Auto-generated method stub
 
 			}
 		}, m_cboItemValue);
 	}
 



It’s an extra Listener for counting.

kind regards

Klas

kklasen

Power User

Joined: 19/11/2020 08:33:30
Messages: 66
Offline

Hello Björn,

It’s not gone. I made a mistake.

A while loop should open the pop-up.The program goes into the loop, up to the point where it should open the popup. from then on it hangs.

Code:
 			int rSize = runner.size();
 
 			while(m_closeCount <= rSize) {
 			// ----Thread-for Pop-up---
 				ChoicePopupExel cpe = new ChoicePopupExel(m_closeCount);
 				Thread t8 = new Thread(cpe);
 				t8.start();
 				cpe.popupStart();
 				
 				try {
 					t8.join();
 				} catch (InterruptedException e) {
 					Statusbar.outputAlert("Fehler beim Beenden des Threads " + e);
 					e.printStackTrace();
 				}
 			
 			}
 
 		}
 

Without while loop it gives back one value.
It does not work with loops?

how can I make it open automatically

kind regards

Klas

CaptainCasa

Power User
[Avatar]

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

Hi,

what you do with threads is "more than suspicious"... ;-) Do not do this.

You open a popup. In this popup you do certain things (in your case: assign something). As reaction of the assignment you want to close the popup ("if everything is assigned"). - So the assignment inside the popup has to send an event (== IListener-callback) to the one who started the popup. This one checks if everythin is assigned, if yes, then closes the popup.

Work with IListener between the opening screen and the popup screen. That's the way to go!

Kind regards! Björn

Björn Müller, CaptainCasa GmbH
kklasen

Power User

Joined: 19/11/2020 08:33:30
Messages: 66
Offline

the executable code:

Code:
 	int m_popupCounter;
 	private void startPopupComboExcel() {
 		m_popupCounter = 3;
 		openPopupComboExcel();
 	}
 
 	private void openPopupComboExcel() {
 		PopupComboxExcelUI bean = new PopupComboxExcelUI();
 		ModalPopup mp = openModalPopup(bean, "Auswahlbereich", 300, 200, new ModalPopup.IModalPopupListener() {
 			@Override
 			public void reactOnPopupClosedByUser() {
 				closePopupComboExcelAndReopenOnCounter(bean);
 			}
 		});
 		mp.setLeftTopReferenceComponentIdCentered(m_content);
 		mp.hideCloseIcon();
 		mp.hideMaximizeIcon();
 		bean.prepare(new managedbeans.PopupComboxExcelUI.IListener() {
 			@Override
 			public void onClosePopup() {
 				closePopupComboExcelAndReopenOnCounter(bean);
 			}
 
 			@Override
 			public void reactOnItemSelection(int cboItemValue) {
 				closePopupComboExcelAndReopenOnCounter(bean);
 			}
 		});
 	}
 	
 	private void closePopupComboExcelAndReopenOnCounter(PopupComboxExcelUI bean) {
 		closePopup(bean);
 		m_popupCounter--;
 		if (m_popupCounter > 0)
 			openPopupComboExcel();
 	}
 
 
Forum Index -> Development
Go to:   
Powered by JForum 2.1.6 © JForum Team