如何在JSP自定义标记中获取属性值

时间:2017-11-10 12:38:13

标签: java jsp converter

我有一个JSP自定义标签,定义如下:

<facelet-taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
    version="2.0">
    <namespace>http://sp.com/customConverterTaglib</namespace>
        <tag>
            <tag-name>BigDecimalConverter</tag-name>
            <converter>
                <converter-id>BigDecimalConverter</converter-id>
            </converter>
            <attribute>
                <name>pattern</name>
                <required>false</required>
                <type>java.lang.String</type>
            </attribute>
        </tag> 
</facelet-taglib>

我正在尝试在我的XHTML页面中使用它:

 <ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:o="http://sp.com/customConverterTaglib">
    <!-- ... -->

    <h:inputText id="weightId" value="#{backingBeanRef['currentObject']}">
        <o:BigDecimalConverter pattern="###,##0.000"/>
    </h:inputText>

    <!-- ... -->
 </ui:composition>

这是我的BigDecimalConverter类:

 @FacesConverter( value="BigDecimalConverter")
 public class BigDecimalConverter implements Converter {

        private String pattern;

        public BigDecimalConverter() {

        }

        public Object getAsObject(FacesContext facesContext,
                UIComponent uiComponent, String param) {
                //things...
        }

        public String getPattern() {
            return pattern;
        }

        public void setPattern(String pattern) {
            this.pattern = pattern;
        }
   }

当方法运行时,在调试模式下我正在看模式属性为null。哪里出错了?为什么我没有正确获得模式属性?

0 个答案:

没有答案