buildingconverter.java

来自「一个购房管理系统,JSF+Hibernate+Mssql2」· Java 代码 · 共 57 行

JAVA
57
字号
/*
 * BuildingConverter.java
 *
 * Created on 2007��5��29��, ����2:59
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.housesale.jsfbean;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import com.housesale.hibernate.Building;

/**
 * 
 * @author MSQ
 */
public class BuildingConverter implements Converter {

	/** Creates a new instance of BuildingConverter */
	public BuildingConverter() {
	}

	public Object getAsObject(FacesContext facesContext,
			UIComponent uIComponent, String string) {
		if (string == null) {
			return null;
		}
		Integer id = new Integer(string);
		BuildingController controller = (BuildingController) facesContext
				.getApplication().createValueBinding("#{building}").getValue(
						facesContext);

		return controller.findBuilding(id);
	}

	public String getAsString(FacesContext facesContext,
			UIComponent uIComponent, Object object) {
		if (object == null) {
			return null;
		}
		if (object instanceof Building) {
			Building o = (Building) object;
			return "" + o.getBuildingId();
		} else {
			throw new IllegalArgumentException("object:" + object + " of type:"
					+ object.getClass().getName()
					+ "; expected type: com.housesale.hibernate.Building");
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?