如何隐藏取消隐藏面板中的面板?

时间:2013-09-18 14:57:54

标签: jsf jsf-2 primefaces

我有一个复选框,所以当我点击我的复选框时,我想取消隐藏我的面板,当我取消选中我的复选框时,我希望我的面板隐藏。 但到目前为止,我的代码还没有成功: managedbean:

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Date;

import javax.faces.event.ActionEvent;

import com.avon.mx.constants.TagsPrintConstants;
import com.avon.mx.utils.FacesUtils;

public class DevolucionesCCMB {

    private String codigoFS;
    private String descripcionFS;
    private String lote;
    private boolean busqueda;
    private Date fechaProduccion;

    private int numeroCajas;
    private int numeroPiezasXCaja;
    private int total;
    private Date fechaIngreso;

    private boolean mostrar;
    private boolean invalidarEtiqueta;
    private String claveEtiqueta;
    private String comentariosEtiqueta;

    private int cantidadAImprimir;

    /**
     * Constructor
     */
    public DevolucionesCCMB() {

    }

    public String redirecciona() {
        if (FacesUtils.existeUsuarioLogueado()) {
            limpiarCampos();
            return TagsPrintConstants.PAGE_DEVOLUCIONES_CC;
        } else {
            return TagsPrintConstants.PAGE_LOGIN;
        }
    }

    /*
     * Obtener el dia hoy
     */
    public Date getNow() {
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
        Date date = new Date();
        return date;
    }

    /*
     * Método para limpiar campos
     */
    public void limpiarCampos() {
        setCodigoFS(TagsPrintConstants.VACIO);
        setDescripcionFS(TagsPrintConstants.VACIO);
        setLote(TagsPrintConstants.VACIO);
        setFechaProduccion(getNow());
        setNumeroCajas(TagsPrintConstants.ZEROINT);
        setNumeroPiezasXCaja(TagsPrintConstants.ZEROINT);
        setTotal(TagsPrintConstants.ZEROINT);
        setFechaIngreso(getNow());
        setInvalidarEtiqueta(TagsPrintConstants.FALSO);
        setClaveEtiqueta(TagsPrintConstants.VACIO);
        setComentariosEtiqueta(TagsPrintConstants.VACIO);
        setCantidadAImprimir(TagsPrintConstants.ZEROINT);
        setMostrar(false);
    }

    public void mostrarOcultar() {
        if (isInvalidarEtiqueta()) {
            setMostrar(true);
        } else {
            setMostrar(false);
        }
        System.out.println("inv: " + isInvalidarEtiqueta());
        System.out.println("most: " + isMostrar()); 
    }

    public void obtenerDescripcion(ActionEvent actionEvent) { 
        setDescripcionFS("Descripción");
    }

    /**
     * @return the codigoFS
     */
    public String getCodigoFS() {
        return codigoFS;
    }

    /**
     * @param codigoFS the codigoFS to set
     */
    public void setCodigoFS(String codigoFS) {
        this.codigoFS = codigoFS;
    }

    /**
     * @return the descripcionFS
     */
    public String getDescripcionFS() {
        return descripcionFS;
    }

    /**
     * @param descripcionFS
     *            the descripcionFS to set
     */
    public void setDescripcionFS(String descripcionFS) {
        this.descripcionFS = descripcionFS;
    }

    /**
     * @return the lote
     */
    public String getLote() {
        return lote;
    }

    /**
     * @param lote
     *            the lote to set
     */
    public void setLote(String lote) {
        this.lote = lote;
    }

    /**
     * @return the fechaProduccion
     */
    public Date getFechaProduccion() {
        return fechaProduccion;
    }

    /**
     * @param fechaProduccion
     *            the fechaProduccion to set
     */
    public void setFechaProduccion(Date fechaProduccion) {
        this.fechaProduccion = fechaProduccion;
    }

    /**
     * @return the numeroCajas
     */
    public int getNumeroCajas() {
        return numeroCajas;
    }

    /**
     * @param numeroCajas
     *            the numeroCajas to set
     */
    public void setNumeroCajas(int numeroCajas) {
        this.numeroCajas = numeroCajas;
    }

    /**
     * @return the numeroPiezasXCaja
     */
    public int getNumeroPiezasXCaja() {
        return numeroPiezasXCaja;
    }

    /**
     * @param numeroPiezasXCaja the numeroPiezasXCaja to set
     */
    public void setNumeroPiezasXCaja(int numeroPiezasXCaja) {
        this.numeroPiezasXCaja = numeroPiezasXCaja;
    }

    /**
     * @return the total
     */
    public int getTotal() {
        return total;
    }

    /**
     * @param total
     *            the total to set
     */
    public void setTotal(int total) {
        this.total = total;
    }

    /**
     * @return the invalidadEtiqueta
     */
    public boolean isInvalidarEtiqueta() {
        return invalidarEtiqueta;
    }

