Selam arkadaslar.Ben de Datatbalede boyle bir sorun var.Ben Insert Butonuna klick edib verini kayit ediyorum.Bazaya yaziliyor ama datatablede gostermiyor.Sayfayi yenileyende gosteriyor.Ben kayit yapdiktan sonra sayfayi yenilemeden de verini datatablede gostermek isdiyorum.Yardimci olursaniz sevinirim.Projeni https://www.dropbox.com/s/rc6r5usdoefm6ux/EJB_JSF.rar bu adresden indire bilirsiniz. (index.xhtml)

<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:p="http://primefaces.org/ui"> <h:head> <title>Facelet Title</title> </h:head> <h:body> <h:form> <p:commandbutton value="Insert" icon="ui-icon-circle-plus" oncomplete="dlgInsertEmp.show();"/> </h:form>
    <h:form id="employee" >
        <p:dataTable id="form" value="#{empctr.employees}" var="emp"  paginator="true" rows="5"
                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                     rowsPerPageTemplate="5,10,15"   >
            <f:facet name="header">
                Employee LIST
            </f:facet>
            <p:column sortBy="#{emp.id}" filterBy="#{emp.id}" headerText="ID">  
                <h:outputText value="#{emp.id}" />  
            </p:column> 
            <p:column sortBy="#{emp.name}" filterBy="#{emp.name}" headerText="NAME">  
                <h:outputText value="#{emp.name}" />  
            </p:column> 
            <p:column sortBy="#{emp.surname}" filterBy="#{emp.surname}" headerText="SURNAME">  
                <h:outputText value="#{emp.surname}" />  
            </p:column>

            <p:column style="width:4%">  
                <p:commandButton  update=":employee" oncomplete="carDialog.show()" icon="ui-icon-pencil" title="Edit"/>  
                <p:commandButton  update=":employee" oncomplete="carDialog.show()" icon="ui-icon-closethick" title="Delete"/> 
            </p:column>

        </p:dataTable><br/>
    </h:form>

    <h:form id="frmInsertEmp">
        <p:dialog header="New Employee" widgetVar="dlgInsertEmp" resizable="false" id="dlgInsertEmp" modal="true">  
             <p:growl id="growl" showDetail="true" sticky="true" /> 
            <h:panelGrid id="pgInsertEmp" columns="2" cellpadding="4" style="margin:0 auto;">

                <h:outputText value="Name:" />  
                <p:inputText style="width: 150px" value="#{empctr.name}"/>

                <h:outputText value="Surname:" />  
                <p:inputText style="width: 150px" value="#{empctr.surname}" />

            </h:panelGrid>  
            <p:separator/>
            <p:commandButton  update=":frmInsertEmp,growl" actionListener="#{empctr.insertEmp(actionEvent)}" oncomplete="dlgInsertEmp.hide()" value="Save" icon="ui-icon-check" title="Save"/>  
            <p:commandButton  update=":frmInsertEmp" oncomplete="dlgInsertEmp.hide()" value="Cancel" icon="ui-icon-closethick" title="Cancel"/>

        </p:dialog>  
    </h:form>
</h:body>
</html>

(Employee.java) package az.mb.ejb; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id;

@Entity public class Employee implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id;

private String name;
private String surname;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getSurname() {
    return surname;
}

public void setSurname(String surname) {
    this.surname = surname;
}

@Override
public int hashCode() {
    int hash = 0;
    hash += (int) id;
    return hash;
}

@Override
public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof Employee)) {
        return false;
    }
    Employee other = (Employee) object;
    if (this.id != other.id) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "az.mb.ejb.Employee[ id=" + id + " ]";
}

}

(EmployeeBean.java)

package az.mb.ejb; import java.util.List; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext;

@Stateless public class EmployeeBean implements EmployeeBeanLocal {

@PersistenceContext(unitName="EJB_JSFPU")
EntityManager em;

public List<Employee>  listEmployee(){
return em.createQuery("Select e From Employee e").getResultList();
}

public  void insertEmployee(Employee e){
em.persist(e);
}

public void updateEmployee(Employee e){
em.merge(e);
}

public Employee findById(int id){
return em.find(Employee.class, id);
}

public void deleteEmp(int id){
Employee e = em.find(Employee.class, id);
if(e !=null){
em.remove(e);
}
}

}

