Hi!

To be short, I have a <h:dataTable> filled by values from a list.

For each row/item the user can press a "view details" button, which opens a 
popup with the javascript-function window.open(). The user is also given the 
possibility to open several popups at a time to provide support for comparing 
to or more rows to each other (the names of the popups are unique).

My "challenge" is that I need a way to set and respect a limit of number of 
popups allowed. My commandLinks should render differently based on this 
condition. 

if (currentNumberOfPopups < popupLimit)
commandLink opens a new popup window with row details

if (currentNumberOfPopups >= popupLimit)
commandLink opens a popup saying that the popupLimit has been reached.

If limit is reached and the user close one of the existing popup windows, it 
should be possible to open new popups. The condition set on the commandLinks 
therefore enforces a refresh of my parent page whenever a new popup is created 
or if a popup is closed. If the limit is reached the user is also presented 
with an error message on top of the parent page.

Ok, and this is what I've tried to do so far:

I have a bean with a HashMap and the attributes currentNumberOfPopups and 
popupLimit (both ints). When I open a new popup I put a reference of it into 
the HashMap, thus keeping track of the popups that are opened (and the number 
of popups of course). I also execute a javascript function that clicks a hidden 
button in my parent page, and this button is implemented with ajax a4j to 
refresh the view to be up to date with the changes.

To handle the closing of a popup I have an unload event that fires only if 
users have pressed the 'X' button or if they have pressed a "close" 
commandButtoon. (to manage this I had to go for an IE only solution, but i'm 
okay with that for now). A refresh of the page does not fire this event. This 
event basically removes the reference from the HashMap, and then clicks the 
same refresh-button as was clicked when opening.

My problem is:
This way of doing it doesn't seem to be "accurate" enough. Sometimes (for no 
reason) the parent view doesn't refresh as it should (commandLinks are'nt 
updated), and I've also experienced that my counter gets out of sync with the 
actual number of popups open. This results in the error-popup to be opened when 
it shouldn't have been opened. 

Does anybody see another/a better way of handling this? How to respect a popup 
limit? Any ideas / new approaches would have been appreciated. I've been 
thinking of having a global array in javascript that holds the handlers to the 
popup-windows, and then somehow manage the rendering based on the size of this 
array, but the problem is that when I refresh the parent page this array is 
reset as well, so I cannot go down that path. 

Regards,

Eivind

 
 

<<winmail.dat>>

Reply via email to