p:media problems with stream and autoplay - jsf

I got a datatable with a list of files, some of them are sound files. If I use a stream Firebug say a Network error 404. I made it work by writing the files (but param autoplay=false don't work), but its an ugly workaround, I'm probably missing something to make stream work.
Firebug says :
"NetworkError: 404 not found - http://localhost:8080/Projet/javax.faces.resource/dynamiccontent.properties.xhtml?ln=primefaces&v=5.3&pfdrid=1G8w72KY96Ob6Ye0QRtzBg%3D%3D&pfdrt=sc&pfdrid_c=true"
<p:dataTable var="doc" value="#{besoin.document}" id="besoinTableDocument"
draggableColumns="true" resizableColumns="true"
scrollable="true" scrollHeight="150"
selectionMode="single" rowKey="#{doc.id}">
<f:facet name="header">
<p:commandButton value="Upload" icon="ui-icon-extlink" onclick="PF('dlgupload').show();">
<f:attribute name="filId" value="0" />
</p:commandButton>
</f:facet>
<br/>
<p:column sortBy="nom" headerText="Nom">
<h:outputText value="#{doc.nom}" />
</p:column>
<p:column>
<p:commandButton icon="ui-icon-search" title="Télécharger" ajax="false" actionListener="#{documentBacking.makeFile}">
<f:attribute name="doc" value="#{doc}"/>
<p:fileDownload value="#{documentBacking.file}" />
</p:commandButton>
<p:commandButton icon="ui-icon-trash" title="Supprimer" ajax="true" actionListener="#{besoinView.deleteDocument}" update="besoinTableDocument">
<p:confirm header="Confirmation" message="Valider la suppression" icon="ui-icon-alert" />
<f:attribute name="doc" value="#{doc}"/>
</p:commandButton>
</p:column>
<p:column>
<<p:media value="/resources/sound/#{doc.nom}" player="quicktime" rendered="#{doc.sound}" width="200" height="30" >
<f:param name="autoPlay" value="false"/>
</p:media>
<p:media value="#{doc.stream}" player="quicktime" width="180" height="30" rendered="#{doc.sound}"/>
<f:param name="autoPlay" value="false"/>
</p:media>
</p:column>
</p:dataTable>
ManagedBean
#ManagedBean
#RequestScoped
public class Document implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private Besoin besoin;
private String nom;
private Blob blob;
private boolean sound;
private StreamedContent stream;
public Document(ResultSet rs, Besoin bean) throws SQLException {
this.id = rs.getInt("DOC_ID");
this.nom = rs.getString("DOC_NOM");
this.blob = rs.getBlob("DOC_BLOB");
this.besoin = bean;
this.sound = FilenameUtils.getExtension(nom).matches("^(ogg|mp3|mp4)$");
InputStream in = blob.getBinaryStream();
String mime = FacesContext.getCurrentInstance().getExternalContext().getMimeType(nom);
this.stream = (sound?new DefaultStreamedContent(in, mime):null);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Besoin getBesoin() {
return besoin;
}
public void setBesoin(Besoin besoin) {
this.besoin = besoin;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public Blob getBlob() {
return blob;
}
public void setBlob(Blob blob) {
this.blob = blob;
}
public boolean isSound() {
return sound;
}
public void setSound(boolean sound) {
this.sound = sound;
}
public StreamedContent getStream() {
return stream;
}
public void setStream(StreamedContent stream) {
this.stream = stream;
}
}

Related

Primefaces subTable in dataTable not working

i am pretty new to jsf and i'm having a bit trouble implementing a subTable in my dataTable. Der var atribute from my subtable doesn't seem to evaluate to the elements from the list. Also the #PostConstruct method from my backing bean isn't called either, when i execute my webapp and navigate to the xhtml site. No errors are shown in the console, so i have pretty much no idea what i did wrong.
Backing Bean
#Named(value = "selfEvalBean")
#ViewScoped
public class SelfEvaluationBean extends AbstractBean implements Serializable {
private static final long serialVersionUID = 310401011219411386L;
private static final Logger logger = Logger.getLogger(SelfEvaluationBean.class);
#Inject
private ISelfEvaluationManager manager;
private List<SelfEvaluation> selfEvaluations;
private SelfEvaluationTopic topic;
public List<SelfEvaluation> getSelfEvaluations() {
return selfEvaluations;
}
public void setSelfEvaluation(final List<SelfEvaluation> theSelfEvaluations) {
selfEvaluations = theSelfEvaluations;
}
#PostConstruct
public void init() {
if (!isLoggedIn()) {
return;
}
final User user = getSession().getUser();
List<SelfEvaluation> eval = user.getSelfEvaluations();
if (eval == null) {
eval = manager.createSelfEvaluation(user);
}
selfEvaluations = eval;
topic = new SelfEvaluationTopic();
}
//some methods
/**
* #return the topic
*/
public SelfEvaluationTopic getTopic() {
return topic;
}
/**
* #param theTopic
*/
public void setTopic(final SelfEvaluationTopic theTopic) {
topic = theTopic;
}
}
SelEvaluation Class
#Entity
public class SelfEvaluation extends JPAEntity implements Serializable {
private static final long serialVersionUID = 1L;
#ManyToOne
private User user;
#Column
private String title;
#OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private List<SelfEvaluationTopic> topics = new ArrayList<>();
public User getUser() {
return user;
}
public void setUser(final User theUser) {
user = theUser;
public List<SelfEvaluationTopic> getTopics() {
return topics;
}
public void setTopics(final List<SelfEvaluationTopic> theTopics) {
topics = theTopics;
}
public void addSelfEvalTopic(final SelfEvaluationTopic theTopic) {
topics.add(theTopic);
}
public void removeSelfEvalTopic(final SelfEvaluationTopic theTopic) {
topics.remove(theTopic);
}
#Override
public boolean equals(final Object theObject) {
if (!(theObject instanceof SelfEvaluation)) {
return false;
}
final SelfEvaluation other = (SelfEvaluation) theObject;
return getId().equals(other.getId());
}
public String getTitle() {
return title;
}
public void setTitle(final String title) {
this.title = title;
}
#Override
public int hashCode() {
return getId().hashCode();
}
#Override
public String toString() {
return String.format("SelfEvaluation {id: %d, from: %s}", getId(),
user.getUsername());
}
}
SelfEvaluationTopic Class
#Entity
public class SelfEvaluationTopic extends JPAEntity implements Serializable {
private static final long serialVersionUID = 1L;
#Column(nullable = false)
private String topic;
#Column
private boolean sad;
#Column
private boolean normal;
#Column
private boolean happy;
public String getTopic() {
return topic;
}
public void setTopic(final String theTopic) {
topic = assertNotNull(theTopic);
}
public boolean getSad() {
return sad;
}
public void setSad(final boolean evaluation) {
sad = evaluation;
}
public boolean getNormal() {
return normal;
}
public void setNormal(final boolean evaluation) {
normal = evaluation;
}
public boolean getHappy() {
return happy;
}
public void setHappy(final boolean evaluation) {
happy = evaluation;
}
#Override
public boolean equals(final Object theObject) {
if (!(theObject instanceof SelfEvaluationTopic)) {
return false;
}
final SelfEvaluationTopic other = (SelfEvaluationTopic) theObject;
return getId().equals(other.getId());
}
#Override
public int hashCode() {
return getId().hashCode();
}
#Override
public String toString() {
return String
.format("SelfEvaluationTopic {id: %d, topic: %s, sad: %b, normal: %b, happy: %b}",
getId(), topic, sad, normal, happy);
}
}
XHTML Site
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="templates/template.xhtml">
<!--header and footer template-->
<ui:define name="content">
<f:loadBundle basename="internationalization.selfEval" var="msg" />
<h:form id="form">
<p:growl id="info" autoUpdate="true" />
<p:dataTable id="selfEval" var="eval" value="#{selfEvalBean.selfEvaluations}" >
<f:facet name="header">
#{msg['header']}
</f:facet>
<p:columnGroup type="header">
<p:row>
<p:column>
<f:facet name="header">#{msg['selfEval']}</f:facet>
</p:column>
<p:column width="2%">
<f:facet id="sad" name="header">
<p:graphicImage library="images" name="sad.png"/>
</f:facet>
</p:column>
<p:column width="2%">
<f:facet id="sad" name="header">
<p:graphicImage library="images" name="normal.png"/>
</f:facet>
</p:column>
<p:column width="2%">
<f:facet id="sad" name="header">
<p:graphicImage library="images" name="happy.png"/>
</f:facet>
</p:column>
</p:row>
</p:columnGroup>
<p:subTable var="t" value="#{eval.topics}">
<f:facet name="header">
<h:outputText value="#{eval.title}" />
</f:facet>
<p:column id="topic" >
<h:outputText value="#{t}" /> <!--t is of type List<SelfEvaluation> and not SelfEvaluationTopic-->
<p:commandButton style="float:right; width:22px; height: 22px; background-color: #cd001e;" title="Delete" update=":form" action="#{selfEvalBean.remove(t)}" icon="fa fa-trash-o" />
</p:column>
<p:column width="2%" >
<div style="text-align: center;" >
<p:selectBooleanCheckbox id="s" value="#{t}" />
</div>
</p:column>
<p:column width="2%" >
<div style="text-align: center;" >
<p:selectBooleanCheckbox id="n" value="#{t}" />
</div>
</p:column>
<p:column width="2%" >
<div style="text-align: center;" >
<p:selectBooleanCheckbox id="h" value="#{t}" />
</div>
</p:column>
</p:subTable>
</p:dataTable>
<center>
<p:commandButton id="addSelfEvalTopic" styleClass="button" value="#{msg['actionAdd']}" onclick="PF('evalDialog').show();" update=":form" />
<p:commandButton id="selection" styleClass="button" style="float:right;" value="#{msg['actionSelect']}" action="#{selfEvalBean.save}" />
</center>
</h:form>
<p:dialog widgetVar="evalDialog" header="#{msg['newTopic']}" showEffect="clip" hideEffect="clip" resizable="false">
<h:form id="dialog">
<h:panelGrid columns="2">
<p:outputLabel value="Description:" />
<p:inputText value="#{selfEvalBean.topic.topic}" required="true" maxlength="60" />
<p:commandButton value="#{msg['actionSave']}" styleClass="button" action="#{selfEvalBean.addTopic}" update=":form" oncomplete="PF('evalDialog').hide();" />
<p:commandButton value="#{msg['actionCancel']}" styleClass="button" immediate="true" oncomplete="PF('evalDialog').hide();" />
</h:panelGrid>
</h:form>
</p:dialog>
</ui:define>
</ui:composition>
Manager Class fills the Database with some initial data, so there is nothing really interesting going on.
JSF version is 2.2.12 and PrimeFaces version is 6.0.
I'm using Maven for build and the webapp is running on GlassFish 4.1.1.

primefaces selectCheckboxMenu empty selected list

I'm trying to get selected values from a selectCheckboxMenu, but always the selection list is empty. this's my jsf form:
<h:form id="form">
<p:dataTable id="singleDT" var="user" value="#{roleBean.users}"
rowKey="#{roleBean.users}" rows="12" paginator="true"
rowsPerPageTemplate="12,15,22" paginatorPosition="bottom"
emptyMessage="Aucun compte présent." reflow="true"
editable="false" selectionMode="single">
<p:column headerText="Login" filterBy="#{user.username}">
<h:outputText value="#{user.username}" />
</p:column>
<p:column headerText="Nom" filterBy="#{user.lastname}">
<h:outputText value="#{user.lastname}" />
</p:column>
<p:column headerText="Prénom" filterBy="#{user.firstName}">
<h:outputText value="#{user.firstName}" />
</p:column>
<p:column headerText="Email" filterBy="#{user.emal}">
<h:outputText value="#{user.emal}" />
</p:column>
<p:column headerText="Affécter Roles">
<p:selectCheckboxMenu id="menu" value="#{roleBean.rolesselected}"
label="Roles"
filter="false" filterMatchMode="startsWith"
panelStyle="width:135px" converter="#{roleconvertor}" immediate="true" >
<f:selectItems value="#{roleBean.roles}" var="n"
itemValue="#{n}" itemLabel="#{n.description}"
itemDescription="#{n.rolename}" />
</p:selectCheckboxMenu>
</p:column>
<p:column width="90">
<p:commandButton styleClass="ui-yelbutton" immediate="true" process="#form" value="Valider"
title="Remove"
ajax="true" action="#{roleBean.addrole(user)}" />
</p:column>
</p:dataTable>
</h:form>
Here's the managedBean related. when I run the jsf page I show the list of value and I can check it. also tne converter was worked but when I try to test a size of selectedrole it's always 0.
public class RoleBean implements Serializable {
#Autowired
UserCatalogueService userservice;
#Autowired
Roleservice roleservice;
List< Role> roles;
List<UserCatalogue> users ;
private static final long serialVersionUID = 1L;
String notification;
private List<Role> rolesselected = new ArrayList<Role>();
#PostConstruct
public void init() {
roles=roleservice.findAll();
}
public List<Role> getRolesselected() {
return rolesselected;
}
public void setRolesselected(List<Role> rolesselected) {
this.rolesselected = rolesselected;
}
public List<UserCatalogue> getUsers() {
List<UserCatalogue> users= userservice.findAll();
List<UserCatalogue> users1= userservice.findAll();
users1.clear();
for(int i=0; i< users.size(); i++)
{
if(users.get(i).getRoles().size()==0)
{
System.out.println(users.get(i).getFirstName()+ "est un nouvel utilisateur");
//users.remove(i);
users1.add(users.get(i));
}
}
return users1;
}
public String getNotification() {
notification=getUsers().size()+" Alerts";
return notification;
}
public void setNotification(String notification) {
this.notification = notification;
}
public void setUsers(List<UserCatalogue> users) {
this.users = users;
}
public List<Role> getRoles() {
return roleservice.findAll();
}
public void setRoles(List<Role> roles) {
this.roles = roles;
}
public void addrole( UserCatalogue user)
{
System.out.println("the size of list is "+rolesselected.size());
}
}
Try to change rolesselected from List to array using the []

jsf2 make datatable row editable does show inputtext fields

I am trying to edit a datatable row with JSF2. In debugging the editAction is showing the correct row, but the outputtext is not transformed into inputtext to allow editing, There seems to be a rendering problema executing the edit action. My bean is sessionscoped and when hitting one of the buttons (edit, add, delete, cancel) the method getListaNoticias is executed as many times as there are inputfields.
My code:
historial.xhtml
<h:form>
<h:dataTable styleClass="tablaHistorial"
value="#{historialBean.listaNoticias}" var="o">
<h:column>
<f:facet name="header">Fecha</f:facet>
#{o.fecha}
</h:column>
<h:column>
<f:facet name="header">Noticia</f:facet>
<h:inputTextarea value="#{o.titulo}" rendered="#{o.editable}"/>
<h:outputText value="#{o.titulo}" rendered="#{not o.editable}" />
</h:column>
<h:column>
<h:commandButton action="#{historialBean.editAction(o)}">
<f:ajax render="#form" />
</h:commandButton>
</h:column>
<h:column>
<h:commandButton action="#{historialBean.save(o)}">
<f:ajax render="#form" execute="#form" />
</h:commandButton>
</h:column>
<h:column>
<h:commandButton action="#{historialBean.cancelarAccion(o)}">
<f:ajax render="#form" />
</h:commandButton>
</h:column>
<h:column>
<h:commandButton action="#{historialBean.borrar(o)}">
<f:ajax render="#form" />
</h:commandButton>
</h:column>
</h:dataTable>
</h:form>
historialBean class
#ManagedBean
#SessionScoped
public class HistorialBean implements Serializable {
private static final long serialVersionUID = 1L;
public List<Noticia> listaNoticias;
public HistorialBean() {
}
public String irAConsola() {
return navigationBean.redirectToLoggedIn();
public List<Noticia> getListaNoticias() {
ConexionUtil conexion = new ConexionUtil();
listaNoticias = new ArrayList<Noticia>();
listaNoticias = conexion.prepararListaNoticiasBBDDExterna();
return listaNoticias;
}
public void setListaNoticias(List<Noticia> listaNoticias) {
this.listaNoticias = listaNoticias;
}
public void editAction(Noticia noticia) {
noticia.setEditable(true);
}
public void editar(Noticia noticia) {
ConexionUtil conexion = new ConexionUtil();
conexion.editarNoticiaBBDDExterna(noticia);
noticia.setEditable(false);
}
public void borrar(Noticia noticia) {
ConexionUtil conexion = new ConexionUtil();
conexion.deshabilitarNoticiaBBDDExterna(noticia);
}
public void cancelarAccion(Noticia noticia) {
noticia.setEditable(false);
}
}
Noticia class
public class Noticia {
private String titulo;
private String fecha;
private boolean editable;
public Noticia(String titulo,String fecha) {
super();
this.titulo = titulo;
this.fecha = fecha;
}
public String getTitulo() {
return titulo;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
public String getFecha() {
return fecha;
}
public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
}
}
At the end I solved it putting the creation of the list in the bean constructor:
public HistorialBean() {
ConexionUtil conexion = new ConexionUtil();
listaNoticias = new ArrayList<Noticia>();
listaNoticias = conexion.prepararListaNoticiasBBDDExterna();
}
public List<Noticia> getListaNoticias() {
return listaNoticias;
}

Avoid loading datatable each time when i make an ajax call by clicking on each row

In JSF2 - I see my datatable reloading each time when i make an ajax call by clicking on each column row. Is there a way to stop loading each time i make an ajax call ? This creates problem by resetting my datatable to default values and i get a wrong value back at managed bean.
<h:inputText size="8" id="startDate"
value="#{contactBean.startDate}">
<f:convertDateTime pattern="MM/dd/yyyy" type="date" />
</h:inputText>
<h:outputText> - </h:outputText>
<h:inputText size="8" id="endDate" value="#{contactBean.endDate}">
<f:convertDateTime pattern="MM/dd/yyyy" type="date" />
</h:inputText>
<h:commandButton value="Filter"
actionListener="#{contactBean.loadAJAXFilterContentList}">
<f:ajax render=":form1:tableContents" />
</h:commandButton>
<h:dataTable id="tableContents"
value="#{contactBean.filterContentList}" var="crs"
binding="#{contactBean.dataTable}" border="1">
<h:column>
<f:facet name="header">
<h:outputText styleClass="contactTableHeader" value="Date/Time" />
</f:facet>
<h:commandLink action="#{contactBean.loadPreviewScreenContents(crs)}">
<h:outputText title="#{crs.dateTime}" value="#{crs.dateTime}">
<f:convertDateTime pattern="MM/dd/yyyy hh:mm a" type="date" />
</h:outputText>
<f:ajax render=":form1:previewScreen" />
</h:commandLink>
</h:column>
</h:dataTable>
<h:panelGrid id="previewScreen">
<h:outputText styleClass="PreviewHeader"
value="Preview of #{contactBean.previewCntDateTime}" />
</h:panelGrid>
So in the above case whenever i click the column it calls the filterContentList() method in my managed bean instead of calling loadPreviewScreenContents(crs) directly.
My bean is RequestScoped. I tried with SessionScope,ViewScope but these 2 scopes retain my previous states like i have other ajax functions in my page and it retains that state. So i cant use Session or ViewScopes in this case.
Is there a solution ?
Bean code:
#ManagedBean(name = "contactBean")
#RequestScoped
public class ContactManagedBean implements Serializable {
private static final long serialVersionUID = 1L;
List<ContactResponseBean> filterContentList = new ArrayList<ContactResponseBean>();
ContactRequestBean contactRequestBean = new ContactRequestBean();
ContactResponseBean crs = new ContactResponseBean();
private String logText;
HtmlDataTable dataTable;
public void setFilterContentList(List<ContactResponseBean> filterContentList) {
this.filterContentList = filterContentList;
}
public void setFilterContentList(List<ContactResponseBean> filterContentList) {
this.filterContentList = filterContentList;
}
public Date getPreviewCntDateTime() {
return previewCntDateTime;
}
public void setPreviewCntDateTime(Date previewCntDateTime) {
this.previewCntDateTime = previewCntDateTime;
}
public String getLogText() {
return logText;
}
public void setLogText(String logText) {
this.logText = logText;
}
public HtmlDataTable getDataTable() {
return dataTable;
}
public void setDataTable(HtmlDataTable dataTable) {
this.dataTable = dataTable;
}
public ContactResponseBean getCrs() {
return crs;
}
public void setCrs(ContactResponseBean crs) {
this.crs = crs;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public void loadAJAXFilterContentList() {
filterButtonAjxFlag = true;
}
public List<ContactResponseBean> getFilterContentList() {
ContactRequestBean contactRequestBean = new ContactRequestBean();
contactRequestBean.setUserId(getUserId());
contactRequestBean.setSummaryType(getSummaryType());
contactRequestBean.setStartDate(getStartDate());
contactRequestBean.setEndDate(getEndDate());
ContactRequestBeanService crbs = new ContactRequestBeanService();
filterContentList = crbs.getFilterContentList(contactRequestBean);
return filterContentList;
}
public void loadPreviewScreenContents(){
crs = (ContactResponseBean) dataTable.getRowData();
setPreviewCntDateTime(crs.getDateTime());
}
}

Primefaces actionbutton called several times

I've been strugling with an issue I can't find the way to solve it and I can't find anything related on the web.
I'm using Netbeans with Primefaces to develop a JSF web app.
Everything works fine except that sometimes the call to the actionlisteners is being done several times.
For example this is my JSF page with primefaces:
<h:body>
<ui:composition template="home.xhtml">
<ui:define name="content">
<h2>Administración de alertas SMS</h2>
<p:panel id="display">
<p:selectBooleanCheckbox itemLabel="Enviar alertas SMS" value="#{smsConfigBean.alertsEnabled}"/>
<p>
<h:outputText value="Mensaje de Texto: " /><br /><br />
<p:inputTextarea rows="5" cols="50" counterTemplate="{0} caracteres restantes." counter="counter" maxlength="160" value="#{smsConfigBean.smsMessage}" id="smsMessage"/>
<br />
<h:outputText id="counter" />
</p>
<p>
<h:outputText value="Dispositivo de envio SMS: " />
<p:selectOneRadio id="options" value="#{smsConfigBean.usePhone}">
<f:selectItem itemLabel="Modem USB" itemValue="false" />
<f:selectItem itemLabel="Telefono Android" itemValue="true" />
</p:selectOneRadio>
</p>
<br />
<p:tabView id="tabView">
<p:tab id="tab1" title="Modem USB">
<h:panelGrid id="modemGrid" columns="2" cellpadding="4">
<h:outputText value="Puerto: " />
<p:inputText id="port" value="#{smsConfigBean.port}"/>
<h:outputText value="Bit Rate (Opcional): " />
<p:inputText id="bitRate" value="#{smsConfigBean.bitRate}"/>
<h:outputText value="Nombre de modem (Opcional): " />
<p:inputText id="modemName" value="#{smsConfigBean.modemName}"/>
<h:outputText value="PIN: " />
<p:inputText id="pin" value="#{smsConfigBean.modemPin}"/>
<h:outputText value="Centro de Mensajes: " />
<p:inputText id="smsc" value="#{smsConfigBean.SMSC}"/>
</h:panelGrid>
</p:tab>
<p:tab id="tab2" title="Telefono Android">
<h:panelGrid id="phoneGrid" columns="2" cellpadding="4">
<h:outputText value="Path ADB:" />
<p:inputText id="adbPath" value="#{smsConfigBean.adbPath}"/>
<h:outputText value="Directorio de Configuracion:" />
<p:inputText id="configPath" value="#{smsConfigBean.configPath}"/>
<h:outputText value="Modo de conexion " />
<p:selectOneRadio id="connectOptions" value="#{smsConfigBean.useWifi}">
<f:selectItem itemLabel="USB" itemValue="false"/>
<f:selectItem itemLabel="WiFi" itemValue="true" />
</p:selectOneRadio>
<h:outputText value="Direccion IP (Solo para WiFi): " />
<p:inputText id="ipDir" value="#{smsConfigBean.ipDir}"/>
</h:panelGrid>
</p:tab>
</p:tabView>
</p:panel>
<br />
<p:commandButton id="saveSmsAlerts" value="Guardar" update="messages" action="#{smsConfigBean.saveChanges}" actionListener="#{smsConfigBean.saveChanges}"/>
</ui:define>
</ui:composition>
</h:body>
And this is my backend bean:
package Beans;
import helpers.Global; import javax.faces.bean.ManagedBean; import
javax.faces.bean.SessionScoped;
#ManagedBean #SessionScoped public class SmsConfigBean {
private Boolean alertsEnabled;
private Boolean usePhone;
private Boolean useWifi;
private String port;
private int bitRate;
private String modemName;
private String modemPin;
private String SMSC;
private String adbPath;
private String configPath;
private String ipDir;
private String smsMessage;
public SmsConfigBean() {
alertsEnabled = Global.getAlertsEnabled();
port = Global.getPort();
bitRate = Global.getBitRate();
modemName = Global.getModemName();
modemPin = Global.getModemPin();
SMSC = Global.getSMSC();
usePhone = Global.getUsePhone();
adbPath = Global.getAdbPath();
configPath = Global.getConfigPath();
useWifi = Global.getUseWifi();
ipDir = Global.getIpDir();
smsMessage = Global.getSmsMessage();
}
public Boolean getAlertsEnabled() {
return alertsEnabled;
}
public void setAlertsEnabled(Boolean alertsEnabled) {
this.alertsEnabled = alertsEnabled;
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = port;
}
public int getBitRate() {
return bitRate;
}
public void setBitRate(int bitRate) {
this.bitRate = bitRate;
}
public String getModemName() {
return modemName;
}
public void setModemName(String modemName) {
this.modemName = modemName;
}
public String getModemPin() {
return modemPin;
}
public void setModemPin(String modemPin) {
this.modemPin = modemPin;
}
public String getSMSC() {
return SMSC;
}
public void setSMSC(String SMSC) {
this.SMSC = SMSC;
}
public Boolean getUsePhone() {
return usePhone;
}
public void setUsePhone(Boolean usePhone) {
this.usePhone = usePhone;
}
public String getAdbPath() {
return adbPath;
}
public void setAdbPath(String adbPath) {
this.adbPath = adbPath;
}
public String getConfigPath() {
return configPath;
}
public void setConfigPath(String configPath) {
this.configPath = configPath;
}
public Boolean getUseWifi() {
return useWifi;
}
public void setUseWifi(Boolean useWifi) {
this.useWifi = useWifi;
}
public String getIpDir() {
return ipDir;
}
public void setIpDir(String ipDir) {
this.ipDir = ipDir;
}
public String getSmsMessage() {
return smsMessage;
}
public void setSmsMessage(String smsMessage) {
this.smsMessage = smsMessage;
}
public void saveChanges(){
Global.setSmsMessage(smsMessage);
Global.setIpDir(ipDir);
Global.setUseWifi(useWifi);
Global.setConfigPath(configPath);
Global.setAdbPath(adbPath);
Global.setUsePhone(usePhone);
Global.setSMSC(SMSC);
Global.setModemPin(modemPin);
Global.setModemName(modemName);
Global.setBitRate(bitRate);
Global.setPort(port);
Global.setAlertsEnabled(alertsEnabled);
Global.sendInfoResponseMessage("Cambios guardados con exito");
}
}
The problem is that when saving the changes of this form by hitting the commandButton 'saveSmsAlerts' the call is being made twice. Resulting in the growl message to be shown twice too.
(You won't see the growl component because it was defined in the template)
This happens also in another page that I did for the same app that uploads a file using fileuploader. The file is uploaded 4 times!!
I'm using chrome to test the application and netbeans to develop it.
You should remove one of action or actionListener attribute.
<p:commandButton id="saveSmsAlerts" value="Guardar" update="messages" action="#{smsConfigBean.saveChanges}"/>
if you remove action attribute you should change the action method signature
<p:commandButton id="saveSmsAlerts" value="Guardar" update="messages" actionListener="#{smsConfigBean.saveChanges}"/>
Like this
public void saveChanges(ActionEvent e){
...
}
here is the difference between action and actionListener
Differences between action and actionListener

Resources