Jsf PrimeFaces. Error during the render response. p:commandButton - jsf

I'm starting to use JSF with primefaces library over an Hibernate project. I've tried to use wizard component to manage a form but, when I click any of the buttons in the wizard, I get the following warning and the action listener is not invoked.
I think the problem is that, in the wizard there are some p:commandButton because when I use h:commandButton, everything works. Could someine explain in what way primefaces commandButton ih different from the standard one, and how could I face this problem? What's different in the rendering process?
Thanks for your help!
Here's the warning:
9-ott-2012 9.50.43 org.apache.myfaces.trinidadinternal.context.PartialViewContextImpl getPartialResponseWriter
AVVERTENZA: getPartialResponseWriter() called during render_reponse. The returned writer is not integrated with PPRResponseWriter
Here's the code of the page:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<h:outputScript name="jsf.js" library="javax.faces" target="head" />
</h:head>
<h:body>
<p:growl id="growl" showDetail="true" sticky="true" />
<h:form>
<p:wizard widgetVar="wiz"
flowListener="#{traduttoreBean.onFlowProcess}">
<p:tab id="personali" title="Info Personali">
<p:panel header="Informazioni Personali">
<h:messages errorClass="error"/>
<h:panelGrid columns="2" columnClasses="label, value" styleClass="grid">
<h:outputText value="Nome: *" />
<p:inputText required="true" label="Nome"
value="#{traduttoreBean.info.nome}" />
<h:outputText value="Cognome: *" />
<p:inputText required="true" label="cognome"
value="#{traduttoreBean.info.cognome}" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="confirm" title="Confirmation">
<p:panel header="Confirmation">
<h:panelGrid id="confirmation" columns="6">
<h:outputText value="Nome: " />
<h:outputText styleClass="outputLabel"
value="#{traduttoreBean.info.nome}" />
<h:outputText value="Cognome: " />
<h:outputText styleClass="outputLabel"
value="#{traduttoreBean.info.cognome}" />
<h:outputText />
</h:panelGrid>
<p:commandButton value="Submit" update="growl" action="#{traduttoreBean.save}" ></p:commandButton>
</p:panel>
</p:tab>
</p:wizard>
</h:form>
</h:body>
</html>
The associated bean:
public class TraduttoreBean implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private Traduttore traduttore;
private InfoTraduttore info;
public TraduttoreBean(){
this.traduttore=new Traduttore();
this.info= new InfoTraduttore();
this.info.setTraduttore(traduttore);
}
public void save(ActionEvent actionEvent) {
PersistenzaUtenti pu= PersistenzaUtenti.getInstance();
PersistenzaInfoTraduttori pi= PersistenzaInfoTraduttori.getInstance();
try {
pu.insert(traduttore);
pi.insert(info);
} catch (Exception e) {
}
FacesMessage msg = new FacesMessage("Successful", "Welcome :" + info.getNome());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public String onFlowProcess(FlowEvent event) {
return event.getNewStep();
}
public Traduttore getTraduttore() {
return traduttore;
}
public void setTraduttore(Traduttore traduttore) {
this.traduttore = traduttore;
}
public InfoTraduttore getInfo() {
return info;
}
public void setInfo(InfoTraduttore info) {
this.info = info;
}
}
For the declaration of the bean I've tried both with the annotation #Managed bean and the faces-config file.
Here's my definition:
<managed-bean>
<managed-bean-name>traduttoreBean</managed-bean-name>
<managed-bean-class>guiBeans.TraduttoreBean</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>

Answer provided by comment:
The problem was that Trinidad libraries were in conflict with
Primefaces. Solved removing Trinidad libraries.

Related

Update bean property while using actionListener [duplicate]

