有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我有一个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) 个答案