customerfunctionconverter.java

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

JAVA
50
字号
/*
 * CustomerFunctionConverter.java
 *
 * Created on 2007��6��2��, ����11:01
 *
 * 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.CustomerFunction;

/**
 *
 * @author msq
 */
public class CustomerFunctionConverter implements Converter {
    
    /** Creates a new instance of CustomerFunctionConverter */
    public CustomerFunctionConverter() {
    }

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

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

⌨️ 快捷键说明

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