Search in sources :

Example 11 with UIViewRoot

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

the class JSFUtil method getComponentValue.

/**
 * @author sshah
 *
 * @param componentId
 *            the id component to check
 *
 * @return the value of the choosen component
 */
public static String getComponentValue(String componentId) {
    String value = null;
    UIViewRoot root = getCurrentInstance().getViewRoot();
    UIComponent component = root.findComponent(componentId);
    if (component != null) {
        Object o = component.getValueExpression("value").getValue(getCurrentInstance().getELContext());
        value = (String) o;
    }
    return value;
}
Also used : UIComponent(javax.faces.component.UIComponent) UIViewRoot(javax.faces.component.UIViewRoot)

Example 12 with UIViewRoot

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

the class JSFUtil method removeComponent.

/**
 * @author sshah
 *
 * @param componentId
 *            the id component to check
 */
public static void removeComponent(String componentId) {
    UIViewRoot root = getCurrentInstance().getViewRoot();
    UIComponent component = root.findComponent(componentId);
    if (component != null) {
        UIComponent parent = component.getParent();
        parent.getChildren().remove(component);
    }
}
Also used : UIComponent(javax.faces.component.UIComponent) UIViewRoot(javax.faces.component.UIViewRoot)

Example 13 with UIViewRoot

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

the class JSFUtil method getBundleMessage.

/**
 * @param bundleName
 *            the name of the bundle
 * @param messageKey
 *            the key of the bundle to find
 *
 * @return the value for the requested id
 */
public static String getBundleMessage(String bundleName, String messageKey) {
    String bundleMessage = null;
    // Getting ResourceBundle with current Locale
    FacesContext ctx = getCurrentInstance();
    UIViewRoot uiRoot = ctx.getViewRoot();
    Locale locale = uiRoot.getLocale();
    ClassLoader ldr = currentThread().getContextClassLoader();
    ResourceBundle bundle = getBundle(bundleName, locale, ldr);
    bundleMessage = bundle.getString(messageKey);
    return bundleMessage;
}
Also used : Locale(java.util.Locale) FacesContext(javax.faces.context.FacesContext) ResourceBundle(java.util.ResourceBundle) UIViewRoot(javax.faces.component.UIViewRoot)

Example 14 with UIViewRoot

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

the class ThemeHelper method getFolderType.

/**
 * @param topic
 *            the topic to find
 *
 * @return the folder type
 */
public String getFolderType(Topic topic) {
    // 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);
    String topicType = null;
    int topicStatus = topic.getStatus();
    FolderType folderType = theme.getFolderType(topic.getType(), topicStatus, topic.getReplies() >= hotThreshold);
    try {
        if (topicStatus != Constants.TOPIC_MOVED) {
            try {
                topicType = bundle.getString(folderType.type);
            } catch (MissingResourceException e) {
                topicType = "";
            }
        } else {
            topicType = bundle.getString("Topic_Moved");
        }
    } catch (Exception e) {
        return "";
    }
    return topicType;
}
Also used : JSFUtil.getDefaultLocale(it.vige.rubia.ui.JSFUtil.getDefaultLocale) JSFUtil.getSelectedLocale(it.vige.rubia.ui.JSFUtil.getSelectedLocale) Locale(java.util.Locale) FacesContext(javax.faces.context.FacesContext) MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle) UIViewRoot(javax.faces.component.UIViewRoot) MissingResourceException(java.util.MissingResourceException) FolderType(it.vige.rubia.theme.FolderType)

Example 15 with UIViewRoot

use of javax.faces.component.UIViewRoot in project joinfaces by joinfaces.

the class ViewScope method getViewRoot.

@NonNull
private UIViewRoot getViewRoot() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (facesContext == null) {
        throw new IllegalStateException("No FacesContext found.");
    }
    UIViewRoot viewRoot = facesContext.getViewRoot();
    if (viewRoot == null) {
        throw new IllegalStateException("No ViewRoot found");
    }
    return viewRoot;
}
Also used : FacesContext(javax.faces.context.FacesContext) UIViewRoot(javax.faces.component.UIViewRoot) NonNull(org.springframework.lang.NonNull)

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