在 jsf
应用程序中渲染某些组件时,我遇到了问题。
问题是当我在页面上使用 jQuery
时,例如隐藏按钮。当页面重新渲染时,按钮返回到其原本应隐藏的形式。
有人在这个问题上有专业知识,能够帮助我找到合适的解决方案,或者这里有一些原则或技术被我盲目地误解了?
谢谢。 :)
最佳答案
The problem is when I use jQuery on my page for example hiding the button. When the page reRenders the button come back to its original form which is supposed to be hidden.
不要使用 jQuery 来操作 DOM,而是使用 JSF Ajax 来操作 DOM。
例如
<h:form>
<h:selectBooleanCheckbox value="#{bean.checked}">
<f:ajax render="buttons" />
</h:selectBooleanCheckbox>
<h:panelGroup id="buttons">
<h:commandButton value="Submit" rendered="#{bean.checked}" />
</h:panelGroup>
</h:form>
另请参阅:
关于jquery - 重新渲染 richfaces/jsf 组件时如何维护 jQuery/javasscript 操作的 DOM 状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8922308/