使用 richfaces tabPanel 防止选项卡开关上的表单提交
有一个选项卡面板,类似于:
<rich:tabPanel >
<rich:tab header="Description" >
<ui:include src="./tests/description.xhtml"/>
</rich:tab>
<rich:tab header="Something else">
something else
</rich:tab>
</rich:tabPanel>
在description.xhtml中包含一些字段:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:advanced="http://java.sun.com/jsf/composite/advanced">
<h:panelGroup id="description">
// ...
<h:outputLabel value="Name"/>
<h:inputText id="name"
value="#{testTree.selected.name.text}"
rendered="#{description.editing}"/>
// ...
<advanced:button text="Reset" //Just a little upgraded a4j:commandButton
icon="images/clear.png"
action="#{description.resetEditing()}"
execute="@this"
render="description"
rendered="#{description.editing}"/>
<advanced:button text="Save"
icon="images/save2.png"
action="#{description.commitEditing()}"
execute="description" // #name and a few more fields
render="description"
rendered="#{description.editing}"/>
</h:panelGroup>
</ui:composition>
切换到第二个选项卡,我提交了“描述”表单,但这不好。我想重置所有字段。
如何使用 RichFaces 4 实现这一目标?
Got a tab panel something like:
<rich:tabPanel >
<rich:tab header="Description" >
<ui:include src="./tests/description.xhtml"/>
</rich:tab>
<rich:tab header="Something else">
something else
</rich:tab>
</rich:tabPanel>
With a few fields in description.xhtml:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:advanced="http://java.sun.com/jsf/composite/advanced">
<h:panelGroup id="description">
// ...
<h:outputLabel value="Name"/>
<h:inputText id="name"
value="#{testTree.selected.name.text}"
rendered="#{description.editing}"/>
// ...
<advanced:button text="Reset" //Just a little upgraded a4j:commandButton
icon="images/clear.png"
action="#{description.resetEditing()}"
execute="@this"
render="description"
rendered="#{description.editing}"/>
<advanced:button text="Save"
icon="images/save2.png"
action="#{description.commitEditing()}"
execute="description" // #name and a few more fields
render="description"
rendered="#{description.editing}"/>
</h:panelGroup>
</ui:composition>
Switching to the second tab I got my "description" form submitted and this is not good. I want to reset all fields instead.
How can I achieve this with RichFaces 4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,在选项卡之间切换时会提交父 tabPanel。您可以使用 tabPanel 的 switchType 属性将这种行为更改为 ajax 或 client。我可以想到两种方法来防止表单在从一个选项卡更改为另一个选项卡时提交:
将 switchType 属性更改为客户端
为每个选项卡包含一个表单< /p>
我看不到表单的定义位置,但我猜测整个 rich:tabPanel 都在表单内。我发现您的description.xhtml 页面中没有定义表单。您可以尝试删除现有的表单,然后为每个选项卡添加一个表单,即在description.xhtml 中:
我还将tabPanel 的switchType 属性设置为ajax,以便仅刷新tabPanel 的内容。
By default when switching between tabs the parent tabPanel is submitted. You can change this behaviour using the switchType attribute of the tabPanel to either ajax or client. I can think of two ways to prevent your form from being submitted on changing from one tab to another:
Change the switchType attribute to client
Include a form for each tab
I can't see where your form is defined but I am guessing the whole rich:tabPanel is inside the form. I see there is no form defined in your description.xhtml page. You can try removing the form that you have and then add a form for each tab, i.e. in description.xhtml:
I would also set the switchType attribute of the tabPanel to ajax so that only the content of tabPanel is refreshed.
1) 将 switchType 属性更改为 client
2)为每个选项卡包含一个表格,
我花了 6 个小时谷歌搜索,最后在这里结束了对另一个选项卡的搜索,
更改此属性值救了我的命。
1) Change the switchType attribute to client
2) Include a form for each tab
I have spent 6 hours googling , finally ended here searching for another,
Changing this attribute value saved my day.