This question already has answers here:
p:commandbutton action doesn't work inside p:dialog
(4 answers)
Closed 2 years ago.
I have a dialog in a form. The dialog has an inputTextarea and a commandButton. The commandButton uses actionListener to call a method on the bean. My issue is that the data in the inputTextarea is not available to my actionListener's method. The comments field shown below is null on the bean. How can I get access to it's contents in my bean's method?
The Page:
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
template="/common/template.xhtml">
<ui:define name="title">test</ui:define>
<ui:define name="head">
<h:outputStylesheet name="web0020.css" library="css"/>
</ui:define>
<ui:define name="content">
<p:panel id="fileUploads" header="File Uploads" style="margin-bottom:20px">
<h:form id="form">
<p:messages id="messages" showDetail="false" closable="true">
<p:autoUpdate/>
</p:messages>
<p:dialog header="Approve" widgetVar="approveDlg" modal="true" appendTo="#(body)">
<p:panelGrid columns="1" layout="grid" styleClass="ui-noborder">
<h:outputText value="Approve Submission" style="font-weight:bold;font-size:1.3em"/>
<p:outputLabel for="comments" value="Comments:" style="font-weight:bold"/>
<p:inputTextarea id="comments" value="#{testView.comments}"
rows="1" cols="100"/>
<p:commandButton value="Save"
actionListener="#{testView.approve()}"
icon="ui-icon-check" update=":form:messages"/>
</p:panelGrid>
</p:dialog>
<p:commandButton value="Approve" onclick="PF('approveDlg').show();" icon="fa fa-thumbs-up"
update=":form:messages"/>
</h:form>
</p:panel>
</ui:define>
</ui:composition>
#Named
#ViewScoped
public class TestView implements Serializable{
#SuppressWarnings("compatibility:1287963775427900593")
private static final long serialVersionUID = 1L;
public TestView() {
super();
}
private String comments;
public void approve() {
try {
System.out.println("Comment:" + comments); //THIS IS EMPTY
} catch (Exception e) {
FacesContext.getCurrentInstance()
.addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error! " + e.getMessage(), e.getMessage()));
}
}
public void setComments(String comments) {
this.comments = comments;
}
public String getComments() {
return comments;
}
}
Answered with this - Primefaces dialog with modal=true not working properly. In order to make a modal form, you have to use appendTo="#(body)" and if you use appendTo, you will be outside the page's form, so you have to embed a separate form (outside of the main page's form) inside your dialog

Java Server Faces - How to update value of displayed List on web page [duplicate]

This question already has answers here:
How to dynamically add JSF components
(3 answers)
Closed 7 years ago.
I am doing dynamic textbox for request name and the value but when I click the add button on my .xhtml file it is always on size of 1. I want to get the current size of the List then add another blank object.
HomepageBean.java
#ManagedBean
public class HomepageBean {
private String url;
private String portNumber;
private List<RequestParameter> requestParameterList = new ArrayList<>();
public List<RequestParameter> getRequestParameterList() {
return requestParameterList;
}
public void setRequestParameterList(List<RequestParameter> requestParameterList) {
this.requestParameterList = requestParameterList;
}
/**
* #return the url
*/
public String getUrl() {
return url;
}
/**
* #param url the url to set
*/
public void setUrl(String url) {
this.url = url;
}
/**
* #return the portNumber
*/
public String getPortNumber() {
return portNumber;
}
/**
* #param portNumber the portNumber to set
*/
public void setPortNumber(String portNumber) {
this.portNumber = portNumber;
}
public void addRequestParameter(List<RequestParameter> requestParameters){
System.out.println("size: " + requestParameterList.size());
RequestParameter requestParameter = new RequestParameter();
requestParameters.add(requestParameter);
System.out.println("size: " + requestParameterList.size());
this.setRequestParameterList(requestParameters);
}
public void removeRequestParameter(RequestParameter requestParameter){
requestParameterList.remove(requestParameter);
}
}
and this is my .xhtml file which iterates the value of List from the bean
index.xhtml
<?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://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">>
<h:head>
<h:outputStylesheet library="css" name="/WEB-INF/homepageStyle.css"/>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:outputLabel style="font-weight: bold" value="Platform V2 Emulator"/>
<br />
<h:panelGrid styleClass="panelGridCenter" columns="4" cellpadding="5">
<h:outputLabel for="url" value="Url:" style="font-weight:bold" />
<p:inputText id="url" value="#{homepageBean.url}" />
<p:commandButton value="Submit" update="urlString" icon="ui-icon-check" />
<h:outputText id="urlString" value="#{homepageBean.url}" />
</h:panelGrid>
<h:panelGrid styleClass="panelGridCenter" columns="4" cellpadding="5">
<h:outputLabel for="portNumber" style="font-weight: bold" value="Port:"/>
<p:inputText id="portNumber" value="#{homepageBean.portNumber}"/>
<p:commandButton value="Submit" update="portNumberString" icon="ui-icon-check" />
<h:outputText id="portNumberString" value="#{homepageBean.portNumber}" />
</h:panelGrid>
<h:panelGrid columns="6" cellpadding="5">
<h:outputLabel for="parameters" style="font-weight: bold" value="Request Parameters:"/>
</h:panelGrid>
<h:panelGrid id="parametersGrid" columns="3" cellpadding="5">
<c:forEach items="#{homepageBean.requestParameterList}" var="parameter">
<h:inputText value="#{parameter.key}"/>
<h:inputText value="#{parameter.value}"/>
<h:commandButton action="#{homepageBean.removeRequestParameter(parameter)}" value="Remove"/>
</c:forEach>
</h:panelGrid>
<h:panelGrid columns="1" cellpadding="5">
<p:commandButton actionListener="#{homepageBean.addRequestParameter(homepageBean.requestParameterList)}" update="parametersGrid" value="Add"/>
</h:panelGrid>
<h:link outcome="welcomePrimefaces" value="Primefaces welcome page" />
</h:form>
</h:body>
Well I think your size is always 1 because in your addRequestParameter method you add only one element. Clicking next time this button you create new request and new empty list is created. You have to store your older objects somewhere (e.g. database).

