Search in sources :

Example 26 with UIViewRoot

use of javax.faces.component.UIViewRoot in project acs-community-packaging by Alfresco.

the class InvokeCommand method setupResponseWriter.

/**
 * setup the JSF response writer.
 */
private ResponseWriter setupResponseWriter(final String mimetype, final HttpServletResponse response, final FacesContext facesContext) throws IOException {
    final OutputStream os = response.getOutputStream();
    final UIViewRoot viewRoot = facesContext.getViewRoot();
    final RenderKitFactory renderFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
    final RenderKit renderKit = renderFactory.getRenderKit(facesContext, viewRoot.getRenderKitId());
    final ResponseWriter writer = renderKit.createResponseWriter(new OutputStreamWriter(os, "UTF-8"), mimetype, "UTF-8");
    facesContext.setResponseWriter(writer);
    // must be text/xml otherwise IE doesn't parse the response properly into responseXML
    response.setContentType(mimetype);
    return writer;
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) OutputStream(java.io.OutputStream) RenderKit(javax.faces.render.RenderKit) OutputStreamWriter(java.io.OutputStreamWriter) UIViewRoot(javax.faces.component.UIViewRoot) RenderKitFactory(javax.faces.render.RenderKitFactory)

Example 27 with UIViewRoot

use of javax.faces.component.UIViewRoot in project rubia-forums by flashboss.

the class ForumUtil method getToHTMLRenderer.

/**
 * @param req
 *            the request that maybe contains the format object
 * @return the renderer for the requested request
 */
private static ToHTMLRenderer getToHTMLRenderer(Object req) {
    ToHTMLRenderer renderer = null;
    // TODO: GETTING RENDERER FROM APPLICATION SCOPE ATTRIBUTE
    if (renderer == null) {
        // Getting ResourceBundle with current Locale
        FacesContext ctx = getCurrentInstance();
        UIViewRoot uiRoot = ctx.getViewRoot();
        Locale locale = uiRoot.getLocale();
        ClassLoader ldr = currentThread().getContextClassLoader();
        ResourceBundle bundle = getBundle("ResourceJSF", locale, ldr);
        // Create the HTMLRenderer for BBCode
        ToHTMLConfig config = new ToHTMLConfig();
        renderer = new ToHTMLRenderer(config, bundle);
    }
    return renderer;
}
Also used : Locale(java.util.Locale) ToHTMLConfig(it.vige.rubia.format.render.bbcodehtml.ToHTMLConfig) FacesContext(javax.faces.context.FacesContext) ToHTMLRenderer(it.vige.rubia.format.render.bbcodehtml.ToHTMLRenderer) ResourceBundle(java.util.ResourceBundle) UIViewRoot(javax.faces.component.UIViewRoot)

Example 28 with UIViewRoot

use of javax.faces.component.UIViewRoot in project rubia-forums by flashboss.

the class NotificationEngineImpl method schedule.

public void schedule(Integer postId, int mode, String absViewURL, String absReplyURL) {
    try {
        if (postId == null || mode == -1) {
            return;
        }
        // Getting ResourceBundle with current Locale
        // Too bad for now we support notifications sent in the locale of
        // the poster :-(
        UIViewRoot uiRoot = getCurrentInstance().getViewRoot();
        Locale locale = uiRoot.getLocale();
        ClassLoader ldr = Thread.currentThread().getContextClassLoader();
        ResourceBundle bundle = ResourceBundle.getBundle("ResourceJSF", locale, ldr);
        // Create task
        NotificationTask task = new NotificationTask(absViewURL, absReplyURL, postId, mode, bundle);
        // Register at the end of the current tx to broadcast notifications
        Transaction tx = tm.getTransaction();
        tx.registerSynchronization(task);
    } catch (Exception e) {
        log.error(e);
    }
}
Also used : Locale(java.util.Locale) Transaction(javax.transaction.Transaction) ResourceBundle(java.util.ResourceBundle) UIViewRoot(javax.faces.component.UIViewRoot) MessagingException(javax.mail.MessagingException) NamingException(javax.naming.NamingException) ModuleException(it.vige.rubia.ModuleException)

Example 29 with UIViewRoot

use of javax.faces.component.UIViewRoot in project rubia-forums by flashboss.

the class BackButton method afterPhase.

@Override
public void afterPhase(PhaseEvent arg0) {
    FacesContext facesContext = arg0.getFacesContext();
    UIViewRoot uiViewRoot = facesContext.getViewRoot();
    if (getCancelButton(uiViewRoot) != null)
        facesContext.getViewRoot().setViewId(oldViewId);
}
Also used : FacesContext(javax.faces.context.FacesContext) UIViewRoot(javax.faces.component.UIViewRoot)

Example 30 with UIViewRoot

use of javax.faces.component.UIViewRoot in project rubia-forums by flashboss.

the class BackButton method beforePhase.

@Override
public void beforePhase(PhaseEvent arg0) {
    FacesContext facesContext = arg0.getFacesContext();
    UIViewRoot uiViewRoot = facesContext.getViewRoot();
    if (getCancelButton(uiViewRoot) == null)
        oldViewId = uiViewRoot.getViewId();
}
Also used : FacesContext(javax.faces.context.FacesContext) UIViewRoot(javax.faces.component.UIViewRoot)

Aggregations

UIViewRoot (javax.faces.component.UIViewRoot)41 FacesContext (javax.faces.context.FacesContext)18 Test (org.junit.Test)10 ViewHandler (javax.faces.application.ViewHandler)8 Locale (java.util.Locale)6 ResourceBundle (java.util.ResourceBundle)4 Application (javax.faces.application.Application)3 UIComponent (javax.faces.component.UIComponent)3 ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Map (java.util.Map)2 ExternalContext (javax.faces.context.ExternalContext)2 FacesContextFactory (javax.faces.context.FacesContextFactory)2 PreDestroyViewMapEvent (javax.faces.event.PreDestroyViewMapEvent)2 LifecycleFactory (javax.faces.lifecycle.LifecycleFactory)2 ServletContext (javax.servlet.ServletContext)2 NonNull (org.springframework.lang.NonNull)2 Handler (com.sun.jsftemplating.annotation.Handler)1 ModuleException (it.vige.rubia.ModuleException)1 ToHTMLConfig (it.vige.rubia.format.render.bbcodehtml.ToHTMLConfig)1