javax.faces.application.ProjectStage Java Examples

The following examples show how to use javax.faces.application.ProjectStage. 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 File: CoreRenderer.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
public static void assertComponentIsInsideForm(UIComponent component, String msg, boolean throwException) {
	if (!FacesContext.getCurrentInstance().isProjectStage(ProjectStage.Production)) {
		UIComponent c = component;
		while ((c != null) && (!(c instanceof UIForm))) {
			c = c.getParent();
		}
		if (!(c instanceof UIForm)) {
			System.out.println("Warning: The BootsFaces component " + component.getClass()
					+ " works better if put inside a form. These capabilities get lost if not put in a form:");
			if (throwException) {
				throw new FacesException(msg);
			} else {
				System.out.println(msg);
			}
		}
	}
}
 
Example #2
Source File: EmptyServletContext.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Object getAttribute(String attribute) {
    final String projectStageKey = AbstractConfigProcessor.class.getName() + ".PROJECTSTAGE";
    if (attribute.equals(projectStageKey)) {
        return ProjectStage.Development;
    }
    return null;
}
 
Example #3
Source File: ProjectStageAutoConfigurationTest.java    From joinfaces with Apache License 2.0 5 votes vote down vote up
@Test
public void testProductionIsDefault() {
	this.webApplicationContextRunner
			.run(context ->
					assertThat(context.getBean(JavaxFaces2_0Properties.class).getProjectStage()).isEqualTo(ProjectStage.Production)
			);
}
 
Example #4
Source File: ProjectStageAutoConfigurationTest.java    From joinfaces with Apache License 2.0 5 votes vote down vote up
@Test
public void testDevelopmentWhenDebug() {
	this.webApplicationContextRunner
			.withPropertyValues("debug")
			.run(context ->
					assertThat(context.getBean(JavaxFaces2_0Properties.class).getProjectStage()).isEqualTo(ProjectStage.Development)
			);
}
 
Example #5
Source File: ProjectStageAutoConfigurationTest.java    From joinfaces with Apache License 2.0 5 votes vote down vote up
@Test
public void testExplicitMappingTakesPrecedence() {
	this.webApplicationContextRunner
			.withPropertyValues("joinfaces.jsf.project-stage=UnitTest")
			.run(context ->
					assertThat(context.getBean(JavaxFaces2_0Properties.class).getProjectStage()).isEqualTo(ProjectStage.UnitTest)
			);
	this.webApplicationContextRunner
			.withPropertyValues("debug", "joinfaces.jsf.project-stage=UnitTest")
			.run(context ->
					assertThat(context.getBean(JavaxFaces2_0Properties.class).getProjectStage()).isEqualTo(ProjectStage.UnitTest)
			);
}
 
Example #6
Source File: AJAXBroadcastComponent.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the ajax call when ajax syntax was found ajax:<command>
 *
 * @param context
 * @param command
 * @return
 */
private Object executeAjaxCalls(FacesContext context, String command) {
	Object result = null;
	int pos = command.indexOf("ajax:");
	while (pos >= 0) { // the command may contain several AJAX and
						// JavaScript calls, in arbitrary order

		String el = command.substring(pos + "ajax:".length());
		if (el.contains("javascript:")) {
			int end = el.indexOf("javascript:");
			el = el.substring(0, end);
		}
		el = el.trim();
		while (el.endsWith(";")) {
			el = el.substring(0, el.length() - 1).trim();
		}

		if (context.isProjectStage(ProjectStage.Development)) {
			checkELSyntax(el, context.getELContext());
		}
		ValueExpression vex = evalAsValueExpression("#{" + el + "}");
		try {
			result = vex.getValue(context.getELContext());
		} catch (javax.el.PropertyNotFoundException ex) {
			MethodExpression mex = evalAsMethodExpression("#{" + el + "}");
			result = mex.invoke(context.getELContext(), null);
		}

		// look for the next AJAX call (if any)
		pos = command.indexOf("ajax:", pos + 1);
	}
	return result;
}
 
Example #7
Source File: ButtonRenderer.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
/**
 * Translate the outcome attribute value to the target URL.
 *
 * @param context
 *            the current FacesContext
 * @param outcome
 *            the value of the outcome attribute
 * @return the target URL of the navigation rule (or the outcome if there's
 *         not navigation rule)
 */
private String determineTargetURL(FacesContext context, Button button, String outcome) {
	ConfigurableNavigationHandler cnh = (ConfigurableNavigationHandler) context.getApplication()
			.getNavigationHandler();
	NavigationCase navCase = cnh.getNavigationCase(context, null, outcome);
	/*
	 * Param Name: javax.faces.PROJECT_STAGE Default Value: The default
	 * value is ProjectStage#Production but IDE can set it differently in
	 * web.xml Expected Values: Development, Production, SystemTest,
	 * UnitTest Since: 2.0
	 *
	 * If we cannot get an outcome we use an Alert to give a feedback to the
	 * Developer if this build is in the Development Stage
	 */
	if (navCase == null) {
		if (FacesContext.getCurrentInstance().getApplication().getProjectStage().equals(ProjectStage.Development)) {
			return "alert('WARNING! " + C.W_NONAVCASE_BUTTON + "');";
		} else {
			return "";
		}
	} // throw new FacesException("The outcome '"+outcome+"' cannot be
		// resolved."); }
	String vId = navCase.getToViewId(context);

	Map<String, List<String>> params = getParams(navCase, button);
	String url;
	url = context.getApplication().getViewHandler().getBookmarkableURL(context, vId, params,
			button.isIncludeViewParams() || navCase.isIncludeViewParams());
	return url;
}
 
