问题描述
我有,我想显示/隐藏组件,用户点击后,的commandButton
。
I have a component that I want to show/hide after user hits a commandButton
.
是这样的:
<h:commandButton id="showButton" value="#{bean.wasPressed ? 'Hide' : 'Show'}">
<f:ajax listener="#{bean.toggle()}" render="explanation showButton" />
</h:commandButton>
和
<h:panelGroup id="explanation" rendered="#{bean.wasPressed}">
<h:outputText value="something" />
</h:panelGroup>
在 bean.toggle()
只是设置是pressed
属性为true或false适当。我使用&LT; H:形式prependId =假&GT;
The bean.toggle()
simply sets the wasPressed
property to true or false appropriately. I am using <h:form prependId="false">
.
问题是我的按钮渲染
属性的值。它明确地报名两种:解释
和 showButton
。
The problem is the value of the render
attribute of my button. It explicitly enlists both: explanation
and showButton
.
只要 showButton
总是present(它只是改变了它的标签),在解释
为present只有当是pressed
属性为true。否则,它说:
As long as the showButton
is always present (it only changes its label), the explanation
is present only if the wasPressed
property is true. Otherwise it says:
malformedXML:在更新:explanaition找不到
我该如何解决这个问题呢?
How can I solve this problem?
我想不会恢复到躲在源$ C $ c中的元素,所以我想不使用任何jQuery的切换( - )或任何方式使用隐藏的元素风格= 显示:无
或任何这方面的东西
I would like not to revert to hiding the element in the source code, so I would like not to use any jQuery toggle(-) or any way of hiding the element using style="display: none"
or any of this stuff.
它甚至可以实现在JSF 2.1?
Is it even achievable in JSF 2.1?
推荐答案
您不能更新它们不会呈现,呈现=伪元素是一个JSF的方式来删除从DOM树中的元素,
You cannot update elements which are not rendered , rendered=false "is a JSF way to" to remove elements from the DOM Tree ,
它不喜欢的CSS显示:无或可见性:隐藏&LT; - 这两人将保留的元素在DOM树,但隐藏的,而JSF呈现= FALSE甚至不会渲染(保持)在DOM树中的元素(你甚至不会看到它的页面的查看源文件)
its not like css display:none or visibility:hidden <- this two will keep the elements in the DOM tree but hidden , while the JSF rendered=false wont even render (keep) the element in the DOM tree (you wont even see it in the "view source" of the page)
所以,你如果你需要包装的panelGroup中与其他`panelGroup中'和更新包装的ID
So in you case you need to wrap the panelGroup with another `panelGroup' and update the id of the wrapper
<h:commandButton id="showButton" value="#{bean.wasPressed ? 'Hide' : 'Show'}">
<f:ajax listener="#{bean.toggle()}" render="explanationWrapper showButton" />
</h:commandButton>
<h:panelGroup id="explanationWrapper">
<h:panelGroup id="explanation" rendered="#{bean.wasPressed}">
<h:outputText value="something" />
</h:panelGroup>
</h:panelGroup>
还看类似的问题
also look at similar question
这篇关于AJAX渲染属性不与渲染工作=&QUOT;假&QUOT;零件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!