我正在学习jQuery.我想在我的jsf 2.0应用程序中使用jQuery.就像我有html文件,我在这里使用jQuery
<head>
<title>The Devil's Dictionary</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="css/06.css" type="text/css" />
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="js/06.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
我只是从jQuery官方网站下载了jquery-1.7.1.js文件,将其包含在我的目录中,然后开始使用jQuery.
我的06.js文件conatin代码是这样的
$(document).ready(function() {
$('#letter-a a').click(function(){
/**
* The .load() method does all our heavy lifting for us! We specify the target location for
* the HTML snippet by using a normal jQuery selector, and then pass the URL of the file to
* be loaded as a parameter to the method. Now, when the first link …Run Code Online (Sandbox Code Playgroud) 我对这个事实背后的想法有一个疑问,即只有UIForm属性prependId.为什么NamingContainer界面中没有指定属性?你现在可能会说这是因为后向兼容性但我宁愿打破兼容性并让实现该接口的用户也实现prependId的方法.
从我对UIForm组件中的prependId的观点来看,主要的问题是它会破坏findComponent()
我希望如果我使用prependId,那么NamingContainer行为会改变,不仅与渲染有关,而且在想要在组件树中搜索组件时也是如此.
这是一个简单的例子:
<h:form id="test" prependId="false">
<h:panelGroup id="group"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)
现在,当我想获得panelGroup组件时,我希望将字符串传递"group"给方法findComponent(),但它不会找到任何东西,我必须使用"test:group".
具体问题是,当使用ajax时prependId="false".ajax标记在属性更新和处理中期望值关注命名容器.有点奇怪的是,当我使用它时prependId="false",我必须指定完整的id或路径,但没关系.
<h:form id="test" prependId="false">
<h:panelGroup id="group"/>
</h:form>
<h:form id="test1" prependId="false">
<h:commandButton value="go">
<f:ajax render="test:group"/>
</h:commandButton>
</h:form>
Run Code Online (Sandbox Code Playgroud)
那么这段代码将呈现没有问题,但它不会更新panelGroup,因为它无法找到它.在PartialViewContext将只包含ID "group"为renderIds的元素.我不知道这是否是预期的,可能是但我不知道代码.现在我们到了方法findComponent()无法找到组件的位置,因为作为参数传递的表达式是"group"方法期望"test:group"找到组件的位置.
一种解决方案是编写自己的解决方案,findComponent()这是我选择处理此问题的方式.在这个方法中,我处理一个组件,它是一个NamingContainer并且具有属性prependId像正常一样设置为false UIComponent.我将不得不为每个UIComponent提供prependId属性的事情做到这一点,这很糟糕.反射将有助于绕过类型的静态定义,但它仍然不是一个非常干净的解决方案.
另一种方法是在NamingContainer接口中引入prependId属性,并改变行为,findComponent()如上所述.
最后提出的解决方案是改变ajax标记的行为以传递整个id,但这只能解决ajax问题而不是findComponent()实现背后的程序问题.
你怎么看待这个以及它为什么会这样实现呢?我不能成为第一个遇到这个问题的人,但是我找不到相关的主题?!