使用 richfaces tabPanel 防止选项卡开关上的表单提交

发布于 2024-12-03 01:37:50 字数 1925 浏览 2 评论 0原文

有一个选项卡面板,类似于:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

厌味 2024-12-10 01:37:50

默认情况下,在选项卡之间切换时会提交父 tabPanel。您可以使用 tabPanel 的 switchType 属性将这种行为更改为 ajax 或 client。我可以想到两种方法来防止表单在从一个选项卡更改为另一个选项卡时提交:

  1. 将 switchType 属性更改为客户端

  2. 为每个选项卡包含一个表单< /p>

我看不到表单的定义位置,但我猜测整个 rich:tabPanel 都在表单内。我发现您的description.xhtml 页面中没有定义表单。您可以尝试删除现有的表单,然后为每个选项卡添加一个表单,即在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">    

<a4j:form>
<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>
</a4j:form>
</ui:composition>

我还将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:

  1. Change the switchType attribute to client

  2. 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:

<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">    

<a4j:form>
<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>
</a4j:form>
</ui:composition>

I would also set the switchType attribute of the tabPanel to ajax so that only the content of tabPanel is refreshed.

若无相欠,怎会相见 2024-12-10 01:37:50

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文