f:ajax è un tag JSF che aggiunge il meccanismo delle request asincrone a molti componenti UI.
Per passare dei parametri viene aggiunto il tag f:param
pagina con supporto ajax:
ProvaAjax.xhmtl
<html xmlns=”http://www.w3.org/1999/xhtml”
xmlns:f=”http://java.sun.com/jsf/core”
xmlns:h=”http://java.sun.com/jsf/html”
xmlns:ui=”http://java.sun.com/jsf/facelets”
xmlns:p=”http://primefaces.org/ui”
xmlns:c=”http://java.sun.com/jsp/jstl/core”>
<h:head/>
<h:body>
<h:form>
<input type=”hidden” name=”id2″ id=”id2″ value=”55″ />
<h:commandLink value=”ssss”>
<f:param name=”id” value=”44″ />
<f:ajax listener=”#{galleriaBean.countListener}”>
</f:ajax>
</h:commandLink>
</h:form>
</h:body>
</html>
nel tag f:ajax:
GalleriaBean.java
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;
@ManagedBean
@SessionScoped
public class GalleriaBean {
public void countListener(AjaxBehaviorEvent event) {
System.out.println(“test:”);
String id = FacesContext.getCurrentInstance().getExternalContext()
.getRequestParameterMap().get(“id”);
System.out.println(“id:” + id);
}
}
aprendo l’indirizzo: http://localhost:8080/JSFProject/faces/ProvaAjax.xhtml