Java Reference
In-Depth Information
For example, using the refresh() function, we could dynamically modify the
options on a drop-down component based on the selection on another drop-down
component, or we could modify the text on a static text component based on values
that are entered in a text field. These tasks would be done by making an Ajax request
to the server and updating the component without refreshing the whole page.
The refresh() JavaScript function needs to be invoked whenever a JavaScript event
such as onChange , onBlur , onMouseOver , and so on is triggered.
In the following example, we will illustrate how to update a static text component
based on selections made on various drop-down components. In this example, we
simulate an application in which a laptop computer can be customized and ordered.
As the user selects different options for the laptop, its price changes accordingly.
After creating a visual web project as usual, the first thing we need to do is to create
some properties in a session scoped managed bean to hold the values selected by the
user, and the value to be displayed in the static text component. The easiest way to
go here is to modify the generated SessionBean1.java managed bean.
package com.ensode.ajaxlaptoporder;
import com.sun.rave.web.ui.appbase.AbstractSessionBean;
import javax.faces.FacesException;
public class SessionBean1 extends AbstractSessionBean {
private int price;
private String selectedScreenSize = "12";
private String selectedMemory = "1";
private String selectedHardDiskSize = "60";
public SessionBean1() {
}
//Automatically generated methods removed for brevity
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getSelectedHardDiskSize() {
 
Search WWH ::




Custom Search