Java Code Examples for javax.faces.application.Application

The following examples show how to use javax.faces.application.Application. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Boolean evalBoolean(String expression)
{
    if (expression == null)
    {
        return null;
    }
    if (UIComponentTag.isValueReference(expression))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        Object r = app.createValueBinding(expression).getValue(context);
        if (r == null)
        {
            return null;
        } else if (r instanceof Boolean)
        {
            return (Boolean) r;
        } else
        {
            return Boolean.valueOf(r.toString());
        }
    } else
    {
        return Boolean.valueOf(expression);
    }
}
 
Example 2
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
public static void setMethodBinding(UIComponent component,
  String attributeName,
  String attributeValue, Class[] paramTypes)
{
  if (attributeValue == null)
  {
    return;
  }
  if (UIComponentTag.isValueReference(attributeValue))
  {
    FacesContext context = FacesContext.getCurrentInstance();
    Application app = context.getApplication();
    MethodBinding mb = app.createMethodBinding(attributeValue,
                       paramTypes);
    component.getAttributes().put(attributeName, mb);
  }
}
 
Example 3
Source Project: joinfaces   Source File: WindowScopeTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() throws MalformedURLException {
	FacesContext facesContext = FacesContextMocker.mockFacesContext();
	ExternalContext externalContext = mock(ExternalContext.class);
	when(facesContext.getExternalContext()).thenReturn(externalContext);
	when(externalContext.getResource("/WEB-INF/portlet.xml")).thenReturn(null);
	Application application = mock(Application.class);
	when(facesContext.getApplication()).thenReturn(application);

	this.scopeMap = new WindowScopeManager.ScopeMap(FacesContext.getCurrentInstance());

	this.windowScope = new WindowScope() {
		@Override
		@NonNull
		WindowScopeManager.ScopeMap getScopeMap() {
			return WindowScopeTest.this.scopeMap;
		}
	};
}
 
Example 4
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Integer evalInteger(String expression)
{
    if (expression == null)
    {
        return null;
    }
    if (UIComponentTag.isValueReference(expression))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        Object r = app.createValueBinding(expression).getValue(context);
        if (r == null)
        {
            return null;
        } else if (r instanceof Integer)
        {
            return (Integer) r;
        } else
        {
            return Integer.valueOf(r.toString());
        }
    } else
    {
        return Integer.valueOf(expression);
    }
}
 
Example 5
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
/**
 * Set an action on a component - used by tags setProperties() method.
 * Handles method bindings.
 */
public static void setAction(UIComponent component, String value)
{
    if (value == null)
    {
        return;
    }
    if (UIComponentTag.isValueReference(value))
    {
        setMethodBinding(component, "action", value, new Class[] {});
    } else
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        MethodBinding mb = new ActionMethodBinding(value);
        component.getAttributes().put("action", mb);
    }
}
 
Example 6
Source Project: sakai   Source File: Tags.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Double evalDouble(String expression) {
	if (expression == null)
		return null;
	if (UIComponentTag.isValueReference(expression)) {
		FacesContext context = FacesContext.getCurrentInstance();
		Application app = context.getApplication();
		Object r = app.createValueBinding(expression).getValue(context);
		if (r == null)
			return null;
		else if (r instanceof Double)
			return (Double) r;
		else
			return new Double(r.toString());
	} else
		return new Double(expression);
}
 
Example 7
/**
 * Creates the "cheap" objects
 */
@Override
public void createImplicitObjects(final FacesContextEx ctx) {
	if (!implicitsDone_) {
		implicitsDone_ = true;
		if (!ODAPlatform.isAPIEnabled(null))
			return;

		Session session = Factory.getSession(SessionType.CURRENT);

		Database db = session.getCurrentDatabase();
		Map<String, Object> ecMap = TypedUtil.getRequestMap(ctx.getExternalContext());

		ecMap.put("openSession", session);
		ecMap.put("openDatabase", db);

		// Attach NSA
		if (ODAPlatform.isAppFlagSet("nsa")) {
			Application app = ctx.getApplication();
			if (app instanceof ApplicationEx) {
				NSA.INSTANCE.registerApplication((ApplicationEx) app);
				NSA.INSTANCE.registerSession((ApplicationEx) app, (HttpSession) ctx.getExternalContext().getSession(true));
			}
		}
	}
}
 
Example 8
protected Converter findConverter(FacesContext context, UIDataSourceIterator c, ViewDefinition viewDef, ValueColumn vc, Object value) {
    // Explicit converter
    Converter converter = vc.getConverter();
    if(converter!=null) {
        return converter;
    }

    Class<?> converterType = value.getClass();
    if (converterType == null || converterType == String.class || converterType == Object.class) {
        return null;
    }
    
    // Acquire an appropriate converter instance.
    try {
        Application application = context.getApplication();
        return application.createConverter(converterType);
    } catch (Exception e) {
    }
    
    return null;
}
 
Example 9
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
/**
 * Set a MethodBinding on a component - used by tags setProperties() method.
 */
public static void setMethodBinding(UIComponent component, String name, String value,
        Class[] paramTypes)
{
    if (value == null)
    {
        return;
    }
    if (UIComponentTag.isValueReference(value))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        MethodBinding mb = app.createMethodBinding(value, paramTypes);
        component.getAttributes().put(name, mb);
    }
}
 
Example 10
Source Project: sakai   Source File: Tags.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Boolean evalBoolean(String expression) {
	if (expression == null)
		return null;
	if (UIComponentTag.isValueReference(expression)) {
		FacesContext context = FacesContext.getCurrentInstance();
		Application app = context.getApplication();
		Object r = app.createValueBinding(expression).getValue(context);
		if (r == null)
			return null;
		else if (r instanceof Boolean)
			return (Boolean) r;
		else
			return new Boolean(r.toString());
	} else
		return new Boolean(expression);
}
 
Example 11
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Integer evalInteger(String expression)
{
    if (expression == null)
    {
        return null;
    }
    if (UIComponentTag.isValueReference(expression))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        Object r = app.createValueBinding(expression).getValue(context);
        if (r == null)
        {
            return null;
        } else if (r instanceof Integer)
        {
            return (Integer) r;
        } else
        {
            return Integer.valueOf(r.toString());
        }
    } else
    {
        return Integer.valueOf(expression);
    }
}
 
Example 12
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Boolean evalBoolean(String expression)
{
    if (expression == null)
    {
        return null;
    }
    if (UIComponentTag.isValueReference(expression))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        Object r = app.createValueBinding(expression).getValue(context);
        if (r == null)
        {
            return null;
        } else if (r instanceof Boolean)
        {
            return (Boolean) r;
        } else
        {
            return Boolean.valueOf(r.toString());
        }
    } else
    {
        return Boolean.valueOf(expression);
    }
}
 
Example 13
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
/**
 * Set an action on a component - used by tags setProperties() method.
 * Handles method bindings.
 */
public static void setAction(UIComponent component, String value)
{
    if (value == null)
    {
        return;
    }
    if (UIComponentTag.isValueReference(value))
    {
        setMethodBinding(component, "action", value, new Class[] {});
    } else
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        MethodBinding mb = new ActionMethodBinding(value);
        component.getAttributes().put("action", mb);
    }
}
 
Example 14
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
/**
 * Set a MethodBinding on a component - used by tags setProperties() method.
 */
public static void setMethodBinding(UIComponent component, String name, String value,
        Class[] paramTypes)
{
    if (value == null)
    {
        return;
    }
    if (UIComponentTag.isValueReference(value))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        MethodBinding mb = app.createMethodBinding(value, paramTypes);
        component.getAttributes().put(name, mb);
    }
}
 
Example 15
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
public static String eval(String expression)
{
    if (expression == null)
    {
        return null;
    }
    if (UIComponentTag.isValueReference(expression))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        return "" + app.createValueBinding(expression).getValue(context);
    } else
    {
        return expression;
    }
}
 
Example 16
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Double evalDouble(String expression)
{
    if (expression == null)
    {
        return null;
    }
    if (UIComponentTag.isValueReference(expression))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        Object r = app.createValueBinding(expression).getValue(context);
        if (r == null)
        {
            return null;
        } else if (r instanceof Double)
        {
            return (Double) r;
        } else
        {
            return Double.valueOf(r.toString());
        }
    } else
    {
        return Double.valueOf(expression);
    }
}
 
Example 17
Source Project: yawl   Source File: SessionBean.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * redirects to the specified page
 * @param page the name of the page to go to
 */
public void gotoPage(String page) {
    Application app = getApplication() ;
    if (app != null) {
        NavigationHandler navigator = app.getNavigationHandler();
        navigator.handleNavigation(getFacesContext(), null, page);
    }

    // if app is null, session has been destroyed
    else {
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("msLogin.jsp");
        }
        catch (IOException ioe) {
            // message about destroyed app
        }
    }
}
 
Example 18
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Double evalDouble(String expression)
{
    if (expression == null)
    {
        return null;
    }
    if (UIComponentTag.isValueReference(expression))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        Object r = app.createValueBinding(expression).getValue(context);
        if (r == null)
        {
            return null;
        } else if (r instanceof Double)
        {
            return (Double) r;
        } else
        {
            return Double.valueOf(r.toString());
        }
    } else
    {
        return Double.valueOf(expression);
    }
}
 
Example 19
Source Project: sakai   Source File: Tags.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Integer evalInteger(String expression) {
	if (expression == null)
		return null;
	if (UIComponentTag.isValueReference(expression)) {
		FacesContext context = FacesContext.getCurrentInstance();
		Application app = context.getApplication();
		Object r = app.createValueBinding(expression).getValue(context);
		if (r == null)
			return null;
		else if (r instanceof Integer)
			return (Integer) r;
		else
			return new Integer(r.toString());
	} else
		return new Integer(expression);
}
 
Example 20
Source Project: sakai   Source File: Tags.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Double evalDouble(String expression) {
	if (expression == null)
		return null;
	if (UIComponentTag.isValueReference(expression)) {
		FacesContext context = FacesContext.getCurrentInstance();
		Application app = context.getApplication();
		Object r = app.createValueBinding(expression).getValue(context);
		if (r == null)
			return null;
		else if (r instanceof Double)
			return (Double) r;
		else
			return new Double(r.toString());
	} else
		return new Double(expression);
}
 
