【发布时间】:2012-03-17 13:24:06
【问题描述】:
我今天花了几个小时试图解决这个问题。我(以某种方式)找到了解决方案,但没有按预期工作。
我是 jQuery 世界的新手,所以我会尽量说清楚。
在我的示例中,我有一个 xhtml 页面,其中包含另一个 xhtml 页面,其中
<ui:include> 标签。包含的页面最初并未呈现(由于包含所有图片)。当它通过<p:commandLink> 呈现时,页面会正确显示所有图片。每张图片都是<h:ouputLink>,它显示了一个fancyBox,但行为有点错误。
当最终呈现包含的页面并且我第一次单击 <h:ouputLink> 时,fancyBox 没有显示,但随后的单击打开了 fancyBox 并且它正常工作。我想不通为什么。
我正在使用 jsf2、PrimeFaces 3.02、FancyBox 1.7。
我的代码:
main.xhtml
<--Main xhtml-->
<h:form id="myForm">
<h:panelGrid id="panelGridMain"
rendered="#{myBean.actualPage eq 'main'}">
<p:commandLink
id="showIncludedPage"
actionListener="#{myBean.setPage('test')}"
update="@form">
<h:graphicImage value="/Image/TbnPic1.jpg"/>
</p:commandLink>
</h:panelGrid>
<h:panelGroup id="myTestPanel" rendered="#{myBean.actualPage eq 'test'}">
<ui:include src="test.xhtml" />
</h:panelGroup>
</h:form>
Test.xhtml
<ui:component xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:outputLink value="/Images/Pic1.jpg" id="example1" title="" >
<h:graphicImage alt="example1" value="/Images/TbnPic1.jpg" />
</h:outputLink>
</ui:component>
最后是我的 jQuery 代码
$(document).ready(
function() {
$("#myForm\\:example1").live("click",function(e) {
alert(e.isDefaultPrevented());
if (! e.isDefaultPrevented()){
e.preventDefault();
}
$(this).fancybox();
});
});
一些声明:
*我认为.on() 是推荐的,但它对我不起作用,我需要做更多的测试。
*我必须将 e.preventDefault() 添加到我的 .js 中,因为当我单击链接以弹出 fancyBox 时,链接会重定向到包含照片的 url(例如:localhost:8080/.. /Images/Pic1.jpg)
*如果页面最初被渲染,fancyBox 工作正常。
感谢您的帮助,希望您能理解问题=)
【问题讨论】:
标签: javascript jquery jsf-2 fancybox