2017-04-15 1 views
0

Ich versuche Bootstrap in meine Webanwendung zu integrieren. Jetzt möchte ich eine Schaltfläche erstellen und nachdem ich darauf geklickt habe, wird ein Dialog angezeigt. Dies ist erfolgreich, wenn meine xhtml-Seite h: Formular nicht enthält, aber sobald meine XHTML-Seite h zeigt: Formular das Modell kann nicht angezeigt werden.Bootstrap Modal kann nicht innerhalb angezeigt werden <h:form>

Bellow ist die Taste:

<div class="panel panel-default"> 
 
         <div class="panel-heading"> 
 
          Modals 
 
         </div> 
 
         
 
         <div class="panel-body"> 
 
          <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> 
 
           Launch Demo Modal 
 
          </button> 
 
          <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
 
           <div class="modal-dialog"> 
 
            <div class="modal-content"> 
 
             <div class="modal-header"> 
 
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
 
              <h4 class="modal-title" id="myModalLabel">Modal title</h4> 
 
             </div> 
 
             <div class="modal-body"> 
 
              Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
 
             </div> 
 
             <div class="modal-footer"> 
 
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
 
              <button type="button" class="btn btn-primary">Save changes</button> 
 
             </div> 
 
            </div> 
 
           </div> 
 
          </div> 
 
         </div> 
 
        </div>

Dies ist meine xhtml Seite einschließlich der Taste modaler:

<!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:ui="http://java.sun.com/jsf/facelets" 
 
     xmlns:f="http://java.sun.com/jsf/core" 
 
     xmlns:h="http://java.sun.com/jsf/html" 
 
     xmlns:p="http://primefaces.org/ui" 
 
     template="/pages/indexTemplate.xhtml"> 
 

 
\t <h:head> 
 
    \t <title>SLEAM Book | Consult a Facebooker</title> 
 
     <link rel="shortcut icon" type="image/x-icon" href="#{resource['icons/hki2.gif']}"/> 
 
     <style> 
 
