AjaxRenderKitFactory is blocking AJAX in my web project - ajax

I am facing an issue related to Ajax in JSF 2.0
We have 2 web projects (WARs) in the same EAR. the first project is having the following in the faces-config.xml
<factory>
<faces-context-factory>
com.ibm.faces.context.AjaxFacesContextFactory
</faces-context-factory>
<render-kit-factory>
com.ibm.faces.renderkit.AjaxRenderKitFactory
</render-kit-factory>
</factory>
For some reason, the com.ibm.faces.renderkit.AjaxRenderKitFactory is blocking ajax in the other web project, if I removed this section, ajax works fine.
I mean by Ajax here, the rendering for
<h:form>
<h:selectOneMenu value="#{myBean.selected}">
<f:selectItem itemValue="#{null}" itemLabel="ABC" />
<f:selectItem itemValue="one" />
<f:selectItem itemValue="two" />
<f:selectItem itemValue="three" />
<f:ajax listener="#{myBean.listener}" render="result" />
</h:selectOneMenu>
<h:outputText id="result" value="#{myBean.selected} #{myBean.result}" />
but the following is working fine
<h:commandButton value="commandButton" action="#{myBean.submit}">
<f:ajax listener="#{myBean.listener}" render="result" />
</h:commandButton>
<h:outputText id="result" value="#{myBean.selected} #{myBean.result}" />
I am not having this com.ibm.faces.renderkit.AjaxRenderKitFactory in my faces-config so why it is affecting Ajax in my project?

The com.ibm.faces.renderkit.AjaxRenderKitFactory is designed to enable ajax support in jurassic JSF 1.x versions which didn't have built-in ajax support.
Since JSF 2.0 (Dec 2009), JSF got built-in ajax support with the new <f:ajax> tag. Therefore, external ajax libraries designed for JSF 1.x such as those from IBM becomes unnecessary and they would possibly even conflict, as you faced.
Just remove it altogether. In JSF 2.x and newer you don't need external libraries to use ajax. Moreover, you should upgrade any JSF 1.x component libraries to a JSF 2.x compatible one.

Related

Why is the action attribute of a commandButton not working with ajax render

This commandButton is working:
<h:commandButton id="button_updateIt" value="#{i18n.button_update_it}"
action="#{masterBean.update()}">
</h:commandButton>
This ajax call is working:
<h:commandButton id="button_updateIt" value="#{i18n.button_update_it}">
<f:ajax event="click" render=":form_2:updateMe" />
</h:commandButton>
Why is the action attribute combined with ajax not working?
<h:commandButton id="button_updateIt"
value="#{i18n.button_update_it}"
action="#{masterBean.update()}">
<f:ajax event="click" render=":form_2:updateMe" />
</h:commandButton>
I use jsf version 2.1.1 and java 1.7.0 and GlassFish Server 3.1.2 (build 23)
Why you're using the click event? Your form is rerendered before the action method is invoked if you're using that event.
You need to either change the event type or you need to use an listener in the f:ajax click event instead of the action in the commandButton.
<h:commandButton id="button_updateIt"
value="#{i18n.button_update_it}"
action="#{masterBean.update()}">
<f:ajax render=":form_2:updateMe" />
</h:commandButton>
or
<h:commandButton id="button_updateIt"
value="#{i18n.button_update_it}">
<f:ajax event="click" listener="#{masterBean.update()}"
render=":form_2:updateMe" />
</h:commandButton>

Spring Multipart/Form-data csrf issue

i've been having issues with csrf validation with a multipart/form-data type of form, since it didnt let me authenticate nor upload my files, returning a 403 when trying to execute the call.
After some reseach i've found that supposedly, "multipart/form-data" forms have trouble with csrf, and thus i had to add the
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
annotation to each form in my .xhtml file.
(Also tried the form action='', variation)
And yet it kept returning that my csrf value was null
after some more research, i've tried adding the SpringMultipartFilter
<filter>
<display-name>springMultipartFilter</display-name>
<filter-name>springMultipartFilter</filter-name>
<filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>springMultipartFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
and also stated the filterMultipartResolver bean in the application context of the presentation part:
<bean id="filterMultipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="-1" />
</bean>
and after doing that, Chrome did let me validate my user, and did let me press the upload button, returning a 200 (OK) code
but, the file is not getting uploaded and debugging shows that my methods are not being called, consoles are not returning an error both Java nor Chrome Debug console, so im a little lost any help to solve or to get actual knowledge of what is happening would be appreciated, thanks.
Im using Spring+Primefaces+Maven.
Upload form in .xhtml:
<h:form id="uploadForm" enctype="multipart/form-data">
<input type="hidden" name="${_csrf.parameterName}"
value="${_csrf.token}" />
<p:fieldset id="uploadBlock"
legend="#{message['cmb.title1.text.label']}">
<br />
<h:panelGroup layout="block"
style="float : left; margin-right : 10%;">
<h:panelGrid id="display1">
<p:fileUpload update=":tableForm:comparisonTable #this"
fileUploadListener="#{ComparisonCSVController.upload}"
allowTypes="/(\.|\/)(csv)$/i" mode="advanced" fileLimit="1"
description="Select a csv file">
</p:fileUpload>
</h:panelGrid>
</h:panelGroup>
</p:fieldset>
<br />
</h:form>
Im certain its not a problem with the actual methods of my beans or my beans, since everything was working till i enabled spring security, and if i turn it off, everything runs smooth, but i need it enabled, so im facing this problem.
Fixed after messing with the order of the filters in the web.xml.
The order has to be:
- Primefaces filter- (i did edit out a FORWARD tag)
- MultiPart filter-
- Spring Filter -
- Prettyfaces filter, with ASYNC tag on-
Thank you.

