2013-01-11 18 views
8

Her satırda silmek için bir komut satırı olan bir grup kullanıcı görüntüleyen bir PrimeFaces veri tablosuna sahibim. Bağlantı tıklandığında, bir teyeliDialog, destekleyici fasulyesinde "sil" yöntemini çağırması gereken bir "Evet" düğmesiyle görüntülenir. Ne yazık ki, bu yöntem çağrılmaz ve diyalog sadece gizlidir. Bağlantıdan gelen parametre, hata ayıklayıcı ile gördüğüm için ayarlandı.PrimeFaces commandButton onaylaDialog desteklenmeyen fasulye aranıyor

<?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"> 
<h:head><title>Manage users</title></h:head> 
<h:body> 
<ui:composition template="../../template/commonLayout.xhtml"> 
    <ui:define name="content"> 
     <p:layoutUnit position="center"> 
      <h:form id="datatable"> 
       <p:tabView> 
        <p:tab title="Users"> 
         <p:button value = "Add user" outcome="addUser.xhtml?faces-redirect=true"/> 
         <p:growl id="messages" showDetail="true"/> 
         <p:dataTable id="usersTable" var="user" value="#{userMB.userList}" paginator="true" rows="25" 
            paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"> 
          <p:ajax event="rowEdit" listener="#{userMB.onEditUser}" /> 
          <p:column headerText="First name"> 
           <h:outputText value="#{user.firstName}" /> 
          </p:column> 
          <p:column headerText="Last name"> 
           <h:outputText value="#{user.lastName}" /> 
          </p:column> 
          <p:column headerText="E-mail"> 
           <h:outputText value="#{user.email}" /> 
          </p:column> 
          <p:column headerText="Username"> 
           <h:outputText value="#{user.username}"/> 
          </p:column> 
          <p:column headerText="Hire date"> 
           <h:outputText value="#{user.hireDate}"> 
            <f:convertDateTime type="date" pattern="dd.MM.yyyy"/> 
           </h:outputText> 
          </p:column> 
          <p:column headerText="Working hours"> 
           <h:outputText value="#{user.workingHours}" /> 
          </p:column> 
          <p:column headerText="Vacation days"> 
           <h:outputText value="#{user.vacationDays}"/> 
          </p:column> 

          <p:column> 
           <h:link outcome="addUser" value="Edit"> 
            <f:param name="userID" value="#{user.id}" /> 
           </h:link> 
          </p:column> 
          <p:column> 
           <p:commandLink value="Delete" onclick="deleteConfirmDlg.show()"> 
            <f:setPropertyActionListener value="#{user}" target="#{userMB.currentUser}" /> 
           </p:commandLink> 
          </p:column>        
         </p:dataTable> 

         <p:confirmDialog id="deleteConfirmDialog" message="Are you sure?" header="Delete user" severity="alert" widgetVar="deleteConfirmDlg" appendToBody="true"> 
          <p:commandButton id="confirmDelete" value="Yes" oncomplete="deleteConfirmDlg.hide()" update="usersTable" actionListener="#{userMB.deleteUser}"/> 
          <p:commandButton id="declineDelete" value="No" onclick="deleteConfirmDlg.hide()" type="button"/> 
         </p:confirmDialog> 
        </p:tab> 
        <p:tab title="Teams"> 
         <p:button value = "Add team" outcome="addTeam.xhtml?faces-redirect=true"/> 
         <p:dataTable var="team" value="#{userMB.teamList}" paginator="true" rows="25" 
          paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"> 
          <p:column headerText="Name"> 
           <h:outputText value="#{team.name}" /> 
          </p:column> 
          <p:column headerText="Team leader"> 
           <h:outputText value="#{team.teamLeader.displayName}" /> 
          </p:column> 
         </p:dataTable> 
        </p:tab> 
       </p:tabView> 
      </h:form> 
    </p:layoutUnit> 
    </ui:define> 
</ui:composition> 

yedekleme fasulye yöntemi: İşte

benim sayfası

public void deleteUser(ActionEvent event) { 
    if (null != currentUser) { 
     // check if userID is set and delete 
     System.out.println("delete user with id " + currentUser.getId()); 
     userService.deleteUser(currentUser); 
     currentUser = new User(); 
    } 
} 

kontrol ettim ve bunun için en olağan olduğu gibi Formları iç içe geçmiş yok destekleyici aranıyor ...

İşte benim şablon filim es:

