简体   繁体   中英

jsf ajax rendered does not work

I would like to ask why partial rendering for primefaces does not work. POST requests are keeping sent, but it does not rerender.

<?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. 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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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