Java Code Examples for javax.faces.context.FacesContext#getApplication()

The following examples show how to use javax.faces.context.FacesContext#getApplication() . 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 check out the related API usage on the sidebar.
Example 1
Source Project: sakai   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 2
Source Project: sakai   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 3
Source Project: sakai   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 4
Source Project: sakai   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 5
@Override
  public void encodeBegin(FacesContext context) throws IOException {
      Application app = context.getApplication();
      ResourceHandler rh = app.getResourceHandler();
  	ResponseWriter responseWriter = context.getResponseWriter();
Resource h5s = rh.createResource("js/html5shiv.js", C.BSF_LIBRARY);
Resource rjs = rh.createResource("js/respond.js", C.BSF_LIBRARY);

responseWriter.write("<!--[if lt IE 9]>");
responseWriter.startElement("script", null);
responseWriter.writeAttribute("src", h5s.getRequestPath(), null);
responseWriter.endElement("script");
responseWriter.startElement("script", null);
responseWriter.writeAttribute("src", rjs.getRequestPath(), null);
responseWriter.endElement("script");
responseWriter.write("<![endif]-->");
  }
 
Example 6
Source Project: sakai   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 7
Source Project: sakai   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 8
Source Project: sakai   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 9
Source Project: sakai   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 10
Source Project: sakai   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 11
Source Project: sakai   File: TagUtil.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);
}
 
Example 12
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);
}
 
Example 13
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);
}
 
Example 14
Source Project: sakai   File: TagUtil.java    License: Educational Community License v2.0 5 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 15
Source Project: sakai   File: TagUtil.java    License: Educational Community License v2.0 5 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 16
public String convertValue(FacesContext context, UIComponent component, Converter converter, Object value) throws ConverterException {
    if(value!=null) {
        if(converter==null) {
            Application application = context.getApplication();
            converter = application.createConverter(value.getClass());
        }
        // Format it using the converter if necessary, or just converter it to a simple string
        String strValue = converter!=null ? converter.getAsString(context, component, value) 
                                          : value.toString(); 
        return strValue;
    }

    return "";
}
 
Example 17
Source Project: BootsFaces-OSP   File: Datepicker.java    License: Apache License 2.0 5 votes vote down vote up
public Datepicker() {
	setRendererType(null); // this component renders itself

	AddResourcesListener.addThemedCSSResource("core.css");
	AddResourcesListener.addExtCSSResource("jq.ui.core.css");
	AddResourcesListener.addExtCSSResource("jq.ui.theme.css");
	AddResourcesListener.addExtCSSResource("jq.ui.datepicker.css");

	AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, "jq/ui/core.js");
	AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, "jq/ui/datepicker.js");
	FacesContext context = FacesContext.getCurrentInstance();
	Application app = context.getApplication();
	ResourceHandler rh = app.getResourceHandler();
	Resource rdp;
	Iterator<Locale> preferredLanguages = context.getExternalContext().getRequestLocales();
	while (preferredLanguages.hasNext()) {
		String language = preferredLanguages.next().getLanguage();
		if ("en".equals(language)) {
			break;
		}
		final String jsl = "jq/ui/i18n/datepicker-" + language + ".js";
		rdp = rh.createResource(jsl, C.BSF_LIBRARY);
		if (rdp != null) { // rdp is null if the language .js is not present
							// in jar
			AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, jsl);
			break;
		}

	}
	Tooltip.addResourceFiles();
}
 
Example 18
public void refresh() {
    FacesContext context = FacesContext.getCurrentInstance();
    Application application = context.getApplication();
    ViewHandler viewHandler = application.getViewHandler();
    UIViewRoot viewRoot = viewHandler.createView(context, context
            .getViewRoot().getViewId());
    context.setViewRoot(viewRoot);
    context.renderResponse(); //Optional
}
 
Example 19
Source Project: sakai   File: Tags.java    License: Educational Community License v2.0 5 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 20
public void afterPhase(PhaseEvent event) {
	FacesContext context = FacesContext.getCurrentInstance();
	Application app = context.getApplication();
	ValueBinding binding = app.createValueBinding("#{ForumTool}");
	DiscussionForumTool forumTool = (DiscussionForumTool) binding
			.getValue(context);
	Map requestParams = context.getExternalContext()
			.getRequestParameterMap();

	String action = (String) requestParams.get("action");
	String messageId = (String) requestParams.get("messageId");
	String topicId = (String) requestParams.get("topicId");
	String ajax = (String) requestParams.get("ajax");

	HttpServletResponse response = (HttpServletResponse)context.getExternalContext().getResponse();
	if ("true".equals(ajax)) {
		try {
			ServletOutputStream out = response.getOutputStream();
			response.setHeader("Pragma", "No-Cache");
			response.setHeader("Cache-Control",
					"no-cache,no-store,max-age=0");
			response.setDateHeader("Expires", 1);
			if (action == null) {
				out.println("FAIL");
			} else if ("markMessageAsRead".equals(action)) {
				// Ajax call to mark messages as read for user
				if (messageId != null && topicId != null) {
					if (!forumTool.isMessageReadForUser(Long.valueOf(topicId),
							Long.valueOf(messageId))) {
						forumTool.markMessageReadForUser(Long.valueOf(topicId),
								Long.valueOf(messageId), true);
						out.println("SUCCESS");
					} else {
						// also output success in case message is read, but
						// page rendered mail icon (old state)
						out.println("SUCCESS");
					}
				}
			}
			out.flush();
		} catch (Exception ee) {
			log.error(ee.getMessage(), ee);
		}
		context.responseComplete();
	}
	;
}