【问题标题】:Combo Box "showReadonlyAsDisabled" Property Not Working组合框“showReadonlyAsDisabled”属性不起作用
【发布时间】:2016-04-13 19:07:06
【问题描述】:

我的 XPage 上有一个组合框,其中 showReadonlyAsDisabled 标记为 true:

<xp:comboBox
    id="ComboTest"
    defaultValue="One"
    showReadonlyAsDisabled="true"
    readonly="true">
    <xp:selectItem
        itemLabel="One"
        itemValue="One">
    </xp:selectItem>
</xp:comboBox>

但是,组合框仍显示为只读(文本)而不是禁用控件。这是一个错误吗? showReadonlyAsDisabled 属性似乎适用于其他控件(输入、收音机等)。我使用的是 Designer 9.0.1FP4,而 Domino 服务器在 9.0.1FP5 上。

编辑(显示带有数据绑定的组合框):

自定义控件中的组合框

<xp:comboBox
    id="Address"
    value="#{Location.AddressType}"
    defaultValue="Street Address"
    showReadonlyAsDisabled="true"
    readonly="true">
    <xp:selectItems>
        <xp:this.value><![CDATA[#{javascript:keywords.getSelectItem("Address Type", true);}]]></xp:this.value>
    </xp:selectItems>
</xp:comboBox>

父 XPage 上的数据绑定

    <xp:dominoDocument
        var="Location"
        formName="Location"
        action="editDocument"
        documentId="#{javascript:param.location}">
    </xp:dominoDocument>

【问题讨论】:

  • 您的示例没有与其value 属性的数据绑定,因此它似乎是可编辑的。尝试将其绑定到文档的项目/字段并将该文档的 action 设置为打开文档(而不是创建或编辑),您应该会看到它的行为符合预期。
  • 当我对值进行数据绑定时,它仍然无法按预期工作。
  • 这是我经常使用的功能。您能否扩展您的示例以提供完整的绑定图片?
  • 当然。我编辑了我的问题。此外,其他控件似乎不需要数据绑定才能使 showReadonlyAsDisabled 工作,这很奇怪。我还尝试将文档的操作设置为打开,这也不起作用。
  • 如果您在XPages Slack chat 中,则在 2 月 23 日的初学者聊天中对此进行了一些讨论。 Paul Withers 推荐了一个 Dojo Radio Button,因为这显然是一个已知的错误。

标签: xpages


【解决方案1】:

似乎是在阅读模式下呈现为 html 表格的各种选择控件的问题(在我看来,这比这个“在阅读模式下显示禁用”错误更令人讨厌,因为它使样式变得不必要地复杂) .但是,只有当控件绑定到文档数据源时才会发生这种情况。

因此,您可以尝试在页面上创建第二个组合框并将其绑定到 viewScope 变量,然后确保在页面加载时从 Notes 字段复制正确的值,然后确保只有一个 tyour 实例控件在读取/编辑模式下可见:

对于名为Location 的数据源和注释字段AddressType,这将在beforePageLoad 中:

if(!doc1.isNewNote()){
    viewScope.comboField=Location.getItemValueString("AddressType");
}

这将是您的原始/可编辑组合框控件的标记:

<xp:comboBox id="comboBox1" value="#{Location.AddressType}" rendered="#{javascript:doc1.isEditable()}" defaultValue="Street Address">
    <xp:selectItems>
        <xp:this.value><![CDATA[#{javascript:keywords.getSelectItem("Address Type", true);}]]></xp:this.value>
    </xp:selectItems>
</xp:comboBox>

这将是您的附加/禁用组合框控件的标记:

<xp:comboBox id="comboBox2" value="#{viewScope.AddressType}" disabled="true" rendered="#{javascript:!doc1.isEditable()}">
    <xp:selectItems>
        <xp:this.value><![CDATA[#{javascript:keywords.getSelectItem("Address Type", true);}]]></xp:this.value>
    </xp:selectItems>
</xp:comboBox>

【讨论】:

    【解决方案2】:

    您可以将以下 XML 部分添加到应用程序的 faces-config.xml

    这样,ComboBox 的渲染器将设置为默认渲染器,而不是只读渲染器。然后,您的 ComboBox 应如您所愿。

    <renderer>
        <component-family>javax.faces.SelectOne</component-family>
        <renderer-type>javax.faces.Menu.ReadOnly</renderer-type>
        <renderer-class>com.ibm.xsp.renderkit.html_basic.MenuRenderer</renderer-class>
    </renderer>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-09
      相关资源
      最近更新 更多