HTML and CSS Reference
In-Depth Information
Listing 2-20. The Login Action Method in the User Managed Bean
public class User implements Serializable {
...
public String login() {
return "welcome";
}
...
}
As shown in Listing 2-20, the method of the action attribute have the following signature:
Returns a String (outcome) that is used for determining the navigation.
Adding to this, if you are working with EditableValueHolder s, you can invoke a method expression from the
valueChangeListener attribute. Let's see an example to explain this. Listing 2-21 shows the beverages page, which
contains a selectOneMenu component that holds a list of beverages and an outputText to show the price of the
selected beverage.
Takes no argument.
Listing 2-21. The Beverages Page
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns=" http://www.w3.org/1999/xhtml "
xmlns:h=" http://java.sun.com/jsf/html "
xmlns:f=" http://java.sun.com/jsf/core " >
<h:head>
<title>Beverages</title>
</h:head>
<h:body>
<h:form>
<h:outputText value="Select a beverage: " />
<h:selectOneMenu value="#{beverage.name}"
valueChangeListener="#{beverage.beverageSelected}"
onchange="submit()">
<f:selectItem itemLabel="---" itemValue="---"/>
<f:selectItem itemLabel="Tea" itemValue="tea" />
<f:selectItem itemLabel="Coffee" itemValue="coffee" />
<f:selectItem itemLabel="Coca-Cola" itemValue="cocacola" />
</h:selectOneMenu> <br/><br/>
<h:outputText value="You will have to pay: #{beverage.price} USD"
rendered="#{beverage.price ne null}"/>
</h:form>
</h:body>
</html>
 
Search WWH ::




Custom Search