How to use Spring Webflow popup="true" with Primefaces?

Until now we were using Spring Webflow 2.3, which brought the "sf" namespace and Spring.js, which could be used to display view-states in a popup.
Webflow 2.4 deprecated Spring.js and removed the taglib with the following statement:
Previous releases of Spring Web Flow shipped with a component library which provided Ajax and client-side validation capabilities for JSF 1.2 environments. Applications using these components will need to switch to a 3rd party JSF component library such as PrimeFaces or RichFaces.
See: http://docs.spring.io/spring-webflow/docs/current/reference/htmlsingle/#spring-faces-upgrade-from-swf23-components
Now i have added a dependency to Primefaces 5.2 to my pom.xml and everything seems to work fine, except for SWF Popups, which simply redirect to the new view-state.
First page:
<ui:composition template="#{templatePath}"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<h:form id="formDashboard">
<p:commandButton id="addWidget" value="Hinzufügen" action="add-widget"/>
</h:form>
</ui:define>
</ui:composition>
Second page (should be rendered in a popup):
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<ui:fragment id="popupFragment">
abc
</ui:fragment>
</ui:composition>
Flow definition:
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow.xsd">
<view-state id="start" view="dashboard.xhtml">
<transition on="add-widget" to="popup-addWidget"/>
</view-state>
<view-state id="popup-addWidget" view="popup-addWidget.xhtml" popup="true">
<on-render>
<render fragments="popupFragment"/>
</on-render>
</view-state>
</flow>
Spring configuration:
<bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor"/>
</bean>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry"/>
</bean>
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<webflow:flow-execution-listeners>
<webflow:listener ref="facesContextListener"/>
</webflow:flow-execution-listeners>
</webflow:flow-executor>
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices"/>
<!-- Populates the flowRegistry on startup. Removing this and manually adding all flows changes nothing. -->
<bean class="config.FlowRegisteringBeanPostProcessor"/>
<faces:flow-builder-services id="flowBuilderServices"/>
<faces:resources/>
<bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>
I'm not including the web.xml, since there is nothing special.
Using Mojarra 2.2, Primefaces 5.2, Spring 4.2 and Webflow 2.4.1.
Using Firebug i can see that the server POST response issues to redirect, which JSF/Primefaces honors and does a full redirect to the new view-state instead of showing a popup:
<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1"><redirect url="/Demo/spr/dashboard?execution=e1s2"></redirect></partial-response>
If anybody managed to get popup="true" working with these versions, with or without Spring.js, i'd be happy to hear about it.
We ended up using Primefaces' p:dialog and p:confirmDialog, instead of Webflow popups.
This doesn't really answer my question, but i can't see an answer to this seeing that Webflow sends the same response no matter if popup is set to true or false.

JSF 2.2.10: The f:ajax execute="#this" doesn't process h:selectBooleanCheckbox

I was using the Wildfly with JSF version 2.2.8-jboss.org version of this server. After migrating to JBoss EAP 6.3.x, packaging version of the JSF 2.2.9, 2.2.10 or 2.2.11 is happening the following:
If I use the attribute execute as below, the map #{mBean.mapa} is no longer updated.
<h:selectBooleanCheckbox id="chkAtividade" value="#{mBean.mapa[atividade]}" title="#{atividade.nome}">
<f:ajax event="click" execute="#this" render=":form:panelBotoes" />
</h:selectBooleanCheckbox>
I had to change to execute="#form" to get it to function.
<h:selectBooleanCheckbox id="chkAtividade" value="#{mBean.mapa[atividade]}" title="#{atividade.nome}">
<f:ajax event="click" execute="#form" render=":form:panelBotoes" />
</h:selectBooleanCheckbox>
Does anyone know why? In newer versions of the JSF, was there a change in behavior <h:selectBooleanCheckbox> with <f:ajax>? This looks like a bug.

Java Web: How use JSP with JSF and Ajax?

i'm working in a project with jsp, i need to start to use ajax too.
i'm enjoying jsf , is possible work with these together (JSP, JSF and AJAX) ?
I'm asking this cause i could run jsf with ajax
<h:commandButton id="bt_save" value="Save" title="Save" action="#personMBean.clickSave()}">
<f:ajax execute="#form" render="lblMessage" />
</h:commandButton>
<br/>
<h:outputLabel id="lblMessage" value="#{personMBean.message}" />
But when i try input this code in my jsp page it doesn't work, even if i insert on my jsp page:
<%#page contentType="text/html"%>
<%#page pageEncoding="UTF-8"%>
<%#taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%#taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
Any ideas ?
Ensure that you're using JSF 2.x (the <f:ajax> doesn't exist in JSF 1.x) and that you've a <h:head> instead of <head> in the master template (so that JSF can auto-include necessary Ajax JavaScripts).
Said that, you should really consider Facelets as replacement of JSP. JSP is an outdated view technology and ill suited for templating and has been replaced by Facelets as per JSF 2.0 / Java EE 6.
Yes - try richfaces or primefaces
I don't see why you couldn't do this but certainly not on the same page.
To do this you need to map the *.jsp extension to the JSP servlet while mapping the *.jsf or *.xhtml to FacesServlet.

Resources