我喜欢复合组件中的原理,但这和引导程序模式不能一起使用。
什么是管理多个“定制复合组件”对话框并在JSF-Table中像此示例一样使用的最佳实践。将“受管Bean值”从选定的行传递到对话框。
仅当我全部写在一个页面文件中时,这才对我有用。请参阅最后一个。
bootstrapModal.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:h="http://xmlns.jcp.org/jsf/html"
xmlns:cc="http://xmlns.jcp.org/jsf/composite">
<cc:interface>
<cc:attribute name="title" />
<cc:attribute name="linkNameLable" />
<cc:attribute name="linkNameValue" />
<cc:attribute name="urlNameLable" />
<cc:attribute name="urlNameValue" />
<cc:attribute name="saveButtonText" />
<cc:attribute name="saveButtonAction"
method-signature="java.lang.String action()" />
</cc:interface>
<cc:implementation>
<div id="#{cc.clientId}" class="modal fade myModal" tabindex="-1" role="dialog" aria-labelledby="myModal" aria-hidden="true" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<h:form>
<h:outputLabel value="#{cc.attrs.linkNameLable}" />
<h:inputText value="#{cc.attrs.linkNameValue}" />
<h:outputLabel value="#{cc.attrs.urlNameLable}" />
<h:inputText value="#{cc.attrs.urlNameValue}" />
<h:commandButton value="#{cc.attrs.saveButtonText}" action="#{cc.attrs.saveButtonAction}" />
</h:form>
</div>
</div>
</div>
</div>
</cc:implementation>
</html>
包装div不起作用。
<div id=#{cc.clientId}>...</div>
我也尝试将ID传递到表单中。
<h:form id=#{cc.clientId}
view.xhtml与复合组件不起作用。f:ajax无法从复合组件渲染ID
...
<script>
function showModal() {
$('#myModal').modal('show');
}
</script>
...
<h:dataTable id="myTable" value="#{linkController.linkList}" var="o">
...
<h:column>
<f:facet name="header">Actions</f:facet>
<h:form>
<h:commandLink value="edit" onclick="showModal()" action="#{linkController.setLinkFromParam}">
<f:ajax render="myModal value1 value2" />
<f:param name="name" value="#{o.name}" />
<f:param name="url" value="#{o.url}" />
</h:commandLink>
</h:form>
</h:column>
</h:dataTable>
<!-- 1.outside the Table rendering works fine -->
<h:outputText id="value1" value="#{linkController.name}" /><br />
<h:outputText id="value2" value="#{linkController.url}" />
<!-- 2.The render for this id does not work -->
<mahi:bootstrapModal title="Edit Link"
id="myModal"
linkNameLable="Link Name:"
linkNameValue="#{linkController.name}"
urlNameLable="URL:"
urlNameValue="#{linkController.url}"
saveButtonText="Save"
saveButtonAction="#{linkController.updateLink(link)}" />
带有Composite Component内容的view.xhtml可以正常工作。因为我可以直接使用id =“ myModalForm”呈现h:form。
...
<script>
function showModal() {
$('#myModal').modal('show');
}
</script>
...
<h:dataTable id="myTable" value="#{linkController.linkList}" var="o">
...
<h:column>
<f:facet name="header">Actions</f:facet>
<h:form>
<h:commandLink value="edit" onclick="showModal()" action="#{linkController.setLinkFromParam}">
<f:ajax render="myModalForm" />
<f:param name="name" value="#{o.name}" />
<f:param name="url" value="#{o.url}" />
</h:commandLink>
</h:form>
</h:column>
</h:dataTable>
<!-- The Content from the Custom Composite Component works -->
<div id="myModal" class="modal fade myModal" tabindex="-1" role="dialog" aria-labelledby="myLinkModal" aria-hidden="true" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<h:form id="myModalForm">
<h:outputLabel value="Name:" />
<h:inputText value="#{linkController.name}" />
<h:outputLabel value="URL:" />
<h:inputText value="#{linkController.url}" />
<h:commandButton value="Save" action="#{linkController.saveLink(link)}" />
</h:form>
</div>
</div>
</div>
</div>
简单的解决方案:
将类添加到您的模态中以进行调用,然后将您的模态作为类而不是像id那样调用:
模态:>
<div id="#{cc.clientId}" class="modal fade myModal"
脚本:>
<script>
function showModal() {
$('.myModal').modal('show');
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句