【问题标题】:Show bootstrap modal when a list in managed bean is not empty当托管 bean 中的列表不为空时显示引导模式
【发布时间】:2016-07-11 17:03:33
【问题描述】:

我正在使用引导模式来显示选定的数据列表。当托管 bean 中的列表不为空时,如何显示模式。

我的模态是

                 <div id="modalPanel-1" data-backdrop="static" class="modal hide fade in">
                                <div class="modal-header"><a data-dismiss="modal" class="close" id="closeModal" onclick="reconstruct()">×</a>
                                    <h3>Selected Trips</h3></div>
                                <div class="modal-body" style="width: 100%;">
                                    <p:panel style="border: medium none;" id="modalPanel-1-panel">
                                        <h:form id="modalForm">
                                            <h:selectOneMenu style="width:25%;"
                                                             value="#{userAction.assignVehicleSelectedVehicleID}">
                                                <f:selectItem itemLabel="Select Vehicle"></f:selectItem>
                                                <f:selectItems value="#{userAction.allVehicleList}"></f:selectItems>
                                                <p:ajax listener="#{userAction.assignVehicleChangeHandler}"
                                                        process="@this" update="@form"/>
                                            </h:selectOneMenu>
                                            <h:selectOneMenu id="driver" style="width:25%; margin-left: 10px;"
                                                             value="#{userAction.assignVehicleSelectedDriverID}">
                                                <f:selectItem itemLabel="Select Driver"></f:selectItem>
                                                <f:selectItems value="#{userAction.drivername}"/>
                                            </h:selectOneMenu>
                                            <h:commandButton
                                                    styleClass="btn btn-success" value="New Ride"
                                                    style="margin-left: 20px; margin-top: -10px;">
                                                <p:ajax listener="#{userAction.linkVehicleForAssignVehicle}"
                                                        process="@form" update="@form, :treeTableForm" oncomplete="clearModalErr();"></p:ajax>
                                            </h:commandButton>                                               
                                            <div>
                                                <ul></ul>
                                            </div>
                                            <p:dataTable value="#{userAction.selectedMatchedTripDTOs}" var="trip"
                                                         rendered="true" expandedRow="true">
                                                <p:column headerText="Group ID">
                                                    <h:outputText value="#{trip.groupId}"></h:outputText>
                                                </p:column>
                                                <p:column headerText="Route">
                                                    <h:outputText value="#{trip.route}"></h:outputText>
                                                </p:column>
                                                <p:column headerText="Requester">
                                                    <h:outputText value="#{trip.userName}"></h:outputText>
                                                </p:column>
                                                <p:column headerText="Count">
                                                    <h:outputText value="#{trip.count}"></h:outputText>
                                                </p:column>
                                                <p:column headerText="Ride ID">
                                                    <h:outputText value="#{trip.rideId}"></h:outputText>
                                                </p:column>
                                                <p:column>
                                                    <f:facet name="header">Action</f:facet>
                                                    <h:commandLink rendered="true" disabled="false">
                                                        <i class="fa fa-trash" title="Delete"></i>
                                                        <p:ajax listener="#{userAction.removeTripFromSelectedList(trip)}"
                                                                update=":modalForm"/>
                                                    </h:commandLink>
                                                </p:column>
                                                <p:rowExpansion>
                                                    <ul><h:outputText value="#{trip.startDate}"
                                                                      style="color: darkblue; font-size: 16px; padding-left: 400px;"/>
                                                    </ul>                                                    
                                                    <pm:content rendered="#{not empty trip.custom}">
                                                        <ul style="width: 100%;"><h:outputText value="Notes"
                                                                                               style="font-size: 14px"
                                                                                               rendered="#{not empty trip.custom}"/>&nbsp;<h:outputText
                                                                rendered="#{not empty trip.custom}"
                                                                value="#{trip.custom}"
                                                                style="color: #999999; font-size: 14px; "/></ul>
                                                    </pm:content>
                                                </p:rowExpansion>
                                            </p:dataTable>
                                        </h:form>
                                    </p:panel>
                                </div>
                            </div>

我可以将模态框包含在这样的东西中吗?

<pm:content rendered="#{not empty trip.customList}"> </pm:content>

或者当某些东西被添加到托管 bean 的列表中时,我可以触发模式吗?

请帮帮我。

【问题讨论】:

  • 你使用 if 子句,还是 jsp 没有那个?
  • 我可以触发模态显示在 IF 子句中吗?
  • 是的,你可以跳起来
  • 我试过了,还是不行,请帮帮我。
  • 这个问题如何直接与 PrimeFaces 相关(我“使用”PrimeFaces 不是正确答案 ;-))

标签: jquery ajax bootstrap-modal


【解决方案1】:

如果你想在 js 中隐藏一个模式,你可以使用 bootstrap 的隐藏语法

if (data.length > 0) {
   $('#modalPanel-1').modal('hide');
}

【讨论】:

  • 模态显示正常。但我担心时机。如前所述,使用 IF 子句显示它。
  • 你用jquery给modal添加动态内容?
  • 是的,我会添加到列表中。它将使用 Poll 在数据表中刷新。
  • 我在这个丑陋的jsp页面中没有看到任何js
  • 这里没有粘贴。
猜你喜欢
  • 2011-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-27
  • 1970-01-01
  • 2021-07-15
相关资源
最近更新 更多