use of org.primefaces.config.PrimeEnvironment in project primefaces by primefaces.
the class AbstractBehaviorHandler method apply.
@Override
public void apply(FaceletContext faceletContext, UIComponent parent) throws IOException {
if (!ComponentHandler.isNew(parent)) {
return;
}
String eventName = getEventName();
if (UIComponent.isCompositeComponent(parent)) {
boolean tagApplied = false;
if (parent instanceof ClientBehaviorHolder) {
applyAttachedObject(faceletContext, parent);
tagApplied = true;
}
BeanInfo componentBeanInfo = (BeanInfo) parent.getAttributes().get(UIComponent.BEANINFO_KEY);
if (null == componentBeanInfo) {
throw new TagException(tag, "Composite component does not have BeanInfo attribute");
}
BeanDescriptor componentDescriptor = componentBeanInfo.getBeanDescriptor();
if (null == componentDescriptor) {
throw new TagException(tag, "Composite component BeanInfo does not have BeanDescriptor");
}
List<AttachedObjectTarget> targetList = (List<AttachedObjectTarget>) componentDescriptor.getValue(AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY);
if (null == targetList && !tagApplied) {
throw new TagException(tag, "Composite component does not support behavior events");
}
boolean supportedEvent = false;
if (targetList != null) {
for (int i = 0; i < targetList.size(); i++) {
AttachedObjectTarget target = targetList.get(i);
if (target instanceof BehaviorHolderAttachedObjectTarget) {
BehaviorHolderAttachedObjectTarget behaviorTarget = (BehaviorHolderAttachedObjectTarget) target;
if ((null != eventName && eventName.equals(behaviorTarget.getName())) || (null == eventName && behaviorTarget.isDefaultEvent())) {
supportedEvent = true;
break;
}
}
}
}
if (supportedEvent) {
// Workaround to implementation specific composite component handlers
FacesContext context = FacesContext.getCurrentInstance();
PrimeEnvironment environment = PrimeApplicationContext.getCurrentInstance(context).getEnvironment();
if (environment.isMojarra()) {
addAttachedObjectHandlerToMojarra(environment, parent);
} else {
addAttachedObjectHandlerToMyFaces(parent, faceletContext);
}
} else {
if (!tagApplied) {
throw new TagException(tag, "Composite component does not support event " + eventName);
}
}
} else if (parent instanceof ClientBehaviorHolder) {
applyAttachedObject(faceletContext, parent);
} else {
throw new TagException(tag, "Unable to attach behavior to non-ClientBehaviorHolder parent");
}
}
use of org.primefaces.config.PrimeEnvironment in project primefaces by primefaces.
the class FileUploadFilter method init.
@Override
public void init(FilterConfig filterConfig) throws ServletException {
String uploader = filterConfig.getServletContext().getInitParameter(Constants.ContextParams.UPLOADER);
if (uploader == null || "auto".equals(uploader)) {
PrimeEnvironment environment = new StartupPrimeEnvironment();
bypass = environment.isAtLeastJsf22();
} else if ("native".equals(uploader)) {
bypass = true;
} else if ("commons".equals(uploader)) {
bypass = false;
}
thresholdSize = filterConfig.getInitParameter(THRESHOLD_SIZE_PARAM);
uploadDir = filterConfig.getInitParameter(UPLOAD_DIRECTORY_PARAM);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("FileUploadFilter initiated successfully");
}
}
use of org.primefaces.config.PrimeEnvironment in project primefaces by primefaces.
the class PostConstructApplicationEventListener method processEvent.
@Override
public void processEvent(SystemEvent event) throws AbortProcessingException {
// temp manually instantiate as the ApplicationContext is not available yet
PrimeEnvironment environment = new StartupPrimeEnvironment();
LOGGER.log(Level.INFO, "Running on PrimeFaces {0}", environment.getBuildVersion());
if (environment.isAtLeastJsf23()) {
Jsf23Helper.addSearchKeywordResolvers();
}
}
use of org.primefaces.config.PrimeEnvironment in project primefaces by primefaces.
the class WidgetBuilderTest method attributeDefaultValueIsNotEncoded.
@Test
public void attributeDefaultValueIsNotEncoded() throws IOException {
CollectingResponseWriter writer = new CollectingResponseWriter();
FacesContext context = new FacesContextMock(writer);
PrimeConfigurationMock config = new PrimeConfigurationMock(context, new PrimeEnvironment(context));
config.setMoveScriptsToBottom(true);
WidgetBuilder builder = new WidgetBuilder(context, config);
Panel panel = mock(Panel.class);
when(panel.resolveWidgetVar(context)).thenReturn("myComponent");
when(panel.getClientId(context)).thenReturn("myComponent1");
builder.init("MyComponent", panel);
String defaultValue = "'My custom default value'";
builder.attr("someAttribute", null, defaultValue);
builder.finish();
String output = writer.toString();
assertFalse(output.contains(defaultValue));
String expectedOutput = "<script id=\"myComponent1_s\" type=\"text/javascript\">PrimeFaces" + ".cw(\"MyComponent\",\"myComponent\",{id:\"myComponent1\"});</script>";
assertEquals(expectedOutput, output);
}
use of org.primefaces.config.PrimeEnvironment in project primefaces by primefaces.
the class WidgetBuilderTest method attrJavascriptEscapeJavascript.
@Test
public void attrJavascriptEscapeJavascript() throws IOException {
CollectingResponseWriter writer = new CollectingResponseWriter();
FacesContext context = new FacesContextMock(writer);
PrimeConfigurationMock config = new PrimeConfigurationMock(context, new PrimeEnvironment(context));
config.setMoveScriptsToBottom(true);
WidgetBuilder builder = new WidgetBuilder(context, config);
Panel panel = mock(Panel.class);
when(panel.resolveWidgetVar(context)).thenReturn("myComponent");
when(panel.getClientId(context)).thenReturn("myComponent1");
builder.init("MyComponent", panel);
builder.attr("someAttribute", "<script>alert('Hello World!')</script>", null);
builder.finish();
String output = writer.toString();
String expectedOutput = "<script id=\"myComponent1_s\" type=\"text/javascript\">PrimeFaces" + ".cw(\"MyComponent\",\"myComponent\",{id:\"myComponent1\"," + "someAttribute:\"<script>alert(\\x27Hello World!\\x27)<\\/script>\"});</script>";
assertEquals(expectedOutput, output);
}
Aggregations