JSF、Richfaces学习

通过这个demo,可以理解richfaces的基本运行方式,对该技术有一个感性认识。

其中有ajax标签,可以自动同步数据到服务器端,方便开发人员,当然用得不好,也可能造成性能低下的问题!


演示效果:


1.输入框当中默认是5


2.修改为8

JSF、Richfaces学习_第1张图片

3. 右边的菜单会自动更新成8个选项

JSF、Richfaces学习_第2张图片

选中option3后,会出现如下日志输入:

JSF、Richfaces学习_第3张图片


官方文档:

http://docs.jboss.org/richfaces/latest_4_X/vdldoc/a4j/ajax.html


TestBean.java

package com.ccbupt.kaoshi.xuanze;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import org.richfaces.demo.tables.model.capitals.Capital;
import com.ccbupt.kaoshi.service.UserRoleService;

@ManagedBean(name="testBean")
@SessionScoped
public class TestBean implements Serializable{

	private static final long serialVersionUID = 1109360897806292248L;
	private List capitalsOptions = null;
	private String value = "";
	private int count = 5;
	
	/**@ManagedProperty(value="userRoleServices")
	private UserRoleService userRoleService;
	*/
	
	
	@PostConstruct
	public void init() {
		capitalsOptions = new ArrayList();
		//System.out.println(count);
		for(int i = 0; i < count; i++) {
			capitalsOptions.add(new SelectItem(i,"option"+i));
		}
	}
	
/*	public void valueChanged(ValueChangeEvent event) {
        capitalsOptions.clear();
        System.out.println(count);
        if (null != event.getNewValue()) {
        	capitalsOptions = new ArrayList();
            for (int i = 0; i < count; i++) {
            	capitalsOptions.add(new SelectItem("1","二"));
            }
        }
	}
*/	
	public List getCapitalsOptions() {
		return capitalsOptions;
	}

	public void setCapitalsOptions(List capitalsOptions) {
		this.capitalsOptions = capitalsOptions;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

/**	public UserRoleService getUserRoleService() {
		return userRoleService;
	}

	public void setUserRoleService(UserRoleService userRoleService) {
		this.userRoleService = userRoleService;
	}
*/
	public void getTiJiao() {
		System.out.println(value + "已被选中" + count);
	}
    
	public int getCount() {
		return count;
	}
	
	public void setCount(int count) {
		capitalsOptions.clear();
		for (int i = 0; i < count; i++) {
        	capitalsOptions.add(new SelectItem(i,"option"+i));
        }
		
		this.count = count;
	}
		
}





test.html




	
	

	



你可能感兴趣的:(javaee)