【问题标题】:How to render all Grid fields except one inputText?如何呈现除一个 inputText 之外的所有 Grid 字段?
【发布时间】:2013-04-02 07:57:26
【问题描述】:

我有一个使用 ajax 的搜索表单。在搜索字段searchKeyFieldIdkeyup 事件期间,我需要更新同一面板网格中的所有其他字段。

<h:panelGrid id="myGrid" columns="4" >

    <!-- When searchKeyFieldId change ... -->
    <!-- Need to render all the myGrid EXCEPT searchKeyFieldId -->
    <h:outputText value="search key"/>
    <h:inputText id="searchKeyFieldId"
        value="#{MyController.searchKeyField}"      
        valueChangeListener="#{MyController.licenseNumberChange}" >
        <a4j:ajax event="keyup" render="myGrid" />
    </h:inputText>

    <h:outputText value=""/>
    <h:outputText value=""/>

    <!-- Target render fields -->   
    <h:outputText value="text1"/>
    <h:inputText id="field1"
        value="#{MyController.field1}"/>

    <h:outputText value="text2"/>
    <h:inputText id="field2"
        value="#{MyController.field2}"/>

    <h:outputText value="text3"/>
    <h:inputText id="field3"
        value="#{MyController.field3}"/>
    .....   
</h:panelGrid>  

但是,当我使用render="myGrid" 时,搜索字段也会更新,因此会失去焦点。最终用户必须再次单击/聚焦输入字段才能继续输入。

所以,我只需要更新特定字段如下:

<a4j:ajax event="keyup" render="field1 field2 field3 field4 field5 ..." />

但是,我有很多字段,准确地说是 40 个,这个解决方案不是一个好习惯。

【问题讨论】:

    标签: ajax jsf rendering


    【解决方案1】:

    这个解决方案不是一个好的做法

    对不起,这太荒谬了。它完全可以完成您想要的工作,因此是正确的方法。克服它并把它们都写下来。如有必要,您可以将样板文件隐藏在 bean 属性后面。

    render="#{MyController.clientIdsToRender}"
    

    如有必要,您可以根据 JSF 组件树自动填充字符串,但为此编写代码将需要比硬编码视图中已定义的客户端 ID 所需的更多字符。

    在标准 JSF 和 RichFaces 中没有其他方法。然而,PrimeFaces 提供了PrimeFaces Selectors (PFS) 的替代方案。另请参阅此相关问题:How to exclude child component in ajax update of a parent component?

    另一种完全不同的选择是将面板网格分成两个面板网格,一个包含搜索输入,另一个包含要更新的字段。如有必要,您可以将它们与良好的 CSS 对齐。

    【讨论】:

    • 谢谢伙计。你非常乐于助人@BalusC
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-24
    • 2021-11-20
    • 2017-08-05
    • 2012-12-25
    • 2017-08-02
    相关资源
    最近更新 更多