我已经编写了一个用于保存和列出数据的jsf表单。为了在一个按钮中调用两个方法,我使用了f:actionListener.Data正在保存但是我不能在h上有任何数据:dataTable.Here是我的代码。
的index.xhtml
<h:form>
<h:panelGrid columns="3" border="0">
<h:outputText value="Personel adı"/>
<h:inputText value="#{kmb.personelad}" size="25" required="true"
requiredMessage="Lütfen personel adını giriniz!"
id="personeladi"/>
<h:message for="personeladi" style="color: red"/>
<h:outputText value="Personel soyadı"/>
<h:inputText value="#{kmb.personelsoyad}" size="25" required="true"
requiredMessage="Lütfen personel soyadını giriniz!"
id="personelsoyadi"/>
<h:message for="personelsoyadi" style="color: red"/>
<h:outputText value="Personel görevi"/>
<h:inputText value="#{kmb.personelgorev}" size="25" required="true"
requiredMessage="Lütfen personel görevini giriniz!"
id="personelgorevi"/>
<h:message for="personelgorevi" style="color: red"/>
<h:outputText value="Personel e-postası"/>
<h:inputText value="#{kmb.personeleposta}" size="25" required="true"
requiredMessage="Lütfen personel epostasını giriniz!"
id="personeleposta"/>
<h:message for="personeleposta" style="color: red"/>
<h:outputText value="Personel maaşı"/>
<h:inputText value="#{kmb.personelmaas}" size="25" required="true"
requiredMessage="Lütfen personel maaşını giriniz!"
id="personelmaasi"/>
<h:message for="personelmaasi" style="color: red"/>
<h:commandButton value="Kaydet" action="#{kmb.veriEkle}" id="kayit">
<f:actionListener type="com.mesutemre.ListeleManagedBean"/>
</h:commandButton>
<h:commandButton value="Temizle" type="reset"/>
<h:outputText value=""/>
<br/><br/>
<h:dataTable value="#{lmb.liste}" var="l" border="1" id="tablo">
<h:column>
<f:facet name="header">PERSONEL ADI</f:facet>
#{l.ad}
</h:column>
<h:column>
<f:facet name="header">PERSONEL SOYADI</f:facet>
#{l.soyad}
</h:column>
<h:column>
<f:facet name="header">PERSONEL E-POSTA</f:facet>
#{l.eposta}
</h:column>
<h:column>
<f:facet name="header">PERSONEL GÖREVİ</f:facet>
#{l.gorev}
</h:column>
<h:column>
<f:facet name="header">PERSONEL MAAŞI</f:facet>
#{l.maas}
</h:column>
</h:dataTable>
</h:panelGrid>
<h:messages globalOnly="true" style="color: red"/>
</h:form>
ManagedBean就在这里;
public class ListeleManagedBean implements ActionListener {
private List<Personel> liste = new ArrayList<Personel>();
private MySQLBaglantisi msb = new MySQLBaglantisi();
public List<Personel> getListe() {
return liste;
}
public void setListe(List<Personel> liste) {
this.liste = liste;
}
public void processAction(ActionEvent event) throws AbortProcessingException {
msb.baglan();
String sql = "SELECT * FROM jsfapp.personel";
try {
PreparedStatement pstmt = (PreparedStatement) msb.getConnection().prepareStatement(sql);
ResultSet resultSet = pstmt.executeQuery();
while (resultSet.next()) {
liste.add(new Personel(resultSet.getString(1), resultSet.getString(2),
resultSet.getString(3), resultSet.getString(4), resultSet.getString(5)));
}
} catch (Exception e) {
e.printStackTrace();
}
for (int i = 0; i < liste.size(); i++) {
System.out.println(liste.get(i).getAd());
}
}
}
为什么我在h:dataTable上看不到任何数据?