⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 carbean.java

📁 一个比较好的jsf spring hibernate的例子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                            converter = ((ValueHolder) component).                                getConverter();                            result = ((ValueHolder) component).getValue();                        }                        // if we do have a value                        if (null != result) {                            // and we do have a converter                            if (null != converter) {                                // convert the value to String                                result = converter.                                    getAsString(FacesContext.                                                getCurrentInstance(),                                                component, result);                            }                        }                    }                    return result;                }                public int hashCode() {                    return CarBean.this.components.hashCode();                }                public boolean isEmpty() {                    return CarBean.this.components.isEmpty();                }                public java.util.Set<String> keySet() {                    return CarBean.this.components.keySet();                }                public Object put(Object k, Object v) {                    throw new UnsupportedOperationException();                }                public void putAll(Map t) {                    throw new UnsupportedOperationException();                }                public Object remove(Object k) {                    throw new UnsupportedOperationException();                }                public int size() {                    return CarBean.this.components.size();                }                public Collection<Object> values() {                    ArrayList<Object> result =                           new ArrayList<Object>(this.size());                    for (Object o : keySet()) {                        result.add(get(o));                    }                    return result;                }            };    }    /**     * <p>For each entry in data, create component and cause it to be     * populated with values.</p>     * @param context the <code>FacesContext</code> for the current request     * @param data a ResourceBundle     */    private void initComponentsFromProperties(FacesContext context,                                              ResourceBundle data) {        // populate the map        for (Enumeration<String> keys = data.getKeys(); keys.hasMoreElements();) {            String key = keys.nextElement();            if (key == null) {                continue;            }            // skip secondary keys.            if (key.contains("_")) {                continue;            }            String value = data.getString(key);            String componentType = data.getString(key + "_componentType");            String valueType = data.getString(key + "_valueType");            if (LOGGER.isLoggable(Level.FINE)) {                LOGGER.fine("populating map for " + key + "\n" +                            "\n\tvalue: " + value +                            "\n\tcomponentType: " + componentType +                            "\n\tvalueType: " + valueType);            }            // create the component for this componentType            UIComponent component =                  context.getApplication().createComponent(componentType);            populateComponentWithValue(context, component, componentType,                                       value, valueType);            components.put(key, component);        }    }    /**     * <p>populate the argument component with values, being sensitive     * to the possible multi-nature of the values, and to the type of     * the values.</p>     * @param context the <code>FacesContext</code> for the current request     * @param component the <code>UIComponent</code> to populate     * @param componentType the component type     * @param value the value     * @param valueType the value type     */    private void populateComponentWithValue(FacesContext context,                                            UIComponent component,                                            String componentType,                                            String value,                                             String valueType) {        Application application = context.getApplication();        Converter converter = null;        // if we need a converter, and can have a converter        if (!"java.lang.String".equals(valueType) &&            component instanceof ValueHolder) {            // if so create it,            try {                converter =                      application.createConverter(CarStore.loadClass(valueType,                                                                     this));                // add it to our component,                ((ValueHolder) component).setConverter(converter);            } catch (ClassNotFoundException cne) {                FacesMessage errMsg = MessageFactory.getMessage(                      CONVERTER_ERROR_MESSAGE_ID,                      valueType);                throw new IllegalStateException(errMsg.getSummary());            }        }        // if this component is a SelectOne or SelectMany, take special action        if (isMultiValue(componentType)) {            // create a UISelectItems instance            UISelectItems items = new UISelectItems();            items.setValue(parseStringIntoArrayList(value, converter));            // add it to the component            component.getChildren().add(items);        } else {            // we have a single value            if (null != converter) {                component.getAttributes().put("value",                                              converter.getAsObject(context,                                                                    component,                                                                    value));            } else {                component.getAttributes().put("value", value);            }        }    }       /**     * Determines if the component type is a SelectMany or SelectOne.     * @param componentType the component type     * @return true of the componentType starts with SelectMany or SelectOne     */    private boolean isMultiValue(String componentType) {        if (null == componentType) {            return false;        }        return (componentType.startsWith("javax.faces.SelectMany") ||                componentType.startsWith("javax.faces.SelectOne"));    }    /*     * Tokenizes the passed in String which is a comma separated string of     * option values that serve as keys into the main resources file.     * For example, optionStr could be "Disc,Drum", which corresponds to     * brake options available for the chosen car. This String is tokenized     * and used as key into the main resource file to get the localized option     * values and stored in the passed in ArrayList.     */    /**     * <p>Tokenizes the passed in String which is a comma separated string of     * option values that serve as keys into the main resources file.     * For example, optionStr could be "Disc,Drum", which corresponds to     * brake options available for the chosen car. This String is tokenized     * and used as key into the main resource file to get the localized option     * values and stored in the passed in ArrayList.</p>     *     * @param value a comma separated String of values     * @param converter currently ignored     * @return a <code>List</code> of <code>SelectItem</code> instances     *  parsed from <code>value</code>     */    public List<SelectItem> parseStringIntoArrayList(String value,                                         Converter converter) {        if (value == null) {            return null;        }        String[] splitOptions = value.split(",");        ArrayList<SelectItem> optionsList =              new ArrayList<SelectItem>((splitOptions.length) + 1);        for (String optionKey : splitOptions) {            String optionLabel;            try {                optionLabel = resources.getString(optionKey);            } catch (MissingResourceException e) {                // if we can't find a hit, the key is the label                optionLabel = optionKey;            }            if (null != converter) {                // PENDING deal with the converter case            } else {                optionsList.add(new SelectItem(optionKey, optionLabel));            }        }        return optionsList;    }    public String updatePricing() {        getCurrentPrice();        return null;    }    public Integer getCurrentPrice() {        // go through our options and try to get the prices        int sum = (Integer) ((ValueHolder) getComponents().get("basePrice")).              getValue();        for (Object o : getComponents().keySet()) {            String key = (String) o;            UIComponent component = (UIComponent) getComponents().get(key);            Object value = component.getAttributes().get("value");            if (null == value || (!(component instanceof UIInput))) {                continue;            }            // if the value is a String, see if we have priceData for it            if (value instanceof String) {                try {                    sum +=                          Integer.valueOf(priceData.getString((String) value));                } catch (NumberFormatException e) {                    // do nothing                }            }            // if the value is a Boolean, look up the price by name            else if (value instanceof Boolean &&                     (Boolean) value) {                try {                    sum +=                          Integer.valueOf(priceData.getString(key));                } catch (NumberFormatException e) {                    // do nothing                }            } else if (value instanceof Number) {                sum += ((Number) value).intValue();            }        }        Integer result = sum;        // store the new price into the component for currentPrice        ((ValueHolder) getComponents().get("currentPrice")).              setValue(result);        return result;    }    public Map getComponents() {        return components;    }    public Map<String,Object> getAttributes() {        return attributes;    }}

⌨️ 快捷键说明

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