CommonLayout.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"> 
<h:head> 
<h:outputStylesheet library="css" name="default.css" /> 
</h:head> 
<h:body> 
<p:layout fullPage="true"> 
<div id ="header"> 
<ui:insert name="header"> 
    <ui:include src="commonHeader.xhtml"></ui:include> 
</ui:insert> 
</div> 
<div id="left-menu"> 
<ui:insert name="left-menu"> 
    <ui:include src="leftMenu.xhtml"></ui:include> 
</ui:insert> 
</div> 
<div id ="content"> 
<ui:insert name="content"> 
    <ui:include src="commonContent.xhtml"></ui:include> 
</ui:insert> 
</div> 
</p:layout> 
</h:body> 
</html> 

CommonHeader.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"> 
<h:head> 
</h:head> 
<h:body> 
    <ui:composition> 
     <p:layoutUnit position="north" size="100"> 
      <h:outputText value="Welcome #{request.remoteUser}!"/> <br /> 
      <a href="#{request.contextPath}/j_spring_security_logout">Logout</a><br /> 
     </p:layoutUnit> 
    </ui:composition> 
</h:body> 
</html> 

CommonContent.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"> 
<h:head> 
</h:head> 
<h:body> 
    <ui:composition> 
     <p:layoutUnit position="center"> 
       <ui:include src="../widgets/schedule.xhtml"/> 
     </p:layoutUnit> 
    </ui:composition> 
</h:body> 
</html> 

LeftMenu.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"> 
<h:head> 
</h:head> 
<h:body> 
    <ui:composition> 
     <p:layoutUnit position="west" size="200"> 
     <h:form> 
      <p:menu width="100%" rendered="#{request.isUserInRole('ROLE_MANAGER')}"> 
       <p:submenu label="Management"> 
        <p:menuitem value="Manage users" outcome="/pages/management/manageUsers.xhtml?faces-redirect=true"></p:menuitem> 
       </p:submenu> 
      </p:menu> 
      </h:form> 
    </p:layoutUnit> 
    </ui:composition> 
</h:body> 
</html> 

Ben PrimeFaces 3.4 ve JSF kullanıyorum 2.0

+2

Üzgünüz, ama tüm yazılarınızı okumadım bile. Tüm bu kod/metin gerçekten gerekli mi? Şerefe! – SimonSez

+1

Gerçekten çok fazla kod gürültüsü var (bunu gelecekteki sorularda en aza indirmeye çalışın), ama neyse ki tarif edilen semptom benim için problemin sebebini anlamak için yeterliydi. Hiç kimse kodu göremedi :) – BalusC

+0

Üzgünüz, Ayrıca, orada bir yerde başka iç içe geçmiş formlar olmadığından emin olmak için şablon dosyamı da dahil et. – AndaP

cevap

19

<p:confirmDialog ... appendToBody="true"> onayla iletişim kutusunun HTML gösterimi DOM esnasında JavaScript HTML <body> elemanın sonuna taşınacaktır neden olur hazır.

Ancak bu onayla iletişim kutusunun HTML gösterimi artık herhangi bir biçimde içeride olmadığını neden olur. Bu yüzden etkili bir şekilde bir form gönderilmemiştir ve istek parametreleri gönderilmemiştir ve bu yüzden JSF eylemi ortadan kaldıramayacaktır.

Sen <h:form> kendi iletişim onaylamak vermek gerekir.

<p:confirmDialog ...> 
    <h:form> 
     ... 
    </h:form> 
</p:confirmDialog> 

ve bakım sırasında karışıklık (iç içe formları, yani yasadışı) önlemek için, aynı zamanda, en az "dış" <h:form> sonra, şablonun sonuna bu bileşen taşımak göstermektedir.

+0

Diyaloğu formdan sonra taşıdım, maalesef şu anda bu güncelleme = ": datatable: usersTable" bileşeni bulunamıyor. Bunun, formun dışındaki bir bileşene başvurmanın yolu olduğunu düşündüm. – AndaP

+0

'', aynı zamanda bir adlandırma kabıdır. Bunun gibi sabit bir ID verin 've' update = "kullanın: datatable: tabs: usersTable" '. Ayrıca bkz. Http://stackoverflow.com/questions/8634156/how-to-reference-components-in-jsf-ajax-cannot-find-component-with-identifier/8644762#8644762 – BalusC

+0

Ayrıca numaralı telefona bir kimlik eklendi ve Şuan çalışıyor. Çok teşekkürler! – AndaP