\t \t \t .ui-datatable thead th, .ui-datatable tbody td, .ui-datatable tfoot td { 
 
    \t \t border-style: none; 
 
     </style> 
 
    </h:head> 
 
\t <h:body> 
 
    \t <ui:composition template="indexTemplate.xhtml"> 
 
\t \t \t <ui:define name = "content"> 
 
     \t \t <h:form> 
 
      \t \t <h:outputText value="Add a Publication" styleClass="text-primary"/> 
 
      \t \t <br/><br/> 
 
      \t \t \t <h:inputText value="#{userBean.publicationContent}" styleClass="form-control"/> 
 
      \t \t \t <br/> 
 
      \t \t \t <p:commandButton value="Post" 
 
\t \t \t \t \t \t \t \t \t action="#{userBean.createPublication}" 
 
\t \t \t \t \t \t \t \t \t styleClass="btn btn-primary" 
 
\t \t \t \t \t \t \t \t \t id="btn" ajax="true"/> 
 
\t \t \t \t \t #{userBean.lps.size()} 
 
\t \t \t \t \t <div class="panel panel-default"> 
 
         <div class="panel-heading"> 
 
          Modals 
 
         </div> 
 
         
 
         <div class="panel-body"> 
 
          <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> 
 
           Launch Demo Modal 
 
          </button> 
 
          <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
 
           <div class="modal-dialog"> 
 
            <div class="modal-content"> 
 
             <div class="modal-header"> 
 
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
 
              <h4 class="modal-title" id="myModalLabel">Modal title</h4> 
 
             </div> 
 
             <div class="modal-body"> 
 
              Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
 
             </div> 
 
             <div class="modal-footer"> 
 
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
 
              <button type="button" class="btn btn-primary">Save changes</button> 
 
             </div> 
 
            </div> 
 
           </div> 
 
          </div> 
 
         </div> 
 
        </div> 
 
\t \t \t \t \t <br/><br/><br/> 
 
\t \t \t \t \t <div class="table-responsive"> 
 
    \t \t \t \t \t <p:dataTable var="car" value="#{userBean.lps}" tableStyleClass="table table-striped"> 
 
\t \t \t \t \t   <f:facet name="header"> 
 
\t \t \t \t \t    List Of Publications 
 
\t \t \t \t \t   </f:facet> 
 
\t \t \t \t \t   <p:column headerText="Id"> 
 
\t \t \t \t \t    <h:outputText value="#{car.id}" /> 
 
\t \t \t \t \t   </p:column> 
 
\t \t \t \t \t   <p:column headerText="Title"> 
 
\t \t \t \t \t    <h:outputText value="#{car.title}" /> 
 
\t \t \t \t \t   </p:column> 
 
     \t \t \t \t \t <p:column style="width:32px;text-align: center"> 
 
\t \t \t \t \t \t \t \t <p:commandButton value="Post" 
 
\t \t \t \t \t \t \t \t \t \t \t \t id="btn" 
 
\t \t \t \t \t \t \t \t \t \t \t \t ajax="true" 
 
\t \t \t \t \t \t \t \t \t \t \t \t styleClass="btn btn-primary"/> 
 
     \t \t \t \t \t </p:column> 
 
    \t \t \t \t \t </p:dataTable> 
 
\t \t \t \t \t \t <p:dialog header="Car Info" widgetVar="carDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false"> 
 
     \t \t \t \t \t <p:outputPanel id="carDetail" style="text-align:center;"> 
 
\t    \t \t \t \t <p:panelGrid columns="2" rendered="#{not empty userBean.selectedPublication}" columnClasses="label,value"> 
 
\t \t     \t \t \t \t <h:outputText value="Id:" /> 
 
\t \t \t \t \t     <h:outputText value="#{userBean.selectedPublication.id}" /> 
 
\t \t \t \t \t 
 
\t \t \t \t \t     <h:outputText value="Title" /> 
 
\t \t \t \t \t     <h:outputText value="#{userBean.selectedPublication.title}" /> 
 
\t    \t \t \t \t </p:panelGrid> 
 
     \t \t \t \t \t </p:outputPanel> 
 
    \t \t \t \t \t </p:dialog> 
 
\t \t \t \t \t </div> \t \t 
 
\t \t \t \t </h:form> 
 
      \t </ui:define> 
 
    \t \t </ui:composition> 
 
\t </h:body> 
 
</html>

Die Datei Gesichter-config.xml ist:

<?xml version="1.0" encoding="UTF-8"?> 
 
<faces-config 
 
    xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd" 
 
    version="2.2"> 
 

 
</faces-config>

Haben Sie eine Ahnung bitte über dieses Problem Festsetzung?. Danke vielmals.

+0

Können Sie enthalten, was die JSF wie – Sasang

+0

sieht Hallo @Sasang, ich habe jsf 2.2 benutzt. Ich habe meine vollständige xhtml-Seite sowie die Datei faces-config.xml auf meiner aktualisierten Frage geteilt. Könnten Sie bitte einen Blick darauf werfen? Danke vielmals. – Nerimen

Antwort

0

Sie wie das versuchen könnte:

<p:commandLink value="Edit" styleClass="btn btn-primary" onclick="$('#myModal').modal('show');" update=":myForm" immediate="true"/> 
 
\t \t \t \t \t \t \t \t <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModal" aria-hidden="true" data-keyboard="false" data-backdrop="static"> 
 
\t \t \t \t \t \t \t \t  <div class="modal-dialog modal-sm"> 
 
\t \t \t \t \t \t \t \t   <div class="modal-content"> 
 
\t \t \t \t \t \t \t \t    <h:form id="myForm"> 
 
\t \t \t \t \t \t \t \t     <div class="modal-header"> 
 
\t \t \t \t \t \t \t \t      <h4 class="modal-title">Test Modal</h4> 
 
\t \t \t \t \t \t \t \t     </div> 
 
\t \t \t \t \t \t \t \t     <div class="modal-body"> 
 
\t \t \t \t \t \t \t \t     \t Hello World 
 
\t \t \t \t \t \t \t \t     </div> 
 
\t \t \t \t \t \t \t \t     <div class="modal-footer"> 
 
\t \t \t            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
 
\t \t \t            <button type="button" class="btn btn-primary">Save changes</button> 
 
\t \t \t           </div> 
 
\t \t \t \t \t \t \t \t    </h:form> 
 
\t \t \t \t \t \t \t \t   </div> 
 
\t \t \t \t \t \t \t \t  </div> 
 
\t \t \t \t \t \t \t \t </div>

HTH

+0

Vielen Dank @saria für Ihre Hilfe. – Nerimen

1

Ok, ich habe jsf nicht für immer gemacht, aber es dauerte einige Zeit, ein Beispiel jsf Projekt basierend auf Ihrem Code zu erstellen, ich habe es funktioniert dann erkannte ich die Lösung ist ziemlich trivial, nichts mit JSF überhaupt zu tun. Wenn Sie in einem HTML-Formular eine Schaltfläche haben und den Typ nicht angeben, wird sie standardmäßig übermittelt. Wenn Sie darauf klicken, wird das Formular gesendet. Da Sie das nicht möchten, möchten Sie nur, dass ein Modal auftaucht und nichts POST, Sie müssen nur den Typ angeben. Ersetzen Sie die Taste mit diesem und es sollte funktionieren:

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" type="button"> 
    Launch Demo Modal 
</button> 
Verwandte Themen