Reputation: 29
I'm beginner in JSF programming, so I have a simple question.
I have the following jsf file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Insert Title Here</title>
</h:head>
<body>
<h:form>
<h:panelGrid columns="3">
/* Here I take the username */
<h:outputLabel for="username">Username</h:outputLabel>
<h:inputText id="username" value="#{register.user.username}"
required="true" requiredMessage="Enter username">
<f:ajax event="blur" render="usernameMessage" />
</h:inputText>
<h:message id="usernameMessage" for="username" />
/* Here I take the password */
<h:outputLabel for="password">Password</h:outputLabel>
<h:inputSecret id="password" value="#{register.user.password}"
required="true" redisplay="true" requiredMessage="Enter password">
<f:ajax event="blur" render="passwordMessage" />
</h:inputSecret>
<h:message id="passwordMessage" for="password" />
/* Here I take the email */
<h:outputLabel for="email">Email</h:outputLabel>
<h:inputText id="email" value="#{register.user.email}"
required="true" requiredMessage="Enter email">
<f:ajax event="blur" render="emailMessage" />
</h:inputText>
<h:message id="emailMessage" for="email" />
/* And these are my 3 command buttons, and they are working only when the username, password and email are filled in. */
<h:panelGroup>
<h:commandButton value="Register" action="#{register.submit}">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:commandButton value="setDB" action="#{register.setDB}">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:commandButton value="getDB" action="#{register.getDB}">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:commandButton value="reset" action="#{register.reset}">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
</h:panelGroup>
<h:messages globalOnly="true" layout="table" />
</h:panelGrid>
</h:form>
/* And this is the button that I want to work without the need to fill in the username, password and email */
<h:panelGroup rendered="#{register.user.ini!=true}">
<h3>Result</h3>
<h:commandButton value="getDB" action="#{register.getDB}" />
</h:panelGroup>
</body>
</html>
So my question is how to make the following command button to work:
<h:panelGroup rendered="#{register.user.ini!=true}">
<h3>Result</h3>
<h:commandButton value="getDB" action="#{register.getDB}" />
</h:panelGroup>
It doesn't appear when I start the application. I just want to get database information without the need to fill the fields in :) ... the other buttons are in the form and they work only when the field's username, password and email have something inside. This code produces neither an exception nor an error, but the button doesn't work (the one that is outside the form).
Upvotes: 3
Views: 1855
Reputation: 37051
You can't use h:commandButton
unless it's inside a h:form
I'm not sure what you are trying to achieve but take a look at this PreRenderViewEvent
Also If you want to run some logic on bean creation , you can use @PostConstruct
in your bean
@PostConstruct
public void init() {
retrieveDB();
}
Also , its a really bad practice to give get/set prefix to bean action methods , get/set better be used for geters/setters only
Upvotes: 3