麻烦更新< p:outputpanel>

发布于 2025-02-13 06:12:38 字数 2480 浏览 1 评论 0原文

好的,我的问题是我无法从Ajax更新组件(CURSO),我真的不知道为什么。

这是我的代码:

Rol
                                    <h:selectManyCheckbox value="#{usuarioSession.roles}" id="admin" disabled="#{checkView.validarAdm}">
                                        <f:selectItem itemValue="1" itemLabel="Administrador"></f:selectItem>                       
                                        <p:ajax listener="#{checkView.checkBoxAdmin()}" update="est"></p:ajax>
                                    </h:selectManyCheckbox>

                                    <h:selectManyCheckbox value="#{usuarioSession.roles}" id="doce" disabled="#{checkView.validarDoc}">
                                        <f:selectItem itemValue="2" itemLabel="Docente"></f:selectItem>                          
                                        <p:ajax listener="#{checkView.checkBoxDoc()}" update="est, cursos"></p:ajax>
                                    </h:selectManyCheckbox>

                                    <h:selectManyCheckbox value="#{usuarioSession.roles}" id="est" disabled="#{checkView.validarEst}">
                                        <f:selectItem itemValue="3" itemLabel="Estudiante"></f:selectItem>
                                        <p:ajax listener="#{checkView.checkBoxEst()}" update="doce, admin"></p:ajax>
                                    </h:selectManyCheckbox>

                                </div>
                                
                                <p:outputPanel rendered="#{checkView.check2 == true}" id="cursos" >
                                    <div class="mb-3">
                                        <h:outputLabel class="form-label">Curso</h:outputLabel>
                                        <h:selectManyCheckbox value="#{usuarioSession.cursos}">
                                            <c:forEach items="#{crearCursoView.listarCurso()}" var="lc">
                                                <f:selectItem itemValue="#{lc}" itemLabel="#{lc.nombre}"></f:selectItem>
                                            </c:forEach>
                                        </h:selectManyCheckbox>
                                    </div>
                                </p:outputPanel>

Ok, my problem is I can't update a component (cursos) from ajax, I do not really know why.

Here's my code:

Rol

                                    <h:selectManyCheckbox value="#{usuarioSession.roles}" id="admin" disabled="#{checkView.validarAdm}">
                                        <f:selectItem itemValue="1" itemLabel="Administrador"></f:selectItem>                       
                                        <p:ajax listener="#{checkView.checkBoxAdmin()}" update="est"></p:ajax>
                                    </h:selectManyCheckbox>

                                    <h:selectManyCheckbox value="#{usuarioSession.roles}" id="doce" disabled="#{checkView.validarDoc}">
                                        <f:selectItem itemValue="2" itemLabel="Docente"></f:selectItem>                          
                                        <p:ajax listener="#{checkView.checkBoxDoc()}" update="est, cursos"></p:ajax>
                                    </h:selectManyCheckbox>

                                    <h:selectManyCheckbox value="#{usuarioSession.roles}" id="est" disabled="#{checkView.validarEst}">
                                        <f:selectItem itemValue="3" itemLabel="Estudiante"></f:selectItem>
                                        <p:ajax listener="#{checkView.checkBoxEst()}" update="doce, admin"></p:ajax>
                                    </h:selectManyCheckbox>

                                </div>
                                
                                <p:outputPanel rendered="#{checkView.check2 == true}" id="cursos" >
                                    <div class="mb-3">
                                        <h:outputLabel class="form-label">Curso</h:outputLabel>
                                        <h:selectManyCheckbox value="#{usuarioSession.cursos}">
                                            <c:forEach items="#{crearCursoView.listarCurso()}" var="lc">
                                                <f:selectItem itemValue="#{lc}" itemLabel="#{lc.nombre}"></f:selectItem>
                                            </c:forEach>
                                        </h:selectManyCheckbox>
                                    </div>
                                </p:outputPanel>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事还在继续 2025-02-20 06:12:39

您有一个非常常见的问题rendered =“#{checkview.check2 == true}”,因为如果未在JSF树中呈现输出panel,则它不会在JSF树中呈现。秘密是始终使用没有渲染标志的包装组件,以便您始终可以更新包装器元素以使p:oppotepanel显示和hide。使用下面的示例,然后更新cursoswrapper而不是furesos

<p:outputPanel id="cursosWrapper">
    <p:outputPanel rendered="#{checkView.check2 == true}" id="cursos" >
        <div class="mb-3">
            <h:outputLabel class="form-label">Curso</h:outputLabel>
            <h:selectManyCheckbox value="#{usuarioSession.cursos}">
                <c:forEach items="#{crearCursoView.listarCurso()}" var="lc">
                    <f:selectItem itemValue="#{lc}" itemLabel="#{lc.nombre}"></f:selectItem>
                </c:forEach>
            </h:selectManyCheckbox>
        </div>
    </p:outputPanel>
</p:outputPanel>

...或使用JSF PassThrough添加JSF:Rendered flag到Inner Div。

<p:outputPanel id="cursosWrapper">
    <div class="mb-3" jsf:rendered="#{checkView.check2 == true}">
        <h:outputLabel class="form-label">Curso</h:outputLabel>
        <h:selectManyCheckbox value="#{usuarioSession.cursos}">
            <c:forEach items="#{crearCursoView.listarCurso()}" var="lc">
                <f:selectItem itemValue="#{lc}" itemLabel="#{lc.nombre}"></f:selectItem>
            </c:forEach>
        </h:selectManyCheckbox>
    </div>
</p:outputPanel>

You have a very common problem rendered="#{checkView.check2 == true}" because if your outputpanel is not rendered its not in the JSF tree so you can't update it. The secret is to always use a wrapper component that has NO rendered flag on it so you can always just update that wrapper element to make the p:outputPanel show and hide. use the example below and update cursosWrapper instead of cursos

<p:outputPanel id="cursosWrapper">
    <p:outputPanel rendered="#{checkView.check2 == true}" id="cursos" >
        <div class="mb-3">
            <h:outputLabel class="form-label">Curso</h:outputLabel>
            <h:selectManyCheckbox value="#{usuarioSession.cursos}">
                <c:forEach items="#{crearCursoView.listarCurso()}" var="lc">
                    <f:selectItem itemValue="#{lc}" itemLabel="#{lc.nombre}"></f:selectItem>
                </c:forEach>
            </h:selectManyCheckbox>
        </div>
    </p:outputPanel>
</p:outputPanel>

...or use JSF passthrough to add jsf:rendered flag to the inner DIV.

<p:outputPanel id="cursosWrapper">
    <div class="mb-3" jsf:rendered="#{checkView.check2 == true}">
        <h:outputLabel class="form-label">Curso</h:outputLabel>
        <h:selectManyCheckbox value="#{usuarioSession.cursos}">
            <c:forEach items="#{crearCursoView.listarCurso()}" var="lc">
                <f:selectItem itemValue="#{lc}" itemLabel="#{lc.nombre}"></f:selectItem>
            </c:forEach>
        </h:selectManyCheckbox>
    </div>
</p:outputPanel>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文