【问题标题】:How to submit form, from p:selectBooleanCheckbox change event如何提交表单,来自 p:selectBooleanCheckbox 更改事件
【发布时间】:2013-12-02 17:51:19
【问题描述】:

我正在使用 primefaces 并处理复杂的表单。我需要隐藏表单的一部分,具体取决于复选框的值

    <p:selectBooleanButton id="input1" .... />
<p:inputText id="input2" />


<!-- the boolean checkbox -->
<p:selectBooleanCheckbox id="checkBox1" value="#{bbean.someBoolValue}" >
    <p:ajax event="change" update=":#{p:component('someParentcComponentsId')}" />
</p:selectBooleanCheckbox>

<!-- some input fields here. These will be rendered depending checkBox1 value -->
<p:panel rendered="#{bbean.someBoolValue}" id="hiddingPanel">   
    <h:panelGrid columns="2" >

        <p:inputText id="input3" />
    </h:panelGrid>
</p:panel>

到目前为止,我已经完成了这项工作,所以当点击 checkBox1 时,hiddingPanel 会显示或隐藏。但有一个问题:该表单中每个输入的值(例如 input1input2 )都会丢失,因为“更改”ajax 事件没有提交它们的值。

如何确保在更新表单之前提交所有输入值?

【问题讨论】:

    标签: ajax jsf-2 primefaces


    【解决方案1】:

    请确保您更新真正需要更新的部分。

    <p:selectBooleanCheckbox id="checkBox1" value="#{bbean.someBoolValue}" >
        <p:ajax event="change" update="hiddingPanel" />
    </p:selectBooleanCheckbox>
    
    <!-- some input fields here. These will be rendered depending checkBox1 value -->
    <p:panel id="hiddingPanel">   
        <h:panelGrid columns="2" rendered="#{bbean.someBoolValue}">
    
            <p:inputText id="input3" />
        </h:panelGrid>
    </p:panel>
    

    请注意,我将 rendered 移至其直系子级,原因如下:Why do I need to nest a component with rendered="#{some}" in another component when I want to ajax-update it?

    【讨论】:

    • 谢谢 BalusC。为您解答。所以没有办法(部分)提交表格吗?如果是这种情况,那么我确实应该更新表单的一部分,以避免丢失未提交的更改。
    • 呃,我刚刚回答了如何实现这一点?还是您的意思是部分处理表格?如果是这样,您可以使用process 属性来控制它,但如果&lt;p:ajax&gt; 已经默认为@this
    • 我真正想要的是提交整个表单。我尝试了 'process="@form"',一切似乎都正常。我认为这正是我所需要的。再次感谢
    • 对您的解决方案印象深刻.....我已经浪费了 4 个小时来解决问题。谢谢@BalusC
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-08
    相关资源
    最近更新 更多