Example #8
Source File: ImageRenderer.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Determine the path value of an image value.
 * </p>
 *
 * @param context
 *            the {@link FacesContext} for the current request.
 * @param component
 *            the component to obtain the image information from
 * @return the encoded path to the image source
 */
public static String getImageSource(FacesContext context, UIComponent component) {
	Image image = (Image) component;
	ResourceHandler handler = context.getApplication().getResourceHandler();
	String resourceName = image.getName();
	String value = image.getValue();
	if (value != null && value.length() > 0) {
		if (resourceName != null && image.getLibrary() != null) {
			if (FacesContext.getCurrentInstance().isProjectStage(ProjectStage.Development)) {
				LOGGER.warning(
						"Please use either the 'value' attribute of b:image, or the 'name' and 'library' attribute pair. If all three attributes are provided, BootsFaces uses the 'value' attributes, ignoring both 'name' and 'library'.");
			}
		}
		if (handler.isResourceURL(value)) {
			return value;
		} else {
			value = context.getApplication().getViewHandler().getResourceURL(context, value);
			return (context.getExternalContext().encodeResourceURL(value));
		}
	}

	String library = image.getLibrary();
	Resource res = handler.createResource(resourceName, library);
	if (res == null) {
		if (context.isProjectStage(ProjectStage.Development)) {
			String msg = "Unable to find resource " + resourceName;
			FacesMessages.error(component.getClientId(context), msg, msg);
		}
		return "RES_NOT_FOUND";
	} else {
		return (context.getExternalContext().encodeResourceURL(res.getRequestPath()));
	}
}
 
Example #9
Source File: InjectionAwareApplicationWrapper.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public InjectionAwareApplicationWrapper(
        Application wrapped, JsfModuleConfig jsfModuleConfig, boolean preDestroyViewMapEventFilterMode,
        ProjectStage projectStage)
{
    this.wrapped = wrapped;
    this.containerManagedConvertersEnabled = jsfModuleConfig.isContainerManagedConvertersEnabled();
    this.containerManagedValidatorsEnabled = jsfModuleConfig.isContainerManagedValidatorsEnabled();
    this.fullStateSavingFallbackEnabled = jsfModuleConfig.isFullStateSavingFallbackEnabled();
    this.preDestroyViewMapEventFilterMode = preDestroyViewMapEventFilterMode;
    this.projectStage = projectStage;
}
 
Example #10
Source File: InjectionAwareApplicationWrapper.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Override
public ProjectStage getProjectStage()
{
    if (this.projectStage == null)
    {
        return getWrapped().getProjectStage();
    }
    return this.projectStage;
}
 
Example #11
Source File: ProjectStageAutoConfiguration.java    From joinfaces with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty("debug")
public static ProjectStageCustomizer developmentProjectStageCustomizer() {
	return new ProjectStageCustomizer(ProjectStage.Development);
}
 
Example #12
Source File: ProjectStageAutoConfiguration.java    From joinfaces with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "debug", havingValue = "false", matchIfMissing = true)
public static ProjectStageCustomizer productionProjectStageCustomizer() {
	return new ProjectStageCustomizer(ProjectStage.Production);
}
 
Example #13
Source File: InitParameterServletContextConfigurerConversionTest.java    From joinfaces with Apache License 2.0 4 votes vote down vote up
@Test
public void convertToString_Enum() {
	assertThat(InitParameterServletContextConfigurer.convertToString(ProjectStage.UnitTest))
			.isEqualTo("UnitTest");
}
 
Example #14
Source File: DeltaSpikeFacesContextWrapper.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
private synchronized void init()
{
    // switch into paranoia mode
    if (this.initialized == null)
    {
        this.beanManager = BeanManagerProvider.getInstance().getBeanManager();
        this.jsfModuleConfig = BeanProvider.getContextualReference(this.beanManager, JsfModuleConfig.class, false);

        if (ClassDeactivationUtils.isActivated(JsfRequestBroadcaster.class))
        {
            this.jsfRequestBroadcaster =
                    BeanProvider.getContextualReference(JsfRequestBroadcaster.class, true);
        }

        ViewConfigResolver viewConfigResolver = BeanProvider.getContextualReference(ViewConfigResolver.class);

        //deactivate it, if there is no default-error-view available
        this.defaultErrorViewExceptionHandlerActivated =
                viewConfigResolver.getDefaultErrorViewConfigDescriptor() != null &&
                        ClassDeactivationUtils.isActivated(DefaultErrorViewAwareExceptionHandlerWrapper.class);
        
        this.bridgeExceptionHandlerActivated =
                ClassDeactivationUtils.isActivated(BridgeExceptionHandlerWrapper.class);
        
        this.bridgeExceptionQualifier = AnnotationInstanceProvider.of(jsfModuleConfig.getExceptionQualifier());

        this.preDestroyViewMapEventFilterMode = ClassDeactivationUtils.isActivated(SecurityAwareViewHandler.class);
        this.isNavigationAwareApplicationWrapperActivated =
            ClassDeactivationUtils.isActivated(NavigationHandlerAwareApplication.class);
        org.apache.deltaspike.core.api.projectstage.ProjectStage dsProjectStage =
            ProjectStageProducer.getInstance().getProjectStage();

        for (ProjectStage ps : ProjectStage.values())
        {
            if (ps.name().equals(dsProjectStage.getClass().getSimpleName()))
            {
                this.projectStage = ps;
                break;
            }
        }

        if (this.projectStage == null && dsProjectStage instanceof TestStage)
        {
            this.projectStage = ProjectStage.Development;
        }

        if (this.projectStage == ProjectStage.Production)
        {
            this.projectStage = null; //reset it to force the delegation to the default handling
        }

        this.initialized = true;
    }
}