简体   繁体   English

jsf ajax渲染不起作用

[英]jsf ajax rendered does not work

I would like to ask why partial rendering for primefaces does not work. 我想问为什么部分渲染的primefaces不起作用。 POST requests are keeping sent, but it does not rerender. POST请求保持发送,但不会重新发送。

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <p:messages />
        <h:form>
            <table style="width: 100%">
                <tr>
                    <td><p:outputLabel for="inp1" value="S1" /></td>
                    <td>
                        <p:inputText id="inp1" value="#{form.e.s1}">
                            <p:ajax process="inp1" update="msg1"
                                    event="keyup" />
                        </p:inputText>
                        <p:watermark for="inp1" value="Wpisz S1" />
                        <p:message for="inp1" id="msg1" />
                    </td>
                </tr>
                <tr>

                    <td>Toolbox</td>
                    <td>
                        <p:selectBooleanCheckbox id="inpToolbox" value="#{form.toolbox}">
                            <p:ajax process="inpToolbox" update="toolboxOptions" />
                        </p:selectBooleanCheckbox><br />
                        <p:panel id="toolboxOptions" rendered="#{form.toolbox}">
                            Name: <p:inputText value="#{form.toolboxDescription}" /><br />
                            Number: <p:inputText value="#{form.toolboxNr}" /><br />
                        </p:panel>
                    </td>

                </tr>
            </table>

            <p:commandButton action="#{form.save}" ajax="false"
                             value="Save" />

        </h:form>
    </h:body>
</html>

I have no idea, why it should not work. 我不知道,为什么它不应该工作。 I want every time changes the toolbox value to show the additional information form about toolbox 我希望每次更改工具箱值以显示有关工具箱的其他信息表单

When you would like to update some part of the view you have to specify an id of an element which is actually present in the DOM. 当您想要更新视图的某些部分时,您必须指定实际存在于DOM中的元素的id。 But the panel you are trying to update is not always present in the DOM, only in the case that form.toolbox evaluates to true. 但是,您尝试更新的面板并不总是出现在DOM中,只有在form.toolbox评估为true的情况下才会出现。 So when it is false it cant be updated and so it will not be added to the view. 因此,如果它是错误的,则无法更新,因此不会将其添加到视图中。 What you can do to solve this problem is, to wrap the panel inside another element and update that element. 解决此问题的方法是将面板包装在另一个元素中并更新该元素。 This will work because the wrapper-element is always present. 这将起作用,因为wrapper-element始终存在。

So try the following for the part of the panel: 因此,请尝试以下部分:

<h:panelGroup id="toolboxOptions">
    <p:panel id="toolboxOptionsPanel" rendered="#{form.toolbox}">
    ....
    </p:panel>
</h:panelGroup>

Have a look at to answer of the following question for further explanation: JSF + PrimeFaces: `update` attribute does not update component 看看以下问题的答案进一步解释: JSF + PrimeFaces:`update`属性不更新组件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM