How to hide table?

1

I'm trying to hide a table by pressing a button but I do not want to work, probably the answer is simple but I have not found it

this is my XHTML:

<!DOCTYPE html>
<html xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui"
  xmlns="http://www.w3.org/1999/xhtml">
<h:head>
    <title>TODO supply a title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</h:head>
<body>
    <h:form id="form">
        <p:panel id="panel" rendered="#{dtBasicView.hola eq 1}">
            <p:dataTable id="dt">
                <p:column headerText="Hola"/>
                <p:column headerText="Tabla"/>
                <p:column headerText="Desaparece"/>            
            </p:dataTable>
        </p:panel>
        <p:commandButton value="Ostia!" action="#{dtBasicView.cambiar()}" 
                         process="@this"
                         update=":form:panel form:dt">

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

and this is my bean:

public class BasicView implements Serializable{
  private Integer hola;
}
@PostConstruct
public void init(){
    hola=1;
}

public void cambiar(){
    hola=2; 

}
    
asked by Juan 02.08.2018 в 18:33
source

1 answer

0

Friend you reach has your bean? In the case of ViewScope or SesionScope

Try this:

<h:form id="form">
    <p:panel id="panel" >
                <p:dataTable id="dt" rendered="#{dtBasicView.hola eq 1}">
                    <p:column headerText="Hola"/>
                    <p:column headerText="Tabla"/>
                    <p:column headerText="Desaparece"/>            
                </p:dataTable>
         </p:panel>
   <p:commandButton value="Ostia!" action="#{dtBasicView.cambiar()}" 
                         update=":form:panel"/>
 </h:form>

And the Bean (check the keys), also make use of the getter's & setter's

public class BasicView implements Serializable{
private Integer hola;
@PostConstruct
public void init(){
    this.setHola(1);
}
public void cambiar(){
   this.setHola(2); 
}
public Integer getHola() {
     return hola;
}
public void setHola(Integer hola) {
            this.hola = hola;
}
}
    
answered by 03.08.2018 в 19:10