Static object in viewScoped bean for place holder of fileUpload multiples - java

I'm using a primefaces fileUpload with multiples and fileUploadListener method. The listener is called each time for each file uploaded, I would like to store each file in a arrayList and after the last is uploaded loop through the list and store them in a database.
My managed bean is viewScoped, would it be alright to have a static arrayList to store the uploads or is there a better way to deal with this?
Facelet
<p:fieldset legend="Info">
<p:selectOneRadio id="newold" value="#{newmailer.selectedCompStatus}">
<f:selectItem itemLabel="Existing Company" itemValue="exist" />
<f:selectItem itemLabel="New Company" itemValue="new" />
<p:ajax listener="#{newmailer.setComp}" event="valueChange" update="main" execute="#all" />
</p:selectOneRadio>
<p:panelGrid columns="2" styleClass="Grid" style="margin-bottom:10px" cellpadding="5" rendered="#{newmailer.exist}">
<h:outputLabel value="Company" id="Company" />
<p:selectOneMenu value="#{newmailer.selectedComp}" id="companies" label="Company">
<f:selectItem itemLabel="Choose Company" itemValue="" />
<f:selectItems value="#{mailerInfo.companies}" var="comp" />
<p:ajax listener="#{demo.getCompanyMailer}" event="valueChange" execute="#all" />
</p:selectOneMenu>
</p:panelGrid>
<p:panelGrid id="newPanel" styleClass="Grid" columns="2" style="margin-bottom:10px" cellpadding="5" rendered="#{!newmailer.exist and newmailer.showInfo}">
<h:outputLabel value="Company" id="Company2" />
<p:inputText id="newCompany" value="#{newmailer.selectedComp}" immediate="true">
<f:ajax event="change"/>
</p:inputText>
</p:panelGrid>
<p:panelGrid styleClass="Grid" columns="2" style="margin-bottom:10px" cellpadding="5" rendered="#{newmailer.showInfo}">
<h:outputLabel value="Mailer Id" />
<p:inputText id="mailerId" value="#{newmailer.mailerId}" immediate="true">
<f:ajax event="change"/>
</p:inputText>
</p:panelGrid>
</p:fieldset>
<p:fieldset legend="Status" rendered="#{newmailer.showInfo}">
<p:selectOneRadio id="status" value="#{newmailer.status}" immediate="true">
<f:selectItem itemLabel="Active" itemValue="A" />
<f:selectItem itemLabel="Inactive" itemValue="I" />
<f:ajax event="change"/>
</p:selectOneRadio>
</p:fieldset>
<p:fieldset legend="Description" rendered="#{newmailer.showInfo}">
<p:inputTextarea rows="5" cols="30" value ="#{newmailer.desc}" counter="counter" maxlength="10"
counterTemplate="{0} characters remaining." autoResize="false" immediate="true">
<f:ajax event="change"/>
</p:inputTextarea>
</p:fieldset>
<p:fieldset legend="Load Image" rendered="#{newmailer.showInfo}">
<p:fileUpload fileUploadListener="#{newmailer.handleFileUpload}"
mode="advanced"
update="messages"
sizeLimit="100000"
allowTypes="/(\.|\/)(gif|jpe?g|png|pdf)$/"
process="#form"
multiple="true"
/>
</p:fieldset>
<p:growl id="messages" showDetail="true"/>
</p:panelGrid>
<!-- <p:commandButton value="Submit" type="sumbit" action="#{newmailer.submit}" ajax="false"/>-->
</h:form>
Bean
#ViewScoped
#ManagedBean(name="newmailer")
public class NewMailerBean implements Serializable{
private String status;
private String compStatus;
private String selectedCompStatus;
private String selectedComp;
private String mailerId;
private String desc;
private boolean exist;
private boolean showInfo;
public static Mailer mail;
public static boolean multi=false;
public ArrayList<byte []> images = new ArrayList<byte []>();
public void handleFileUpload(FileUploadEvent event) {
Mailer mail = new Mailer();
mail.setCompany(selectedComp);
mail.setDesc(desc);
mail.setMailerId(mailerId);
mail.setStatus(status);
mail.setUserId("test");
try{
InputStream inputStream = event.getFile().getInputstream();
ByteArrayOutputStream out=new ByteArrayOutputStream(1024);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
byte[] bytearray = out.toByteArray();
inputStream.close();
out.flush();
out.close();
images.add(bytearray);
mail.setImg(bytearray);
}catch(IOException e) {
e.printStackTrace();
}

A static variable is class-level and thus shared among all instances of the same class and thus behaves like as a global application-wide variable. Every single visitor of your webapp would share the very same variable. Every single uploaded file of every single visitor would end up in the same list which is in turn visible to every single visitor.
Is this what you really want?
I don't think so. Just don't make it a static variable at all. Remove the static modifier and you should be all set with a view scoped bean. A view scoped bean lives as long as you're interacting with the same view by ajax.
See also:
Basic Java tutorial - Understanding instance and class members
How to choose the right bean scope?

Related

Can't get submit button work

I am new to java and trying to learn how to add data into database.
I cannot make my submit button work. I am getting error of "target unreachable". I am using hibernate and phpMyAdmin.
As I said I new to this. Please let me know if I am missing information that needed.
Instead of calling class in my submit button should I create private String method for the text boxes?
I am confused.
Thanks a lot for your help.
additem.xhtml
<h:body>
<ui:composition template="template.xhtml">
<ui:define name="content">
<h1>Add a New Item</h1>
<br />
<h:form>
<p:panel id="panel" header="Enter an Item" style="margin-bottom:20px;">
<p:growl id="growl" showDetail="true" sticky="false" />
<h:outputLabel value="Item Number" />Item Number:
<p:inputText value="#{LibraryItem.itemNumber}" />
<br />
<h:outputLabel value="Title" />Title:
<p:inputText value="#{LibraryItem.title}" />
<br />
<h:outputLabel for="type" value="Type">Item Type:
<p:selectOneMenu value="#{libraryItem.type}" style="width:228px">
<f:selectItem itemValue="" itemLabel="Select One" />
<f:selectItem itemValue="book" itemLabel="Book" />
<f:selectItem itemValue="magazine" itemLabel="Magazine" />
<f:selectItem itemValue="movie" itemLabel="Movie" />
<f:selectItem itemValue="music" itemLabel="Music" />
</p:selectOneMenu>
</h:outputLabel>
<br />
<h:outputLabel value="Status" />Status:
<p:inputText value="#{LibraryItem.status}" />
<br />
<p:commandButton value="Submit" actionListener="#{AddLibraryItem.addItem}" update="growl" />
<br />
</p:panel>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
AddLibraryItem.java
#Named
#ManagedBean
#Scope("request")
public class AddLibraryItem {
//no arg constructor
public AddLibraryItem(){
}
#Inject private LibraryItem libraryItem;
#Inject private ILibraryService libraryService;
public String addItem(){
//return value
String returnValue = "success";
//assign values
libraryItem.setStatus("CHECKED_IN");
//add to library
try {
libraryService.add(libraryItem);
displayMessage("Success","Item added");
}catch (Exception e){
displayMessage("Error", e.toString());
return "fail";
}
return returnValue;
}
//Getters and Setters
public LibraryItem getLibraryItem() {
return libraryItem;
}
public void setLibraryItem(LibraryItem libraryItem) {
this.libraryItem = libraryItem;
}
public ILibraryService getLibraryService() {
return libraryService;
}
public void setLibraryService(ILibraryService libraryService) {
this.libraryService = libraryService;
}
//method to display messages
private void displayMessage(String title, String message){
//get faces context
FacesContext currentInstance = FacesContext.getCurrentInstance();
//message to show
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO, title, message);
//display the message
currentInstance.addMessage(null, fm);
}
}

How I pass values from one JSF to another while both are backed by separate Request scoped managed beans

I have gone through a few answers on this topic already, especially from BalusC blogs. But its somehow not working in the implementation below. Am I missing something or doing something completely wrong.
I have a basic form with a few dropdowns, when I submit the form i.e. call submitDetails it returns the following String "phaseTwo?faces-redirect=true" which is backed by bean called PhaseTwoController.java
So on submit from phaseOne.xhtml I want to see phaseTwo.xhtml with values selected on phaseOne.xhtml
Here is the code:
THis is PhaseOne.xhtml backed by PhaseOneController.java
<h:form>
<p:panel header="Select country" style="margin-bottom:10px;">
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="country" value="Country: " />
<p:selectOneMenu id="country" value="#{phaseOneController.country}" style="width:150px">
<p:ajax listener="#{phaseOneController.onCountryChange}" update="subCategory" />
<f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{phaseOneController.countries}" />
</p:selectOneMenu>
<p:outputLabel for="province" value="Province: " />
<p:selectOneMenu id="province" value="#{phaseOneController.province}" style="width:150px">
<p:ajax listener="#{phaseOneController.onProvinceChange}" update="city" />
<f:selectItem itemLabel="Select Province" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{phaseOneController.provinces}" />
</p:selectOneMenu>
<p:outputLabel for="city" value="City: " />
<p:selectOneMenu id="city" value="#{phaseOneController.city}" style="width:150px">
<f:selectItem itemLabel="Select City" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{phaseOneController.cities}" />
</p:selectOneMenu>
</h:panelGrid>
<p:separator />
<p:commandButton value="Select" actionListener="#{phaseOneController.submitDetails}" icon="ui-icon-check">
<f:param name="country" value="#{phaseOneController.country}" />
<f:param name="province" value="#{phaseOneController.province}" />
<f:param name="city" value="#{phaseOneController.city}" />
</p:commandButton>
</p:panel>
</h:form>
#ManagedBean
#RequestScoped
public class PhaseTwoController {
#ManagedProperty(value="#{param.country}")
private String country;
#ManagedProperty(value="#{param.province}")
private String province;
public void setCountry(String country) {
this.country = country;
}
public void setProvince(String province) {
this.province = province;
}
public void setCity(String city) {
this.city = city;
}
}
P.S. I havent posted the code for PhaseOneController.java as I am not sure if it is needed. But if someone wants to look at it, I can post it.

Forward variable on the next page

I have a Users table. Added, view and delete work. But I have problem to edit.
My list page:
<h:form id="form">
<p:dataTable styleClass="table" value="#{userMB.allAdmins}" var="admin" paginator="true" rows="15" rowKey="#{admin.id}" selection="#{userMB.user}" selectionMode="single">
<f:facet name="header">
Lista administratorów
</f:facet>
<p:column headerText="#{msg.firstName}">
<h:outputText value="#{admin.firstName}" />
</p:column>
<p:column headerText="#{msg.lastName}">
<h:outputText value="#{admin.lastName}" />
</p:column>
<p:column headerText="#{msg.personalId}">
<h:outputText value="#{admin.personalId}" />
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButton" value="#{msg.info}" icon="ui-icon-search"
update=":form:display" oncomplete="userDialog.show()"/>
<p:commandButton action="#{userMB.createStart()}" value="#{msg.add}" icon="ui-icon-plus" />
<p:commandButton action="#{userMB.editStart()}" value="#{msg.edit}" >
<f:setPropertyActionListener target="#{userMB.user}" value="#{userMB.user}" />
</p:commandButton>
<p:commandButton action="#{userMB.deleteUser()}" value="#{msg.delete}" icon="ui-icon-close"/>
</f:facet>
</p:dataTable>
<p:dialog id="dialog" header="Administrator" widgetVar="userDialog" resizable="false"
width="300" showEffect="clip" hideEffect="explode">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<p:graphicImage value="./../../images/person4.png" width="150" height="150"/>
</f:facet>
<h:outputText value="#{msg.firstName}" />
<h:outputText value="#{userMB.user.firstName}" />
<h:outputText value="#{msg.lastName}" />
<h:outputText value="#{userMB.user.lastName}" />
<h:outputText value="#{msg.personalId}" />
<h:outputText value="#{userMB.user.personalId}" />
</h:panelGrid>
</p:dialog>
</h:form>
I want to send the selected user on the next page:
I use aciontListener:
<p:commandButton action="#{userMB.editStart()}" value="#{msg.edit}" >
<f:setPropertyActionListener target="#{userMB.user}" value="#{userMB.user}" />
</p:commandButton>
My edit page where I want to send user:
<h:form>
<div id="userPanel">
<h:inputHidden value="#{userMB.user}" />
<p:panel id="panelUser" header="Edytuj administratora" >
<div id="panelImage">
<img src="./../../images/person4.png" alt="person" width="150px" height="130px"/>
</div>
<h:panelGrid columns="3">
<p:outputLabel for="firstName" value="#{msg.firstName}"></p:outputLabel>
<p:inputText id="firstName" value="#{userMB.user.firstName}" label="#{msg.firstName}" required="true">
<f:validator validatorId="nameValidator" />
<p:ajax update="msgFristName" event="keyup" />
</p:inputText>
<p:message for="firstName" id="msgFristName"/>
<p:outputLabel for="lastName" value="#{msg.lastName}"></p:outputLabel>
<p:inputText id="lastName" value="#{userMB.user.lastName}" label="#{msg.lastName}" required="true">
<f:validator validatorId="nameValidator" />
<p:ajax update="msgLastName" event="keyup" />
</p:inputText>
<p:message for="lastName" id="msgLastName"/>
<p:outputLabel for="personalId" value="#{msg.personalId}"></p:outputLabel>
<p:inputText id="personalId" value="#{userMB.user.personalId}" label="#{msg.personalId}" required="true">
<f:validator validatorId="personalIdValidator" />
<p:ajax update="msgPersonalId" event="keyup" />
</p:inputText>
<p:message for="personalId" id="msgPersonalId"/>
<p:outputLabel for="password" value="#{msg.password}"></p:outputLabel>
</p:panel>
</div>
</h:form>
I added: <h:inputHidden value="#{userMB.user}" /> but I do not see data user, only empty field. How do I send this person? I used once this method in other project, a little different without primefaces and it worked. Why now does not work?
Method editStart:
public String editStart() {
return "editStart";
}
faces-config:
<navigation-case>
<from-outcome>editStart</from-outcome>
<to-view-id>/protected/admin/adminEdit.xhtml</to-view-id>
<redirect/>
</navigation-case>
When I'm on the side adminEdit I edited the pool and do editUser method:
public String editUser() {
FacesContext context = FacesContext.getCurrentInstance();
Map requestParameterMap = (Map) context.getExternalContext().getRequestParameterMap();
try {
String userRole = requestParameterMap.get("userRole").toString();
String active = requestParameterMap.get("active").toString();
Boolean act = Boolean.parseBoolean(active);
user.setRole(userRole);
user.setActive(act);
userDao.update(user);
} catch (EJBException e) {
sendErrorMessageToUser("Edit error");
return null;
}
sendInfoMessageToUser("Account edited");
return user.getRole() + "List";
}
My method editStart use only for navigation.
You can either consider Przemek's answer or use one of the 4 ways of passing a parameter to a backing bean.
1. Method expression
2. f:param
3. f:atribute
4. f:setPropertyActionListener
For very well explained full explanation refer to this
It has easy to understand examples. Take a look and pick what fits your needs.
Or simply:
In the actual managed bean...
public String navigationButtonListener(User parameter) {
FacesContext.getCurrentInstance().getExternalContext().getRequestMap()
.put("parameterAttribute", parameter);
return "my-destination-page";
}
In the destination managed bean...
#PostConstruct
public void init(){
myAttribute= (User) FacesContext.getCurrentInstance()
.getExternalContext().getRequestMap().get("parameterAttribute");
}
Good Luck!
You can pass your userid through the session.
Add a parameter to your commandLink
<p:commandButton action="#{userMB.editStart()}" value="#{msg.edit}>
<f:param name="userId" value="#{userMB.user.id}" />
</p:commandButton>
In your backing bean do this
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest myRequest = (HttpServletRequest)context.getExternalContext().getRequest();
HttpSession mySession = myRequest.getSession();
Integer userId = Integer.parseInt(myRequest.getParameter("userId"));
After that you can reload the user you want to edit with the Id you got

primefaces partial processing not working

I would like to use partial processing but it does not work in my code. Does anybody knows why?
<h:form id="frmVehicle" prependId="false">
<p:toolbar styleClass="form_toolbar">
<p:toolbarGroup>
<p:commandButton id="save" process="#(form :not(.noprocess))" ajax="false" value="#{uimsgs.save}" action="#{vmsVehicleActionBean.save()}"
</p:toolbarGroup>
</p:toolbar>
<p:messages id="vmsgs" severity="error,warn" autoUpdate="true" />
<p:tabView id="tabViewSections" orientation="left" styleClass="ses-ui-tabs-left">
<p:tab title="#{vms_uimsgs['vehicle.tab.data']}">
<p:panelGrid id="gridHeader" columns="4" columnClasses="form-label,form-input,form-label,form-input" styleClass="form-grid" >
<p:outputLabel for="kmStatus" value="#{vms_uimsgs['vehicle.kmStatus']}" />
<p:inputText id="kmStatus" value="#{vmsVehicleActionBean.vehicle.kmStatus}"/>
<p:outputLabel for="powerKw" value="#{vms_uimsgs['vehicle.power']}" />
<p:inputText id="powerKw" styleclass="noprocess" value="#{vmsVehicleActionBean.powerKw}">
<p:ajax event="keyup" update="powerPs" />
</p:inputText>
<p:outputLabel value="kw" />
<p:inputText id="powerPs" styleclass="noprocess" value="#{vmsVehicleActionBean.powerPs}">
<p:ajax event="keyup" update="powerKw" />
</p:inputText>
<p:outputLabel value="ps" />
</p:panelGrid>
</p:tab>
</p:tabView>
</h:form>
The two setters (kw & ps ) are still processed. Any idea?
Well i created an example thats works for the standard Primefaces showcase. In your page i see something strange. styleclass="noprocess" are you sure you use this? The API says styleClass with a capital C.
Here is an example wich works oke:
<h:form id="form">
<p:toolbar id="tool">
<p:toolbarGroup id="group">
<p:commandButton value="All" ajax="true" id="btnAll" process="#(input:not(.noprocess))" actionListener="#{personBean.savePerson}" />
</p:toolbarGroup>
</p:toolbar>
<p:messages id="vmsgs" severity="error,warn" autoUpdate="true" />
<p:tabView id="tabViewSections">
<p:tab title="test" id="tab">
<p:panel header="Partial Process">
<p:panelGrid id="grid" columns="2">
<f:facet name="header">
<p:messages />
</f:facet>
<h:outputLabel for="firstname" value="Firstname:" />
<p:inputText id="firstname" value="#{personBean.firstname}" />
<h:outputLabel for="surname" value="Surname: *" />
<p:inputText id="surname" value="#{personBean.surname}" styleClass="noprocess">
</p:inputText>
</p:panelGrid>
</p:panel>
</p:tab>
</p:tabView>
</h:form>
And then bean:
public class PersonBean {
private String firstname;
private String surname;
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
System.out.println("Setted firstname: " +firstname);
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
System.out.println("Setted surname: " +surname);
}
public void savePerson(ActionEvent actionEvent) {
System.out.println("Fire action event");
}
}

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