How can I navigate to another page in JSF?

I am developing small web app using JSF/PrimeFaces. I am able to call bean from web, however, I am unable to return web. This is what I have:
requestLeave.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Request leave</title>
</h:head>
<h:body>
<script language="javascript">
var today = new Date();
document.write(today);
</script>
<h:form id="form" >
<h:panelGrid id= "grid" columns="2" cellpadding="5">
<f:facet name="header">
<p:messages id="msgs" />
</f:facet>
<h:outputLabel for="title" value="Leave Title:" style="font-weight:bold" />
<p:inputText value="#{requestLeave.titleLeave}" required="true" requiredMessage="title is required." />
<h:outputLabel for="type" value="Type:" style="font-weight:bold" />
<p:inputText value="#{requestLeave.typeLeave}" required="true" requiredMessage="type is required." />
<p:commandButton value="Submit" actionListener="#{requestLeave.buttonAction}" />
</h:panelGrid>
</h:form>
</h:body>
</html>
RequestLeave.java
import javax.faces.bean.ManagedBean;
#ManagedBean
public class RequestLeave {
private String titleLeave;
private String typeLeave;
public String getTitleLeave() {
return titleLeave;
}
public void setTitleLeave(String titleLeave) {
this.titleLeave = titleLeave;
}
public String getTypeLeave() {
return typeLeave;
}
public void setTypeLeave(String typeLeave) {
this.typeLeave = typeLeave;
}
public String buttonAction() {
System.out.println("leave title " + titleLeave);
System.out.println("leave type " + typeLeave);
return ("index.jsp");
}
}
With this, I cannot return to index.jsp. Can anyone help me? Thanks in advance.
Change the actionListener attribute to action:
<p:commandButton value="Submit" action="#{requestLeave.buttonAction}" />
More info:
Differences between action and actionListener?

update primefaces dataTable with new rows adding dynamically

When I click on the button New <p:commandButton actionListener="#{ecritureCtrl.newLine}" value="New" update="dataTableSaisiePiece" oncomplete="addRowOnComplete()" ajax="true"/>, a new row is added to my dataTable on only the first click and the page is refreshed. Several cliques except the first were not refreshes the dataTable. So to see my newly added rows, I use the F5 key to refresh my page. Certainly my update="dataTableSaisiePiece" not work or only works rather the first click.
Here is my page home.xhtml :
<?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://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<script type="text/javascript">
function addRowOnComplete() {
jQuery('#supercoolnewrow').trigger('click');
}
</script>
<ui:composition template="/resources/template/all.xhtml">
<ui:define name="titre">Saisie</ui:define>
<ui:define name="content">
<p:tabView id="ViewPlan">
<p:tab id="tab2" title="Saisie 1">
<h:outputScript library="js" name="frenchLocale.js" />
<h:form id="formPiece">
<p:panel id="panelSaisie" header="Saisir" style="color: brown;font-size: 15px">
<h:panelGrid columns="3" >
<p:outputLabel for="description" value="Description:" ></p:outputLabel>
<p:inputText id="description" value="#{ecritureCtrl.description}" required="true" label="Description" maxlength="100" size="75">
<f:validateLength maximum="100" />
</p:inputText>
<p:message for="description" />
<p:outputLabel for="date" value="Date:" ></p:outputLabel>
<p:calendar locale="fr" id="date" required="true" label="Date" value="#{ecritureCtrl.date}" />
<p:message for="date" />
<p:outputLabel for="code" value="Code Avant" ></p:outputLabel>
<p:inputText id="code" value="#{ecritureCtrl.code}" required="true" >
</p:inputText>
<p:message for="code" />
</h:panelGrid>
<br/>
<p:dataTable var="line" value="#{ecritureCtrl.lignes}" id="dataTableSaisiePiece" >
<p:column headerText="First Name" style="width:150px">
<p:inputText value="#{line.intituleCompte}" style="width:100%"/>
</p:column>
<p:column headerText="Last Name" style="width:150px">
<p:inputText value="#{line.code}" style="width:100%"/>
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton actionListener="#{ecritureCtrl.newLine}" value="New" update="dataTableSaisiePiece" oncomplete="addRowOnComplete()" ajax="true"/>
</h:form>
</p:tab>
<p:tab id="tab3" title="Saisie 2">
</p:tab>
</p:tabView>
</ui:define>
</ui:composition>
</html>
My ManagedBean:
#ManagedBean (name = "ecritureCtrl")
#SessionScoped
public class EcritureCtrl {
private List<Avant> lignes = new ArrayList<Avant>();
Avant unUser;
private String description;
private Date date;
private String code;
public EcritureCtrl() {
lignes.add(new Avant());
}
public void newLine(ActionEvent actionEvent){
lignes.add(new Avant());
}
}
Could you please help me ?
Thanks in advance.
this seems to work for me
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
#ManagedBean
#SessionScoped
public class EcritureCtrl implements Serializable {
private static final long serialVersionUID = 1L;
private String code;
private Date date;
private String description;
private List<Avant> lignes = new ArrayList<Avant>();
private Avant unUser;
public String getCode() {
return this.code;
}
public Date getDate() {
return this.date;
}
public String getDescription() {
return this.description;
}
public List<Avant> getLignes() {
return this.lignes;
}
public Avant getUnUser() {
return this.unUser;
}
#PostConstruct
private void init(){
this.lignes.add(new Avant());
}
public void newLine(ActionEvent actionEvent) {
this.lignes.add(new Avant());
}
public void setCode(String code) {
this.code = code;
}
public void setDate(Date date) {
this.date = date;
}
public void setDescription(String description) {
this.description = description;
}
public void setLignes(List<Avant> lignes) {
this.lignes = lignes;
}
public void setUnUser(Avant unUser) {
this.unUser = unUser;
}
}
and
<!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://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Sorry</title>
</h:head>
<h:body>
<script type="text/javascript">
function addRowOnComplete() {
alert();
}
</script>
<h:form id="formPiece">
<p:messages id="messages" showDetail="true" autoUpdate="true"
closable="true" />
<p:tabView id="ViewPlan">
<p:tab id="tab2" title="Saisie 1">
<p:panel id="panelSaisie" header="Saisir"
style="color: brown;font-size: 15px">
<h:panelGrid columns="3">
<p:outputLabel for="description" value="Description:"></p:outputLabel>
<p:inputText id="description" value="#{ecritureCtrl.description}"
required="true" label="Description" maxlength="100" size="75">
<f:validateLength maximum="100" />
</p:inputText>
<p:message for="description" />
<p:outputLabel for="date" value="Date:"></p:outputLabel>
<p:calendar locale="fr" id="date" required="true" label="Date"
value="#{ecritureCtrl.date}" />
<p:message for="date" />
<p:outputLabel for="code" value="Code Avant"></p:outputLabel>
<p:inputText id="code" value="#{ecritureCtrl.code}"
required="true">
</p:inputText>
<p:message for="code" />
</h:panelGrid>
<br />
<p:dataTable var="line" value="#{ecritureCtrl.lignes}"
id="dataTableSaisiePiece">
<p:column headerText="First Name" style="width:150px">
<p:inputText value="#{line.intituleCompte}" style="width:100%" />
</p:column>
<p:column headerText="Last Name" style="width:150px">
<p:inputText value="#{line.code}" style="width:100%" />
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton actionListener="#{ecritureCtrl.newLine}"
value="New" update="dataTableSaisiePiece" oncomplete="addRowOnComplete()"
ajax="true" />
</p:tab>
<p:tab id="tab3" title="Saisie 2">
</p:tab>
</p:tabView>
</h:form>
</h:body>
</html>

