All posts tagged close

  • Primefaces: Close All Lightboxs

    I had a datatable which contains in each row a link to a different iFrame p:lighbox, and on the same page I had to repeat the same datatables with different objects modules and they also have iFrame p:lightbox.

    I came to a place where I had to close the p:lightbox from a backing bean according to some logic validation,
    and in the same time I can’t know the widgetvar of the current opened p:lightbox, so I had to write some generic function to close all the Lightboxes inside the page.

    First I had to know how primefaces generate the widget vars, after some search I found a function in primefaces which takes an ID of a component and generate a proper widgetvar for it.

    #{p:widgetVar('componentId')}
    

    Basically it does the following it gets the id of the component, for example formId:componentId and replaces the : with _ and append a widget_ to the beginning of the var so it becomes widget_formId_componentId.

    So I came with the following function of jQuery to close all my lightboxs in the page

    function closeLightBoxes() {	
    	$('.ui-lightbox').each(function() {
    		var widgetVar = 'widget_' + $(this).attr('id').replace(":", "_").replace('_panel','');		
    		window[widgetVar].hide();
    	});
    }
    

    First I select each .ui-lightbox class, which is the div of the iFrame and then I do the simple formation of primefaces widgetvar generation, but primefaces adds _panel to the end of the ID of that div, so I had to remove it.

    Note: do not specify any widgetvar to your lightboxs, not even dynamic ones.

  • Exit Button In Android App

    Android Exit

    A lot of developers wondering about the exit button and how they can apply it efficiently, well there are many discussions on stackoverflow or other forums suggest to use this piece of code.

    finish();
    System.exit(0);
    

    This code will only “finish” the current activity and never finishes the rest of the activities or take them to the finalize stage.

    So is there a way to exit an android app completely ?

    the answer is very simple: never and never allow the user to exit the app on his own.

    WHY ?

    That’s against Android nature and best practices, and yet the system handles this automatically. That’s what the activity lifecycle (especially onPause/onStop/onDestroy) is for. No matter what you do, do not put a “close” or “exit” application button.

    Do Users Really Want It?

    Let me posit this assertion: no they don’t.

    Of the apps that ship with the device (Gmail, Contacts, Maps, Gallery, etc.) exactly none of them include an exit button, and most users are comfortable with that. Nonetheless many developers are adamant, “I added it after users demanded it!”.
    if you have to add this button, try not to, just explain why to whom ever demands this functionality, as I’m trying to do always when this case comes around, and it always works.

    Here’s a good video which explains the case: