Search in sources :

Example 1 with ShowUrlInfo

use of com.servoy.j2db.server.headlessclient.MainPage.ShowUrlInfo in project servoy-client by Servoy.

the class WebClient method closeSolution.

@SuppressWarnings("nls")
@Override
public boolean closeSolution(boolean force, Object[] args) {
    if (getSolution() == null || closing)
        return true;
    try {
        RequestCycle rc = RequestCycle.get();
        closing = true;
        MainPage mp = MainPage.getRequestMainPage();
        if (mp == null) {
            mp = getMainPage();
        }
        // generate requests on all other reachable browser tabs/browser windows that are open in this client;
        // so that they can show the "page expired" page (even if AJAX timer is not enabled)
        List<String> triggerReqScripts = getTriggerReqOnOtherPagesJS(rc, mp);
        MainPage.ShowUrlInfo showUrlInfo = mp.getShowUrlInfo();
        // if this page is showing in a div dialog (or is about to be closed as it was in one), the page redirect needs to happen inside root page, not in iframe
        boolean shownInDialog = mp.isShowingInDialog() || mp.isClosingAsDivPopup();
        boolean retval = super.closeSolution(force, args);
        if (retval) {
            // reset path to templates such as servoy_webclient_default.css in case session/client are reused for another solution
            if (rc != null)
                putClientProperty(WEBCONSTANTS.WEBCLIENT_TEMPLATES_DIR, null);
            else {
                // for example when being closed from admin page
                invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        putClientProperty(WEBCONSTANTS.WEBCLIENT_TEMPLATES_DIR, null);
                    }
                });
            }
            if (rc != null && rc.getRequestTarget() instanceof AjaxRequestTarget) {
                // the idea of this line is to block all possible showurl calls generated by any RedirectAjaxRequestTargets arriving (after the solution is closed) on the page,
                // page that might want to actually show some (possibly external and slow) other page instead of page expired
                ((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript("getRootServoyFrame().Servoy.redirectingOnSolutionClose = true;");
                if (triggerReqScripts != null) {
                    for (String js : triggerReqScripts) {
                        ((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript(js);
                    }
                }
            }
            // close all windows
            getRuntimeWindowManager().closeFormInWindow(null, true);
            Collection<Style> userStyles = getFlattenedSolution().flushUserStyles();
            if (userStyles != null) {
                for (Style style : userStyles) {
                    ComponentFactory.flushStyle(this, style);
                }
            }
            getRuntimeProperties().put(IServiceProvider.RT_VALUELIST_CACHE, null);
            getRuntimeProperties().put(IServiceProvider.RT_OVERRIDESTYLE_CACHE, null);
            // what page should be shown next in browser?
            if (rc != null) {
                boolean showDefault = true;
                boolean urlShown = false;
                if (showUrlInfo != null) {
                    showDefault = !"_self".equals(showUrlInfo.getTarget()) && !"_top".equals(showUrlInfo.getTarget());
                    String url = "/";
                    if (showUrlInfo.getUrl() != null) {
                        url = showUrlInfo.getUrl();
                    }
                    if (rc.getRequestTarget() instanceof AjaxRequestTarget) {
                        showUrlInfo.setOnRootFrame(true);
                        showUrlInfo.setUseIFrame(false);
                        String show = MainPage.getShowUrlScript(showUrlInfo, getSettings());
                        if (show != null) {
                            urlShown = true;
                            ((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript(show);
                            // extra call to make sure that it is removed for the next time.
                            mp.getShowUrlScript();
                        }
                    } else {
                        rc.setRequestTarget(new RedirectRequestTarget(url));
                    }
                }
                if (showDefault) {
                    if (Session.exists() && RequestCycle.get() != null) {
                        if (getPreferedSolutionNameToLoadOnInit() == null) {
                            if ((urlShown || shownInDialog) && rc.getRequestTarget() instanceof AjaxRequestTarget) {
                                // if this page is shown in a dialog then try to get the parent so that the page map is not included in the url
                                MainPage page = mp;
                                while ((page.isShowingInDialog() || page.isClosingAsDivPopup()) && page.getCallingContainer() != null) {
                                    page = page.getCallingContainer();
                                }
                                CharSequence urlFor = page.urlFor(SelectSolution.class, null);
                                ((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript(MainPage.getShowUrlScript(new ShowUrlInfo(urlFor.toString(), "_self", null, 0, true, false), getSettings()));
                            } else {
                                mp.setResponsePage(SelectSolution.class);
                            }
                        } else {
                            // if solution browsing is false, make sure that the credentials are kept
                            if (!Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.allowSolutionBrowsing", "true"))) {
                                WebClientSession.get().keepCredentials(getPreferedSolutionNameToLoadOnInit());
                            }
                            Map<String, Object> map = new HashMap<String, Object>();
                            map.put("s", getPreferedSolutionNameToLoadOnInit());
                            map.put("m", getPreferedSolutionMethodNameToCall());
                            if (getPreferedSolutionMethodArguments() != null && getPreferedSolutionMethodArguments().length > 0) {
                                map.put("a", getPreferedSolutionMethodArguments()[0]);
                            }
                            if ((urlShown || shownInDialog) && rc.getRequestTarget() instanceof AjaxRequestTarget) {
                                CharSequence urlFor = mp.urlFor(SolutionLoader.class, new PageParameters(map));
                                ((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript(MainPage.getShowUrlScript(new ShowUrlInfo(urlFor.toString(), "_self", null, 0, true, false), getSettings()));
                            } else {
                                rc.setResponsePage(SolutionLoader.class, new PageParameters(map), null);
                            }
                        }
                    }
                }
            }
        }
        return retval;
    } finally {
        closing = false;
    }
}
Also used : ShowUrlInfo(com.servoy.j2db.server.headlessclient.MainPage.ShowUrlInfo) HashMap(java.util.HashMap) WebRequestCycle(org.apache.wicket.protocol.http.WebRequestCycle) RequestCycle(org.apache.wicket.RequestCycle) PageParameters(org.apache.wicket.PageParameters) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) RedirectRequestTarget(org.apache.wicket.request.target.basic.RedirectRequestTarget) Style(com.servoy.j2db.persistence.Style) ShowUrlInfo(com.servoy.j2db.server.headlessclient.MainPage.ShowUrlInfo)

Example 2 with ShowUrlInfo

use of com.servoy.j2db.server.headlessclient.MainPage.ShowUrlInfo in project servoy-client by Servoy.

the class RedirectAjaxRequestTarget method respond.

/**
 * @see org.apache.wicket.IRequestTarget#respond(org.apache.wicket.RequestCycle)
 */
public void respond(RequestCycle requestCycle) {
    WebResponse response = (WebResponse) requestCycle.getResponse();
    final String encoding = Application.get().getRequestCycleSettings().getResponseRequestEncoding();
    // Set content type based on markup type for page
    response.setCharacterEncoding(encoding);
    response.setContentType("text/xml; charset=" + encoding);
    // Make sure it is not cached by a client
    response.setDateHeader("Expires", System.currentTimeMillis());
    response.setHeader("Cache-Control", "no-cache, must-revalidate");
    response.setHeader("Pragma", "no-cache");
    CharSequence urlFor = RequestCycle.get().urlFor(page, null);
    response.write("<?xml version=\"1.0\" encoding=\"");
    response.write(encoding);
    response.write("\"?><ajax-response>");
    response.write("<evaluate");
    response.write(">");
    response.write("<![CDATA[");
    response.write(MainPage.getShowUrlScript(new ShowUrlInfo(urlFor.toString(), "_self", null, 0, true, false, true), Settings.getInstance()));
    response.write("]]>");
    response.write("</evaluate>");
    response.write("</ajax-response>");
}
Also used : ShowUrlInfo(com.servoy.j2db.server.headlessclient.MainPage.ShowUrlInfo) WebResponse(org.apache.wicket.protocol.http.WebResponse)

Aggregations

ShowUrlInfo (com.servoy.j2db.server.headlessclient.MainPage.ShowUrlInfo)2 Style (com.servoy.j2db.persistence.Style)1 HashMap (java.util.HashMap)1 PageParameters (org.apache.wicket.PageParameters)1 RequestCycle (org.apache.wicket.RequestCycle)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 WebRequestCycle (org.apache.wicket.protocol.http.WebRequestCycle)1 WebResponse (org.apache.wicket.protocol.http.WebResponse)1 RedirectRequestTarget (org.apache.wicket.request.target.basic.RedirectRequestTarget)1