jars required to be added to use rich notify messages in jsf?

i am using rich notify messages and added all related jars namely
richfaces-components-ui-4.1.0.Final ,
richfaces-core-impl-4.0.0.Final,
standard-1.1.2 ,
jstl-1.2 ,
validation-api-1.0.0.GA ,
richfaces-core-api-4.0.0.Final ,
richfaces-components-api-4.0.0.Final
jsf-impl-2.0.2,
cssparser-0.9.5,
guava-r08,
jhighlight-1.0.
but i am getting class not found exception:org.richfaces.component.NotifyAttributes.
sample.xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition 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://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<rich:panel>
<f:facet name="header">
<h:outputText value="Validation Form" />
</f:facet>
<h:form>
<h:panelGrid columns="3">
<rich:validator event="change">
<h:outputText value="Name:" />
<h:inputText label="Name" id="name" value="#{userBean.name}"
required="true">
<f:validateLength minimum="3" />
</h:inputText>
<rich:message for="name" ajaxRendered="true" />
<h:outputText value="Job:" />
<h:inputText label="Job" id="job" value="#{userBean.job}"
requiredMessage="Job is required">
<f:validateLength minimum="3" maximum="50" />
</h:inputText>
<rich:message for="job" ajaxRendered="true" />
<h:outputText value="Address:" />
<h:inputText label="Address" id="address"
value="#{userBean.address}" requiredMessage="Address is required">
<f:validateLength minimum="10" />
</h:inputText>
<rich:message for="address" ajaxRendered="true" />
<h:outputText value="Zip:" />
<h:inputText label="Zip" id="zip" value="#{userBean.zip}"
requiredMessage="Zip is required">
<f:validateLength minimum="4" maximum="9" />
</h:inputText>
<rich:message for="zip" ajaxRendered="true" />
</rich:validator>
<rich:notifyMessages stayTime="2000" nonblocking="true" escape="false"/>
<f:facet name="footer">
<a4j:commandButton value="Ajax Validate" />
</f:facet>
</h:panelGrid>
</h:form>
</rich:panel>
</ui:composition>
bean class used to set and get bean vlaues.let me know whats wrong with existing code ,along with jars to be added
userBean.java:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean
#SessionScoped
public class userBean {
private String name;
private String job;
private String address;
private String zip;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
}
error:
Caused by: java.lang.ClassNotFoundException: org.richfaces.component.NotifyAttributes
i am not getting why this is getting although i added all required jars of richfaces4.0 and above.
notify component is not part of RichFaces 4.0. See Richfaces 4.0 VDL documentation. You have to use version 4.1 or up (for example current version RichFaces 4.3).Note: all richfaces-???.jar(s) should be for the same version of RichFaces.

Resources