(EmployeeBeanLoacal.java)

package az.mb.ejb; import java.util.List; import javax.ejb.Local; @Local public interface EmployeeBeanLocal { public List<employee> listEmployee(); void insertEmployee(Employee e); void updateEmployee(Employee e); public Employee findById(int id); void deleteEmp(int id); }

(EmployeeController.java)

package az.mb.ejb; import java.util.ArrayList; import java.util.List; import javax.ejb.EJB; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent;

@ManagedBean(name="empctr") @SessionScoped public class EmployeeController { Employee e ; private List<employee> employees; private int id; private String name; private String surname;

@EJB EmployeeBeanLocal local;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getSurname() {
    return surname;
}

public void setSurname(String surname) {
    this.surname = surname;
}

 public EmployeeController() {
    e= new Employee();
}

 public Employee getE() {
    return e;
}

public void setE(Employee e) {
    this.e = e;
}

 public void insertEmp(ActionEvent actionEvent){
e = new Employee();
e.setId(id);
e.setName(name);
e.setSurname(surname);
local.insertEmployee(e);
FacesContext context = FacesContext.getCurrentInstance();  
context.addMessage(null, new FacesMessage("Successful saved data."));  
}

public List<Employee>  getEmployees() {
    employees = new ArrayList<Employee>();
   employees = local.listEmployee();
    return employees;
}

public void setEmployees(List<Employee>  employees) {
    this.employees = employees;
}

}

soruldu: 05 May '13, 21:12

Elxan's gravatar image

Elxan
135161924
cevap kabul oranı: 14%

değiştirildi: 06 May '13, 03:44

CemIkta's gravatar image

CemIkta ♦
19.9k29125190

insertEmp metodunun içinde local.insertEmployee(e); sonra getEmployees() metodunu çağırman yeterli olacaktır.

(06 May '13, 00:32) Turgay Can Turgay%20Can's gravatar image

<p:commandButton  update=":frmInsertEmp,growl" actionListener="#{empctr.insertEmp(actionEvent)}" oncomplete="dlgInsertEmp.hide()" value="Save" icon="ui-icon-check" title="Save"/>

Bu satırda employee formunu / tablosunu güncellemeyi unutmuşsunuz gibi görünüyor. Bir de bu şekilde dener misiniz?

<p:commandButton update=":employee:form,:frmInsertEmp,growl" actionListener="#{empctr.insertEmp(actionEvent)}" oncomplete="dlgInsertEmp.hide()" value="Save" icon="ui-icon-check" title="Save"/>
permanent link

cevaplandı: 07 May '13, 00:46

OguzOzkeroglu's gravatar image

OguzOzkeroglu
2.5k32939
cevap kabul oranı: 40%

Sadece datatable i güncellemek istiyorsan update=":formId:datatableId" şeklinde update etmen lazım.

permanent link

cevaplandı: 21 Haz '13, 07:13

Ekici's gravatar image

Ekici
12691217
cevap kabul oranı: 25%

Cevabınız
toggle preview

Bu soruyu takip et

E-Posta üzerinden:

Üyelik girişi yaptıktan sonra abonelik işlemlerini yapabilirsiniz

RSS üzerinden:

Cevaplar

Cevaplar ve Yorumlar

Yazı Formatlama

  • *italic* ya da _italic_
  • **bold** ya da __bold__
  • link:[text](http://url.com/ "başlık")
  • resim?![alt text](/path/img.jpg "başlık")
  • liste: 1. Foo 2. Bar
  • temel HTML etiketleri de kullanılabilir

Bu sorunun etiketleri:

×1,076
×281
×97

Soruldu: 05 May '13, 21:12

Görüntüleme: 1,654 kez

Son güncelleme: 21 Haz '13, 07:13

powered by BitNami OSQA