passing values from one jsf page to another through managed bean - java

i need to pass a value(studentId) from a jsf view(list.xhtml) to another jsf page (editor.xhtml) via managed bean (bean.java). I can get the values in bean page but i could not access those in editor . Can you please tell me what went wrong ?
Hope to hear some suggestions
list.xhtml
<h:dataTable value="#{student.createList()}" var="student" styleClass="studentTable"
columnClasses=",,,fixedWidth" border="1" cellspacing="2" cellpadding="2">
<h:column>
<f:facet name="header">Student ID</f:facet>
<h:outputText value="#{student.studentId}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">Name</f:facet>
<h:outputText value="#{student.fname}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">Surname</f:facet>
<h:outputText value="#{student.lname}"></h:outputText>
</h:column>
<h:commandLink actionListener="#{student.edit()}" value ="Editt">
<f:param name="id" value="#{student.studentId}"/>
</h:commandLink>
editor.xhtml
<h:panelGrid border="" cellpadding="20" cellspacing="20" columns="3">
<h:outputLabel value="Student Id" />
<h:inputText value="#{student.studentId}" readonly="true" required="true" requiredMessage="Id is Required" id="Eid">
</h:inputText> <h:message for="Eid"/>
<h:outputLabel value="Student Name" />
<h:inputText value="#{student.fname}" required="true" requiredMessage="Name is Required" id="Ename">
</h:inputText> <h:message for="Ename"/>
<h:outputLabel value="Student Age" />
<h:inputText value="#{student.lname}" required="true" requiredMessage="age is Required" id="Eage">
<h:commandLink value="Update" action="userRecords" actionListener="#{student.update()}">
</h:commandLink>
student.java
public void edit(){
System.out.println("called from edit()"+ this.StudentId);
List<Student> arrList = createList();
FacesContext fc = FacesContext.getCurrentInstance();
mapParam=fc.getExternalContext().getInitParameterMap();
String idStudent;
HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();
for (Student studentManagedBean : arrList) {
if (studentManagedBean.getStudentId() == idStudent) {
this.setStudentId(studentManagedBean.getStudentId());//Error
this.setFname(studentManagedBean.getFname());
this.setLname(studentManagedBean.getLname());
}
System.out.println(" we have "+ this.getStudentId() + this.getFname() );
}
}
public void update() {
Connection conn=null;
try{
Class.forName("org.apache.derby.jdbc.ClientDriver");
conn = DriverManager.getConnection("jdbc:derby://localhost:1527/XX","XX","XXX");
}catch(Exception e){
}
String str = "Update student set FNAME=?,LNAME=? where STUDENTID=?";
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();
int idStudent = Integer.parseInt(request.getParameter("id"));
try {
PreparedStatement pstmt = conn.prepareStatement(str);
pstmt.setString(1, this.getFname());
pstmt.setString(2, this.getLname());
pstmt.setInt(3, idStudent);
// System.out.println("Id Student Update :" + idStudent);//Error
int executeUpdate = pstmt.executeUpdate();
if (executeUpdate > 0) {
System.out.println("Update SuccessFully");
}
} catch (SQLException ex) {
Logger.getLogger(Student.class.getName()).log(Level.SEVERE, null, ex);
} finally {
}

Related

Add new record in retrieved from sql database list

I need to add new record to list, which retrieved from database,-
It's seems be simpse to do, but how to connect(merge) these 2 methods:
public void addNewUser(){
myList= new ArrayList<>();
Values newValue = new Values(this.id, this.orderNo, this.productName, this.price, this.qty);
newValue.setEditable(true);
myList.add(newValue);
}
I retrieve list of users from sql database using such method:
private List<Values> valuesList;
private Values allValues;
private static List<Values> getUsers() {
try {
databaseConnection();
String SQL = "SELECT * FROM Registration";
System.out.println("Retrieve values from Registration table...");
PreparedStatement prepStatement = connection.prepareStatement(SQL);
valuesList = new ArrayList<>();
ResultSet resultSet = prepStatement.executeQuery();
boolean found = false;
while (resultSet.next() == true) {
allValues = new Values();
allValues.setId(resultSet.getInt("id"));
allValues.setOrderNo(resultSet.getString("orderNo"));
allValues.setProductName(resultSet.getString("productName"));
allValues.setPrice(resultSet.getBigDecimal("price"));
allValues.setQty(resultSet.getInt("qty"));
valuesList.add(allValues);
found = true;
}
resultSet.close();
prepStatement.close();
close(connection);
if (found) {
return valuesList;
} else {
return null;
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
System.out.println("Error in getUsers()-->" + e.getMessage());
}
return (null);
}
public List<Values> getInformation() {
return getUsers();
}
Here my display page:
<h:dataTable value="#{user.information}" var="x" border="1">
<h:column>
<f:facet name="header">
<h:outputText value="Id"></h:outputText>
</f:facet>
<h:outputText value="#{x.id}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Order No"></h:outputText>
</f:facet>
<h:inputText value="#{x.orderNo}" rendered="#{x.editable}"></h:inputText>
<h:outputText value="#{x.orderNo}" rendered="#{not x.editable}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Product name"></h:outputText>
</f:facet>
<h:inputText value="#{x.productName}" rendered="#{x.editable}"></h:inputText>
<h:outputText value="#{x.productName}" rendered="#{not x.editable}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Price"></h:outputText>
</f:facet>
<h:inputText value="#{x.price}" rendered="#{x.editable}"></h:inputText>
<h:outputText value="#{x.price}" rendered="#{not x.editable}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Quantity"></h:outputText>
</f:facet>
<h:inputText value="#{x.qty}" rendered="#{x.editable}"></h:inputText>
<h:outputText value="#{x.qty}" rendered="#{not x.editable}"></h:outputText>
</h:column>
</h:dataTable>
<h:commandButton value="AddNew" action="#{user.add}"></h:commandButton>
If you want to add another values like your first method to your List then you can do like this :
//myList = new ArrayList<>(); you dont need to use this, this can empty your list
myList = getUsers();//get your List
Values newValue = new Values(this.id, this.orderNo, this.productName, this.price, this.qty);
//add a new element to your list
newValue.setEditable(true);
myList.add(newValue);
N.B
You have a problem in your xhtml:
<h:commandButton value="AddNew" action="#{user.add}"></h:commandButton>
So if you try to call the addNewUser() then this not work with you.
Solution
This can call your method addNewUser()
<h:commandButton value="AddNew" action="#{user.addNewUser}"></h:commandButton>
So after that :
You should to update your dataTable
<h:commandButton value="AddNew" action="#{user.addNewUser}" update="idOfYourDataTable"/>
Don't forgot to add an id to your dataTable:
<h:dataTable value="#{user.information}" var="x" border="1" id="idOfYourDataTable">
...
Another thing :
<h:dataTable value="#{user.information}"
Make sure you have a List<Values> information in your managedBean, because the code that you put, there are no List information.
Hope this can help you.

can't connect to postgres using jdbc driver in a ManagedBean

I work on a java web application using jsf and Primefaces, with Glassfish 4.1.1 as my application server and PostgreSQL as my database.
I have a form containing a selectOneMenu which value is sent to the ManagedBean with a commandButton.
The ManagedBean then try to connect to the database using the DriverManager and execute a query which results are displayed in a panelGrid.
This is the java code in the ManagedBean Pays.java :
public void save() throws NamingException, SQLException{
String url = "jdbc:postgresql://localhost:5432/zones_franches?user=postgres&password=jihane";
Connection conn = DriverManager.getConnection(url);
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery ("SELECT * FROM pays WHERE id_geom = "+ idGeom +";");
System.out.println("Query executed....");
if(rs.next()) {
idPays = rs.getString("id_pays");
nom = rs.getString("nom");
superficie = rs.getString("superficie");
pib2014 = rs.getString("pib_2014");
population2014 = rs.getString("population_2014");
inflation = rs.getString("inflation");
investissements = rs.getString("investissements");
indDoingBus = rs.getInt("ind_doing_business");
rs.close();
st.close();
conn.close();
}else{
System.out.print("try again !");
rs.close();
st.close();
conn.close();
}
}
And this is the xhtml page code :
<h:form>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="pays" value="Pays sélectionné : " />
<h:selectOneMenu id="pays" value="#{pays.idGeom}" required="true" label="ID Pays">
<f:selectItem itemLabel="Egypte" itemValue="1" />
</h:selectOneMenu>
</h:panelGrid>
<h:panelGrid>
<p:commandButton process="#parent:#parent" update="#form" value="Détails" action="#{pays.save()}"/>
<br/>
<p:panelGrid columns="2">
<f:facet name="header">
<p:graphicImage name="demo/images/misc/kobe.png" />
</f:facet>
<h:outputText value="Code Pays :" />
<h:outputText value="#{pays.idGeom}" />
<h:outputText value="Id Pays :" />
<h:outputText value="#{pays.idPays}" />
<h:outputText value="Nom Pays :" />
<h:outputText value="#{pays.nom}" />
</p:panelGrid>
</h:panelGrid>
</h:form>
The problem is that the results are not displayed in the panelGrid, even if the save() method is executed when I click on the commandButton.

Editing a datatable row with a dialog

I am using Primefaces 3.5, Jsf 2 and I have a datatable, now I implemented a dialog like the primefaces showcase(singlerowselection), it works fine, but I want to edit the row IN the dialog. Furthermore I want that the inputtext is filled with the data from the cell of the datatable, so that you can easily edit it!(like the row editor does it, just in a dialog)
Not like this: http://i.stack.imgur.com/J55j0.jpg
Watermark works, but it is no option because the text disappears if you want to edit it.
It should be like that: http://i.stack.imgur.com/cAFLo.jpg
So, can someone tell me how the cell data can be displayed and edited?
Here is the xhtml (dialog is not in the datatable):
<p:dialog id="dialog" header="Server Detail" widgetVar="serDialog"
resizable="false" showEffect="clip" hideEffect="fold" dynamic="true">
<h:panelGrid id="display" columns="3" cellpadding="4">
<h:outputText value="Data Center Location " />
<p:inputText id="datacenter" value="#{server.dataCenterLocation}"></p:inputText>
<h:outputText value="Identification " />
<h:inputText id="identification" value="#{server.identification}"></h:inputText>
<p:watermark for="identification"
value="#{serverBean.selectedServer.identification}"></p:watermark>
</h:panelGrid>
<p:growl id="growl" showDetail="true" sticky="false" />
<p:commandButton value="Edit Server" action="#{server.onEdit}" update="#form, growl" />
</p:dialog>
the method in the bean(name= server)
(without the selectedServer(name =serverBean) with the getter and setter):
public void onEdit() throws Exception {
PreparedStatement ps = null;
Connection con = null;
int i = 0;
try {
Server ser = new Server();
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
.newInstance();
con = DriverManager
.getConnection("jdbc:sqlserver://...");
String sql = "UPDATE VAI_Serverlist SET [Data Center Location]= ?,... WHERE Identification='"
+ ser.identification + "'";
ps = con.prepareStatement(sql);
ps.setString(1, ser.dataCenterLocation);
...
i = ps.executeUpdate();
} catch (SQLException e) {
System.out.println(i);
e.printStackTrace();
} finally {
try {
con.close();
ps.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Thanks in advance!
<h:form id="form">
<p:dataTable id="table" var="item" value="#{ManagedBean.list()}"
<f:facet name="footer">
<p:commandButton id="showUpdateButton" value="#{msgForms['actions.Edit']}"
update=":update_form"
icon="ui-icon-pencil"
style="margin: 0%"
ajax="true"
immediate="true"
oncomplete="PF('DialogUpdate').show()"
/>
</f:facet>
</p:dataTable>
<h:form id="form">
<p:dialog id="dialog_update"
modal="true"
header="${msgForms['titles.update']}"
widgetVar="DialogUpdate" resizable="false"
showEffect="clip" hideEffect="fold"
>
<h:form id="update_form">
<h:panelGrid columns="3" id="panel">
<!--FIELDS-->
<h:outputLabel for="nombre" value="#{msgForms['fields.nombre']}:" />
<p:inputText id="nombre"
value="#{ManagedBean.selectedItem.nombre}"
required="true"
requiredMessage="#{msgForms['field.required']}"
>
<p:ajax event="keyup" update="nombreMsg" global="false"/>
</p:inputText>
</h:panelGrid>
<!--/FIELDS-->
<!-- BUTTONS ACTIONS-->
<p:commandButton id="updateButtonDg"
value="#{msgForms['actions.update']}"
icon="ui-icon-pencil"
actionListener="#{ManagedBean.update()}"
update=":form:"
style="margin: 0%"
ajax="true"
onclick="DialogUpdate.hide();"
>
</p:commandButton>
<!-- /BUTTONS ACTIONS-->
</h:form>
</p:dialog>
the MANAGED BEAN..
#Named("ManagedBean")
#RequestScoped
public class ManagedBean {
//Spring Item Service is injected...
#Inject
IItemService itemService; //if not required because if you use dependencies injection to connect with de database
private List<Item> filteredItems; //only if you use the attribute: filteredValue="#{ManagedBean.filteredItems}" in the dataTable
private List<Item> items;
public void update() {
//here you save the changes in the data base
this.itemService().updateItem(this.selectedItem);
}
this is more or less what I use, I can not put the literal code, but I think I have not left anything important, so i hope it could to help you.
I recommend that you take a look at the tutorial
http://www.javacodegeeks.com/2012/04/jsf-2-primefaces-3-spring-3-hibernate-4.html
it shows how to integrate jsf2 Spring3 hibernate in your project and also how to inject dependencies using annotations, i recomend you the use of hibernate framework to interact with your database

Session management with parameter tagging / p:button /p:commandButton

I have a web application which have to implement login. user provide username and pwd after authenticating user should redirect to page which they have privilages pages are differant from user to user. Sometimes 2 or more users can get same page but available data should differant for do this I have pass users privilage ID(divisionId) to other beans
for now i have tried URL tagging parameter tagged to URL and dirrect to page successfully but I can't take it to bean variable.
Itried this with p:Button then textbox inputs won't get to bean class to execute the method when button click.
xhtml code -
<h:body>
<p:growl id="growl" showDetail="true" life="3000" />
<p:dialog id="dialog" header="Login" widgetVar="dlg" visible="true" closable="false" >
<h:form id="form">
<h:panelGrid columns="2">
<h:outputLabel for="username" value="Username: " />
<p:inputText id="username" value="#{loginBean.username}"
required="true" requiredMessage="Enter Username"/>
<h:outputLabel for="password" value="Password: " />
<p:password id="password" value="#{loginBean.password}"
required="true" requiredMessage="Enter Password"/>
</h:panelGrid>
<p:commandButton id="LoggingButton" value="Login" action="#{loginBean.doLogin()}"
update=":growl" oncomplete="handleLoginRequest(xhr, status, args),">
</p:commandButton>
</h:form>
</p:dialog>
</h:body>
loginbean-
public class LoginBean{
private String username;
private String password;
private int divisionId;
/**
* Creates a new instance of loginBean
*/
public LoginBean() {
}
public String doLogin() {
DbUser du = new DbUser();
divisionId = du.ValidateUser(username, password);
if(divisionId==0)
addMessage("Invalied username or password", false);
else{
if(divisionId==1){
// return "superuser.xhtml?faces-redirect=true";
return "superuser.xhtml?test="+divisionId+"faces-redirect=true";
//superAdmin
}
else if(divisionId==2||divisionId==3){
// return "engadmin_create_div.xhtml?faces-redirect=true";
return "engadmin_create_div.xhtml?test="+divisionId+"faces-redirect=true";
//ENG/IT ADMIN
}
else{
// return "viewonly_user.xhtml?faces-redirect=true";
return "viewonly_user.xhtml?test="+divisionId+"faces-redirect=true";
//View only users
}
}
return null;
}
I think that work :)
<p:growl id="growl" showDetail="true" life="3000" />
<p:dialog id="dialog" header="Login" widgetVar="dlg" visible="true" closable="false" >
<h:form id="form">
<h:panelGrid columns="2">
<h:outputLabel for="username" value="Username: " />
<p:inputText id="username" value="#{loginBean.username}"
required="true" requiredMessage="Enter Username"/>
<h:outputLabel for="password" value="Password: " />
<p:password id="password" value="#{loginBean.password}"
required="true" requiredMessage="Enter Password"/>
</h:panelGrid>
<p:commandButton id="LoggingButton" value="Login" actionListener="#{loginBean.doLogin()}">
</p:commandButton>
</h:form>
</p:dialog>
</h:body>
Bean
public class LoginBean{
private String username;
private String password;
private int divisionId;
/**
* Creates a new instance of loginBean
*/
public LoginBean() {
}
public static void redirect(String strDes) throws IOException {
ExternalContext ext = FacesContext.getCurrentInstance().getExternalContext();
ext.redirect(ext.getRequestContextPath() + strDes);
}
public void doLogin() {
DbUser du = new DbUser();
divisionId = du.ValidateUser(username, password);
if(divisionId==0)
addMessage("Invalied username or password", false);
else{
if(divisionId==1){
LoginBean.redirect("superuser.xhtml?test="+divisionId+"faces-redirect=true");
//superAdmin
}
else if(divisionId==2||divisionId==3){
LoginBean.redirect("engadmin_create_div.xhtml?test="+divisionId+"faces-redirect=true");
//ENG/IT ADMIN
}
else{
LoginBean.redirect("viewonly_user.xhtml?test="+divisionId+"faces-redirect=true");
//View only users
}
}
}
you get parameter from bean:
Map<String,String> params =
FacesContext.getExternalContext().getRequestParameterMap();
String action = params.get("test");

How to update jsf datatable from back bean

I have a form that user should enter some values to get some info from a web service. Firstly user fulfills the form and then as he clicks the request button webservice is called. Until here everything works nicely. But as the webservice returns the info, I have to re-render the datatable with the new data. Here is my page:
<h:body>
<h:form id="formCus">
<h:outputLabel value="Müşteri Tipi: *"/>
<p:selectOneMenu id="customerType" value="#{customerService.musteriTipi}" style="width: 39%">
<f:selectItem itemLabel="" itemValue=" " />
<f:selectItem itemLabel="Bireysel" itemValue="BIREYSEL" />
<f:selectItem itemLabel="Tüzel" itemValue="TUZEL" />
<f:selectItem itemLabel="Yabancı" itemValue="YABANCI" />
<p:ajax event="change" update="#{customerService.musteriTipi}"/>
</p:selectOneMenu>
<h:outputLabel value="Ad/Firma Adı: *" for="customerName" />
<p:inputText id="customerName" value="#{customerService.adFirmaAdi}" title="Müşteri adı." >
<p:ajax event="change" update="#{customerService.adFirmaAdi}" />
</p:inputText>
<h:outputLabel value="Soyad/Ünvan: *" for="customerSurname" />
<p:inputText id="customerSurname" value="#{customerService.soyadUnvan}" title="Müşteriye ait soyad/ünvan." >
<p:ajax event="change" update="#{customerService.soyadUnvan}" />
</p:inputText>
<h:outputLabel value="TC Kimlik No: *" />
<p:inputText id="customerTC" value="#{customerService.tcKimlikNo}" title="TC Kimlik numarasını buraya girin.TC numarası sadece sayılardan oluşmalıdır." >
<p:ajax event="change" update="#{customerService.tcKimlikNo}" partialSubmit="true" process="#this"/>
</p:inputText>
<h:outputLabel value="Vergi No:" />
<p:inputText id="customerVergi" value="#{customerService.vergiNo}" title="TC Kimlik numarasını buraya girin.TC numarası sadece sayılardan oluşmalıdır." >
<p:ajax event="change" update="#{customerService.vergiNo}" partialSubmit="true"/>
</p:inputText>
<h:outputLabel value="Müdürlük Kodu: *" />
<p:inputText id="departmantId" value="#{customerService.mudurlukKodu}" title="Müdürlük kodunu buraya girin.Müdürlük kodu sadece sayılardan oluşmalıdır." >
<p:ajax event="change" update="#{customerService.mudurlukKodu}" partialSubmit="true"/>
</p:inputText>
<h:outputLabel value="Müşteri Kodu: " />
<p:inputText id="customerId" value="#{customerService.musteriKodu}" title="Müdürlük kodunu buraya girin.Müdürlük kodu sadece sayılardan oluşmalıdır." >
<p:ajax event="change" update="#{customerService.musteriKodu}" />
</p:inputText>
<h:outputLabel value="E-Posta Adresi: " />
<p:inputText id="customerMail" value="#{customerService.mail}" title="Müşteriye ait e-mail adresini buraya girin." >
<p:ajax event="change" update="#{customerService.mail}" partialSubmit="true"/>
</p:inputText>
<h:outputText value=" "/>
<p:commandButton id="query" value="Müşteri Sorgula" actionListener="#{customerService.request}" async="true" onsuccess="panelwv.show()">
<f:ajax execute="#form" render=":personList" ></f:ajax>
</p:commandButton>
</h:form>
<h:panelGrid columns="5">
<h:outputText value=""/>
<h:outputText value=""/>
<p:panel widgetVar="panelwv" visible="false" closable="true" header="Sorgu Yapılıyor...">
<p:graphicImage value="/resources/images/ajaxloadingbar.gif" />
</p:panel>
<h:outputText value=""/>
<h:outputText value=""/>
</h:panelGrid>
<h:outputText value="Bulunan Müşterilere Ait Bilgiler:" />
<h:form id="personList" rendered="#{not empty customerService.musteriKodu}">
<p:dataTable value="#{customerService.customer}" var="item" id="persontable" emptyMessage="Henüz müşteri eklemediniz.">
<p:column headerText="Müşteri/Firma ID">
#{item.customerId}
</p:column>
<p:column headerText="Ad/Firma Adı">
#{item.customerName}
</p:column>
<p:column headerText="Soyad/Ünvan" >
#{item.customerSurname}
</p:column>
<p:column headerText="Müşteri Tipi" >
#{item.customerType}
</p:column>
<p:column headerText="Telefon" >
#{item.customerTel}
</p:column>
<p:column headerText="Adres">
#{item.customerAddress}
</p:column>
<p:column headerText="E-Posta">
#{item.customerMail}
</p:column>
</p:dataTable>
</h:form>
</h:body>
And here is my back bean:
//some getter and setters
List<Customers> customer = new ArrayList<Customers>();
public List<Customers> getCustomer() {
return customer;
}
public void setCustomer(List<Customers> customer) {
this.customer = customer;
}
public String request() {
final RequestContext context = RequestContext.getCurrentInstance();
//System.out.println("Progress...");
//musteriSorgula(musteriSorgulaKriter());
new Thread(new Runnable() {
public void run() {
try {
musteriKodu = String.valueOf(musteriSorgula(musteriSorgulaKriter()).getMusteriBilgisi().getMusteriKodu());
List<TelefonBilgisi> tel_result = telefonSorgula(telefonSorgulaKriter(musteriKodu)).getMusteriTelefonListesi();
//telefon = tel_result.getMusteriTelefonListesi().get(0).getTelefonNo();
if (tel_result.size() > 0) {
for (TelefonBilgisi t : tel_result) {
telefon = t.getTelefonNo();
}
} else {
telefon = "No telephone.";
}
List<UavtAdresBilgisi> uavt_result = uavtAdresSorgula(uavtAdresSorgulaKriter(musteriKodu)).getMusteriUavtAdresListesi();
if (uavt_result.size() > 0) {
for (UavtAdresBilgisi u : uavt_result) {
adres = String.valueOf(u.getSehir()) + ", " + String.valueOf(u.getBucak()) + ", " + String.valueOf(u.getKasaba());
}
} else {
adres = "No address.";
}
Customers cust = new Customers(musteriTipi, BigInteger.valueOf(Long.valueOf(musteriKodu)), adFirmaAdi, soyadUnvan, telefon, adres, mail, projectId);
if (!customer.contains(cust)) {
customer.add(cust);
System.out.println("Customer has been added.");
} else {
System.out.println("Customer is still in the list.");
}
} catch (Exception ex) {
Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);
context.execute("alert('Try again.')");
}
}
}).start();
context.execute("panelwv.close()");
return "";
}
The back bean could connect to webservice and gether the info, I can see that in the logs. In the beginning my datatable is empty. What I want is to show the new data as the webservice responses. context.update("personList") doesn't work when I place it below:
customer.add(cust);
If someone could help me I would be greatly appriciated.
<f:ajax execute="#form" render=":personList" ></f:ajax>
Make a change as
<f:ajax execute="#form" update="persontable" render=":personList" ></f:ajax>
Ok so what you want to do is to force the client to update the data table from your server. Take a look at comet and push technology and also (if you don't need to support older browsers) WebSocket.
If you google around you'll find tutorials on how to do it using JSF. And as you are using Primefaces, not that this library has comet support: checkout p:push and atmosphere support.
This problem is easy to solve if you use RichFaces
I would prefer using RemoteCommand component as #Ömer said.
Try use it at the end of the thread(inside the thread braces) with context.execute("updater();");

Categories

Resources