如何在RichFaces 3.3.x中取消选项卡面板切换

发布于 2024-11-10 07:28:20 字数 1519 浏览 4 评论 0原文

我需要对表单进行一些基本验证。表单数据分为 5 个选项卡,用户应该能够从任何选项卡提交表单。到目前为止,一切都很好。如果用户没有填写字段,或者输入了无效数据,我想保留在当前选项卡上,显示错误消息并取消选项卡切换。

我尝试了我能找到的各种活动。有人知道这是否可能以及我如何实现它吗?如果可能的话,我更愿意将其保留在客户端的 JavaScript 中。

使用如下代码示例。

<rich:tabPanel selectedTab="Info" switchType="client" contentClass="hz-record-tabpanel" ontabchange="doTabChange();"  onbeforeitemchange="doTabChange();" onbeforetabchange="doTabChange();">
                <rich:tab name="Info" label="Tab Label" onlabelclick="doTabChange();">
                    <ui:include src="info.xhtml" />
                </rich:tab>
                <rich:tab name="Officers" label="Officers" onlabelclick="doTabChange();" ontableave="doTabChange();">
                    <ui:include src="officers.xhtml" />
                </rich:tab>
                <rich:tab name="CardServices" label="Card Services" onlabelclick="doTabChange();">
                    <ui:include src="cardservices.xhtml" />
                </rich:tab> 
                <rich:tab name="M2MLimits" label="M2M Limits" onlabelclick="doTabChange();">
                    <ui:include src="m2mlimits.xhtml" />
                </rich:tab> 
                <rich:tab name="AccountServices" label="Account Services" onlabelclick="doTabChange();">
                    <ui:include src="accountservices.xhtml" />
                </rich:tab>                 
            </rich:tabPanel>

有什么想法吗?

I need to do some basic validation on a form. The form data is broken up among 5 tabs, and the user should be able to submit the form from any tab. So far so good. If the user hasn't filled in a field, or has entered invalid data I want to stay on the current tab, display an error message and cancel the tab switch.

I have tried the various events that I can find. Does anybody have any idea if this is possible and how I might achieve it? I would prefer to keep it on the client side in javascript if possible.

Using a code sample such as below.

<rich:tabPanel selectedTab="Info" switchType="client" contentClass="hz-record-tabpanel" ontabchange="doTabChange();"  onbeforeitemchange="doTabChange();" onbeforetabchange="doTabChange();">
                <rich:tab name="Info" label="Tab Label" onlabelclick="doTabChange();">
                    <ui:include src="info.xhtml" />
                </rich:tab>
                <rich:tab name="Officers" label="Officers" onlabelclick="doTabChange();" ontableave="doTabChange();">
                    <ui:include src="officers.xhtml" />
                </rich:tab>
                <rich:tab name="CardServices" label="Card Services" onlabelclick="doTabChange();">
                    <ui:include src="cardservices.xhtml" />
                </rich:tab> 
                <rich:tab name="M2MLimits" label="M2M Limits" onlabelclick="doTabChange();">
                    <ui:include src="m2mlimits.xhtml" />
                </rich:tab> 
                <rich:tab name="AccountServices" label="Account Services" onlabelclick="doTabChange();">
                    <ui:include src="accountservices.xhtml" />
                </rich:tab>                 
            </rich:tabPanel>

Any Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

一梦等七年七年为一梦 2024-11-17 07:28:20

这是我在良好验证后用来关闭 rich:modalPanel 的按钮:

<a4j:commandButton id="btnModify" value="Modifier" actionListener="#{editCityActions.onButtonModifyClick}" data="#{facesContext.maximumSeverity.ordinal ge 2}" oncomplete="if(event.data == false) { #{rich:component('frmEditCity')}.hide(); }" render="tblCities" />

我认为您可以使用 a4j:ajax 或类似的东西应用事件!

This is the kind of button I use to close a rich:modalPanel after a good validation :

<a4j:commandButton id="btnModify" value="Modifier" actionListener="#{editCityActions.onButtonModifyClick}" data="#{facesContext.maximumSeverity.ordinal ge 2}" oncomplete="if(event.data == false) { #{rich:component('frmEditCity')}.hide(); }" render="tblCities" />

I think you can apply an event with a4j:ajax or something like that!

无畏 2024-11-17 07:28:20

我们最终迁移到 Richfaces 4 (4.2),并且我成功地使用了 itemchangebeforeitemchange

事件。

这些事件会触发两次(还没有弄清楚那一个),因此您不希望处理程序代码中出现任何过于密集的内容。

如果 beforeitemchange 返回 false(两次),则选项卡面板将不会切换。

我使用 itemchange 事件来触发任何额外的 JavaScript 来格式化数据,并将焦点放在该选项卡上表单中的第一个输入字段上。

We eventually moved to Richfaces 4 (4.2) and I am successfully using itemchange and beforeitemchange

events.

These events fire twice (haven't figured that one out yet) so you don't want anything too intensive in the handler code.

If beforeitemchange returns false (twice) then the tabpanel will not switch.

I am using the itemchange event to fire any extra javascript to format data, and place focus on the first input field in the form on that tab.

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