    /**
     * @param invalidadEtiqueta
     *            the invalidadEtiqueta to set
     */
    public void setInvalidarEtiqueta(boolean invalidarEtiqueta) {
        this.invalidarEtiqueta = invalidarEtiqueta;
    }

    /**
     * @return the claveEtiqueta
     */
    public String getClaveEtiqueta() {
        return claveEtiqueta;
    }

    /**
     * @param claveEtiqueta
     *            the claveEtiqueta to set
     */
    public void setClaveEtiqueta(String claveEtiqueta) {
        this.claveEtiqueta = claveEtiqueta;
    }

    /**
     * @return the comentariosEtiqueta
     */
    public String getComentariosEtiqueta() {
        return comentariosEtiqueta;
    }

    /**
     * @param comentariosEtiqueta
     *            the comentariosEtiqueta to set
     */
    public void setComentariosEtiqueta(String comentariosEtiqueta) {
        this.comentariosEtiqueta = comentariosEtiqueta;
    }

    /**
     * @return the cantitadAImprimir
     */
    public int getCantidadAImprimir() {
        return cantidadAImprimir;
    }

    /**
     * @param cantitadAImprimir the cantitadAImprimir to set
     */
    public void setCantidadAImprimir(int cantidadAImprimir) {
        this.cantidadAImprimir = cantidadAImprimir;
    }

    /**
     * @return the busqueda
     */
    public boolean isBusqueda() {
        return busqueda;
    }

    /**
     * @param busqueda the busqueda to set
     */
    public void setBusqueda(boolean busqueda) {
        this.busqueda = busqueda;
    }

    /**
     * @return the fechaIngreso
     */
    public Date getFechaIngreso() {
        return fechaIngreso;
    }

    /**
     * @param fechaIngreso the fechaIngreso to set
     */
    public void setFechaIngreso(Date fechaIngreso) {
        this.fechaIngreso = fechaIngreso;
    }

    public boolean isMostrar() {
        return mostrar;
    }

    public void setMostrar(boolean mostrar) {
        this.mostrar = mostrar;
    }

}

这是我的xhtml:

<p:messages id="messages" showDetail="true" autoUpdate="true"
    closable="true" />
<h:form id="formUnits">
    <p:blockUI block="formUnits" trigger="codigoFSP" widgetVar="dlg">
        <p:graphicImage value="./resources/img/cargando.gif"
            style="alignment-adjust: central" />
    </p:blockUI> 
    <p:growl id="growl" showDetail="true" />
    <p:panel id="formulario" styleClass="panelDevoluciones">
        <fieldset>
            <legend id="leyend" class="leyend"> Devoluciones CC </legend>
            <table class="tablaDevolucionCC" border="0">
                <tr>
                    <td align="right">
                        <h:outputLabel id="invalidarEtiqueta" value="Invalidar Etiqueta: " styleClass="textoEtiqueta"/>
                    </td>                               
                    <td align="left">
                        <p:selectBooleanCheckbox id="invalidarEtiquetaP" value="#{devolucionesCCMB.invalidarEtiqueta}">
                            <p:ajax update="growl :formUnits:myPanel" listener="#{devolucionesCCMB.mostrarOcultar}"/> 
                        </p:selectBooleanCheckbox>                                                                      
                    </td>                                          
                </tr>   
                <tr>
                    <p:panel widgetVar="myPanel" rendered="#{devolucionesCCMB.mostrar}" autoUpdate="true">
                        <td align="right">
                            <h:outputLabel id="claveEtiqueta" value="Clave de la Etiqueta: " styleClass="textoEtiqueta"/>
                        </td>
                        <td align="left">
                            <p:inputText id="claveEtiquetaP" value="#{devolucionesCCMB.claveEtiqueta}" disabled="false" size="15" styleClass="textoEtiqueta"/>
                        </td>  
                     </p:panel>                             
                </tr>                                                                                                                                                                                                                                                                                                                       
            </table>
        </fieldset>
    </p:panel>
</h:form>

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

您必须将myPanel包装在另一个容器中并更改它。您的问题基本上是当您的面板保持隐藏状态时,p:selectBooleanCheckbox无法更新它,因为该组件未在DOM树中呈现。您的问题与this case完全相同。这应该做的工作:

<h:panelGroup id="parentPanel">
    <p:panel widgetVar="myPanel" rendered="#{devolucionesCCMB.mostrar}">
        <td align="right">
            <h:outputLabel id="claveEtiqueta" value="Clave de la Etiqueta: " styleClass="textoEtiqueta"/>
        </td>
        <td align="left">
            <p:inputText id="claveEtiquetaP" value="#{devolucionesCCMB.claveEtiqueta}" disabled="false" size="15" styleClass="textoEtiqueta"/>
        </td>  
     </p:panel>  
</h:outputPanel> 

<p:selectBooleanCheckbox id="invalidarEtiquetaP" value="#{devolucionesCCMB.invalidarEtiqueta}">
    <p:ajax update="parentPanel" listener="#{devolucionesCCMB.mostrarOcultar}"/> 
</p:selectBooleanCheckbox>    
相关问题