xpages 基于组合框值隐藏/显示字段 [英] xpages hiding/showing fields based on a combobox value

查看:21
本文介绍了xpages 基于组合框值隐藏/显示字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 和 10 个 包含许多字段组件.

I'm using a <xe:djTabContainer> with 10 <xe:djTabPane> containing numerous fields components.

有一个主要的组合框,它的值将决定显示或不显示哪些字段,从而实现文档结构.

There is a principal combobox whose value will determine which fields to be showed or not and in this way the document structure will be achieved.

如果我使用这种方法,那么对于我想要显示/隐藏的所有 >50 个字段,我将只使用组合框的 onChange 事件?

If I will use this approach, then for all my >50 fields which I want to show/hide, I will use only the onChange event of the combobox?

考虑到有 >50 个字段进入该类别

显示和隐藏它们 >,我应该使用另一种方法/方法吗?谢谢你的时间.

Considering the fact that there are >50 fields which enter in this category < showing&hiding them >, should I use another approach / method? Thanks for your time.

<xp:comboBox value="#{Contr.txt_tipcontractcv}" id="comboBox4">                                 <xp:selectItems id="selectItems1">                                      
     <xp:this.value><![CDATA[#{javascript:return ""}]]></xp:this.value>
</xp:selectItems>
<xp:selectItems id="selectItems2">
    <xp:this.value><![CDATA[#{javascript:@DbColumn(@DbName(),"SetupvwTipuriContracteC",1);}]]>           </xp:this.value>
</xp:selectItems>                   
<xp:eventHandler event="onchange" submit="false">                                       <xp:this.script><![CDATA[XSP.partialRefreshPost("#{id:FisaP}", {
});
]]></xp:this.script>                                    </xp:eventHandler>                          </xp:comboBox>

和面板:

<xp:panel id="FisaP">
        <xp:label id="label4"
            style="color:rgb(128,0,0);font-family:verdana;font-size:9pt;font-weight:bold">
            <xp:this.value><![CDATA[#{javascript:"Fisa contract "+ Contr.getItemValueString("txt_tipcontractcv")}]]></xp:this.value>
            <xp:this.rendered><![CDATA[#{javascript:
            Contr.getItemValueString("txt_tipcontractcv") != ""
         }]]></xp:this.rendered>

        </xp:label>

    </xp:panel>

推荐答案

我会扭转局面.让标签和字段询问组合框是否应该呈现它们.让组合框的 onchange 事件启动面板的部分刷新,其中包括您要显示/隐藏的所有字段.

I would turn it around. Let the labels and fields ask the combobox if they should be rendered or not. Let the combobox's onchange event initiate a partial refresh of a panel which includes all fields you want to show/hide.

如果您的 >50 个字段都在一个地方,您可以使用面板将它们框起来并在那里设置渲染属性.

If your >50 fields are all on one place you can frame them with a panel and set the rendered property there.

如果您的组合框绑定到 viewScope 变量,则字段/标签的呈现属性将是

If your combobox is bound to a viewScope variable the rendered property of fields/labels would be

rendered="#{javascript:viewScope.tipcontractcv1 == 'Vanzare-Cumparare'}"

或者如果它绑定到文档字段,则

or if it is bound to a document field then

rendered="#{javascript:document1.getItemValueString('txt_tipcontractcv1') === 'Vanzare-Cumparare'}"

更新:

根据您在回答中的代码https://stackoverflow.com/a/25636661/2065611,请执行以下操作使其与 Dojo Tab Container 一起工作的步骤:

Based on your code in your answer https://stackoverflow.com/a/25636661/2065611 take the following steps so get it to work with the Dojo Tab Container:

1.

将标签和字段放在具有 id 但没有呈现属性的面板中

Put the labels and fields in panels which do have an id but don't have a rendered attribute

<xp:panel id="panel1">
    <xp:label value="Persoane spre informare" ... id="label2">   
         <xp:this.rendered><![CDATA[#{javascript:
            Contr.getItemValueString("txt_tipcontractcv1") == "Vanzare-Cumparare"
         }]]></xp:this.rendered>
    </xp:label>
    ... other label and fields ...
</xp:panel>

您也可以创建其他面板panel2"、panel3"…….它们可以放置在不同的 djTabPanes 中.

You can create other panels "panel2", "panel3", ... too. They can be placed in different djTabPanes.

2.

更改组合框的 onchange 事件并执行客户端代码以刷新面板

Change the onchange event of your combobox and execute client side code to refresh the panels

            <xp:eventHandler
                event="onchange"
                submit="false">
                <xp:this.script><![CDATA[
                    XSP.partialRefreshPost("#{id:panel1}", {
                        onComplete: function() {
                            XSP.partialRefreshPost("#{id:panel2}");
                        }
                    });
                ]]></xp:this.script>
            </xp:eventHandler>

3.

如果将具有相同渲染属性的标签和字段放在一个附加面板中,则可以优化代码

You can optimize your code if you put labels and fields with the same rendered attribute together into an additional panel

<xp:panel id="panel1">
    <xp:panel id="panelRendered1"
         <xp:this.rendered><![CDATA[#{javascript:
            Contr.getItemValueString("txt_tipcontractcv1") == "Vanzare-Cumparare"
         }]]></xp:this.rendered>
        <xp:label value="Persoane spre informare" ... id="label2" />   
        ... other label and fields ...
    </xp:panel>
</xp:panel>

这篇关于xpages 基于组合框值隐藏/显示字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