Example 21
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
/**
 * Set a MethodBinding on a component - used by tags setProperties() method.
 */
public static void setMethodBinding(UIComponent component, String name, String value,
        Class[] paramTypes)
{
    if (value == null)
    {
        return;
    }
    if (UIComponentTag.isValueReference(value))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        MethodBinding mb = app.createMethodBinding(value, paramTypes);
        component.getAttributes().put(name, mb);
    }
}
 
Example 22
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
/**
 * Set a MethodBinding on a component - used by tags setProperties() method.
 */
public static void setMethodBinding(UIComponent component, String name, String value,
        Class[] paramTypes)
{
    if (value == null)
    {
        return;
    }
    if (UIComponentTag.isValueReference(value))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        MethodBinding mb = app.createMethodBinding(value, paramTypes);
        component.getAttributes().put(name, mb);
    }
}
 
Example 23
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Integer evalInteger(String expression)
{
    if (expression == null)
    {
        return null;
    }
    if (UIComponentTag.isValueReference(expression))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        Object r = app.createValueBinding(expression).getValue(context);
        if (r == null)
        {
            return null;
        } else if (r instanceof Integer)
        {
            return (Integer) r;
        } else
        {
            return Integer.valueOf(r.toString());
        }
    } else
    {
        return Integer.valueOf(expression);
    }
}
 
Example 24
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Double evalDouble(String expression)
{
    if (expression == null)
    {
        return null;
    }
    if (UIComponentTag.isValueReference(expression))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        Object r = app.createValueBinding(expression).getValue(context);
        if (r == null)
        {
            return null;
        } else if (r instanceof Double)
        {
            return (Double) r;
        } else
        {
            return Double.valueOf(r.toString());
        }
    } else
    {
        return Double.valueOf(expression);
    }
}
 
Example 25
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
public static Boolean evalBoolean(String expression)
{
    if (expression == null)
    {
        return null;
    }
    if (UIComponentTag.isValueReference(expression))
    {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        Object r = app.createValueBinding(expression).getValue(context);
        if (r == null)
        {
            return null;
        } else if (r instanceof Boolean)
        {
            return (Boolean) r;
        } else
        {
            return Boolean.valueOf(r.toString());
        }
    } else
    {
        return Boolean.valueOf(expression);
    }
}
 
Example 26
Source Project: yawl   Source File: SessionBean.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * redirects to the specified page
 * @param page the name of the page to go to
 */
public void gotoPage(String page) {
    Application app = getApplication() ;
    if (app != null) {
        NavigationHandler navigator = app.getNavigationHandler();
        navigator.handleNavigation(getFacesContext(), null, page);
    }

    // if app is null, session has been destroyed
    else {
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("Login.jsp");
        }
        catch (IOException ioe) {
            // message about destroyed app
        }
    }
}
 
Example 27
Source Project: sakai   Source File: TagUtil.java    License: Educational Community License v2.0 5 votes vote down vote up
/**
 * Set a ValueBinding on a component - used by tags setProperties() method.
 */
public static void setValueBinding(UIComponent component, String name, String value)
{
    FacesContext context = FacesContext.getCurrentInstance();
    Application app = context.getApplication();
    ValueBinding vb = app.createValueBinding(value);
    component.setValueBinding(name, vb);
}
 
Example 28
Source Project: sakai   Source File: ContextUtil.java    License: Educational Community License v2.0 5 votes vote down vote up
/**
 * Helper method to look up backing bean.
 * Don't forget to cast!
 *   e.g. (TemplateBean) ContextUtil.lookupBean("template")
 * @param context the faces context
 * @return the backing bean
 * @throws FacesException
 */
public static Serializable lookupBean(String beanName)
{
  FacesContext facesContext = FacesContext.getCurrentInstance();
  ApplicationFactory factory = (ApplicationFactory) FactoryFinder.
                               getFactory(
                               FactoryFinder.APPLICATION_FACTORY);
  Application application = factory.getApplication();
  Serializable bean = (Serializable)
                      application.getVariableResolver().resolveVariable(
                      facesContext, beanName);
  return bean;
}
 
Example 29
Source Project: tutorials   Source File: ELSampleBean.java    License: MIT License 5 votes vote down vote up
private Object evaluateEL(String elExpression, Class<?> clazz) {
    Object toReturn = null;
    FacesContext ctx = FacesContext.getCurrentInstance();
    Application app = ctx.getApplication();
    toReturn = app.evaluateExpressionGet(ctx, elExpression, clazz);

    return toReturn;

}
 
Example 30
Source Project: sakai   Source File: Tags.java    License: Educational Community License v2.0 5 votes vote down vote up
public static void setValueBinding(UIComponent component, String attributeName,
      String attributeValue) {
   FacesContext context = FacesContext.getCurrentInstance();
   Application app = context.getApplication();
   ValueBinding vb = app.createValueBinding(attributeValue);
   component.setValueBinding(attributeName, vb);
}