Jsf f:convertNumber-won和#x27;行不通

Jsf f:convertNumber-won和#x27;行不通,jsf,converter,composite-component,Jsf,Converter,Composite Component,我制作了一个JSF复合组件,它使用f:convertNumber。但是,它不能转换值。这是如何造成的,我如何解决 currency.xhtml <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <

我制作了一个JSF复合组件,它使用
f:convertNumber
。但是,它不能转换值。这是如何造成的,我如何解决

currency.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:composite="http://java.sun.com/jsf/composite"
    xmlns:f="http://java.sun.com/jsf/core">

    <composite:interface>
    </composite:interface>

    <composite:implementation>
        <f:convertNumber pattern="#,###" currencyCode="\\"/> 
    </composite:implementation>
</html>

这确实行不通

复合组件被解释为UI组件。然而,
是标记处理程序,而不是UI组件。基本上,它将应用于复合材料本身(并呈现为无用),而不是您所期望的目标组件

<h:outputText value="10000000">
    <mycomp:currency />
</h:outputText>
您至少有两种选择:

  • 也将
    移动到组合中

    <composite:interface>
        <composite:attribute name="value" />
    </composite:interface>
    <composite:implementation>
        <h:outputText value="#{cc.attrs.value}">
            <f:convertNumber pattern="#,###" currencyCode="\\" />
        </h:outputText>
    </composite:implementation>
    

    
    
    当您按照此处所述在标记文件中注册此转换器时

    
    通货
    默认电流转换器
    
    然后,您最终可以按预期使用它

    <h:outputText value="10000000">
        <mycomp:currency />
    </h:outputText>
    
    
    
  • 另见:

    “无法转换”是模糊的。想更明确地描述这个问题以及实际发生了什么吗?@Kukeltje谢谢,我希望我的Composit Componet(currency.xhtml)将h:outputText的值转换为“10000000”作为模式属性(#,#。然而,它显示“10000000”。因此,我认为转换器无法转换值。这是工作。我还需要进一步研究JSF。非常感谢,不客气。请随意提出以前没有问过的问题:)
    <mycomp:currency value="10000000" />
    
    @FacesConverter("defaultCurrencyConverter")
    public class DefaultCurrencyConverter extends NumberConverter {
    
        public DefaultCurrencyConverter() {
            setPattern("#,###");
            setCurrencyCode("\\");
        }
    
    }
    
    <h:outputText value="10000000" converter="defaultCurrencyConverter" />
    
    <tag>
        <tag-name>currency</tag-name>
        <converter>
            <converter-id>defaultCurrencyConverter</converter-id>
        </converter>
    </tag>
    
    <h:outputText value="10000000">
        <mycomp:currency />
    </h:outputText>