myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carsten Kaiser" <carsten.kai...@valtech.de>
Subject How to add inline javascript in application phase?
Date Tue, 27 Mar 2007 11:18:13 GMT
Hello,



I'm facing the following problem:

I have an action, in which I want to trigger a popup window, in case the
triggered background job failed. According to the MyFaces Wiki

this can be achieved by



        FacesContext context = getFacesContext();

        ViewHandler viewHandler = getApplication().getViewHandler();

        String actionUrl = viewHandler.getActionURL(context, a_viewId);

        StringBuffer javaScriptText = new StringBuffer("window.open('");

        javaScriptText.append(actionUrl);

        javaScriptText.append("', 'popupWindow', 'dependent=yes,
menubar=no, toolbar=no');");

        AddResource addResource =
AddResourceFactory.getInstance(context);

        addResource.addInlineScriptAtPosition(context,
AddResource.HEADER_BEGIN, javaScriptText.toString());



Unfortunately the ResponseWriter is not yet set on the FacesContext
during this phase, so a NPE occurs when adding the inline script code

like in the last code line shown above. As far as I figured out the
response writer is setup/initialized in the render response phase. So
how could

this code ever worked? Trying to create a response writer manually just
messed up the whole view... (Later works for the AJAX stuff, but I

guess, that is because the normal response isn't rendered in this case!)



Any hints welcome!



Regards,
CK

-- 
Carsten Kaiser
Principal Consultant
mailto:carsten.kaiser@valtech.de
Mobile: +49 (0)170 5270206

Valtech GmbH
Werner-Heisenberg-Straße 2
63263 Neu-Isenburg
Germany

Phone: +49 (0)6102 88468-0
Fax: +49 (0)6102 88468-28

http://www.valtech.de

Geschäftsführer: Ingo Kriescher
Amtsgericht Düsseldorf HRB48672

Mime
View raw message