helponfocuscomponent.java

来自「jsf与JavaScript结合的范例。让你轻松学会网络编程。」· Java 代码 · 共 48 行

JAVA
48
字号
package jsfcssjs;

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

import java.util.Map;

public class HelpOnFocusComponent extends SetupComponent {

    protected void setup(FacesContext ctx, UIComponent comp) {
        Map attrMap = comp.getAttributes();
        String helpOnFocus = getAttribute(attrMap, "helpOnFocus");
        if (helpOnFocus != null) {
            String helpParam[] = new String[] {
                    EncodeUtils.encodeString(helpOnFocus).toString() };
            insertCall(attrMap, "onfocus", "showHelpOnFocus", helpParam);
            insertCall(attrMap, "onblur", "clearHelpOnBlur", null);
        }
    }
    
    protected String getAttribute(Map attrMap, String attrName) {
        Object attrValue = attrMap.get(attrName);
        if (attrValue != null)
            return attrValue.toString();
        else
            return null;
    }
    
    protected void insertCall(Map attrMap, String attrName,
            String functionName, String functionParams[]) {
        String attrValue = getAttribute(attrMap, attrName);
        if (attrValue != null && attrValue.indexOf(functionName) != -1)
            return;
        StringBuilder buf = EncodeUtils.encodeCall(
                functionName, functionParams);
        if (attrValue != null && attrValue.length() > 0) {
            buf.append(';');
            buf.append(attrValue);
        }
        attrMap.put(attrName, buf.toString());
    }
    
    public String getFamily() {
        return "HelpOnFocus";
    }

}

⌨️ 快捷键说明

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