HTML and CSS Reference
In-Depth Information
<h:head>
<title>Car Information</title>
</h:head>
<h:body>
<p>
Car Model: #{car.model} <br/>
Car Color: #{car.color}
</p>
</h:body>
</html>
In the previous code, we define two view parameters in the page. Every view parameter has two main attributes,
the
name
attribute, which specifies the name of the request parameter, and the
value
attribute, which represents a
value expression that the value of the request parameter will be bound to. This means that the value of the request
parameter whose name is
model
will be bound to
#{car.model}
expression, and the request parameter whose name is
color
will be bound to
#{car.color}
expression. Listing 4-28 shows
Car
managed bean.
Listing 4-28.
Car Managed Bean
@ManagedBean
@RequestScoped
public class Car {
private String model;
private String color;
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
After calling
car.xhtml
page from the browser with the following parameters:
/car.xhtml?model=300D
&
color=black
This will produce the following content in
car.xhtml
page:
Car Model: 300D
Car Color: black