I am trying to display a random number on a panel through PrimeFaces panel. I have the following xhtml code:
<h:form>
<p:growl id="msgs" showDetail="true" />
<p:panel id="basic" header="Random Number" style="margin-bottom:20px">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="#{randomnum.number}" />
</h:panelGrid>
</p:panel>
</h:form>
This panel calls randomnum.number which is like this
import java.io.Serializable;
import java.util.Random;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class randomnum implements Serializable {
private int number;
public randomnum() {
}
public int getNumber() {
return number;
}
@PostConstruct
public void init() {
Random r = new Random();
int Low = 10;
int High = 100;
number = r.nextInt(High-Low) + Low;
System.out.println("Random Number :"+number);
}
}
But when I run my xhtml code, I see the panel but I do not see anything inside it. Also, the System.out.println() output is not displayed on console. How do I resolve the issue? My basic aim is that when I run the xhtml code then a random number must be shown on the panel.