2010-11-03 14 views
3

我一直在玩弄JSF 2.0複合組件,但是我對composite:attribute標籤中的require屬性的含義有些困惑。該文檔表明,如果頁面作者必須爲此屬性提供值,則必需的屬性爲true。複合組件需要的屬性在Mojarra 2.0.3中拋出異常

我將它解釋爲必須爲所有具有required=true的composite:屬性提供值。我還假定一個空字符串是一個有效的值。這就是它在Mojarra 2.0.2中的工作原理。

使用這個簡單的託管bean:

@ManagedBean(name = "simpleMB") 
@ViewScoped 
public class SimpleManagedBean implements Serializable { 

    private static final long serialVersionUID = -1; 

    private String whatever; 

    ... setter and getter 
} 

和複合組件:

<composite:interface> 
    <composite:attribute name="value" required="true" /> 
</composite:interface> 

<composite:implementation> 
    <h:outputText value="Value: '#{cc.attrs.value}'" />  
</composite:implementation> 

這些標籤在鑽嘴魚科2.0.2工作:

<foo:bar value="" /> 
<foo:bar value="#{simpleMB.whatever}" /> 

然而,當我升級到2.0.3,只有第一個標籤起作用。第二個標記導致此錯誤消息:

/requiredAttribute.xhtml @20,42 <foo:bar> The following attribute(s) are 
required, but no values have been supplied for them: value. 

它工作正常,當我設置需要假。

我誤解了所需屬性的含義嗎?有人能澄清我應該期待什麼行爲嗎?

謝謝。

+0

嗨,我剛碰到這個相同的問題。與Mojarra 2.0.3一起出現。感覺像一個錯誤? – 2010-11-19 10:57:18

回答

0

我不知道它是否是一個bug,但它是el表達式的本質。默認表達式類型是字符串,空字符串翻譯爲空。

+0

這是不同的。儘管你試圖傳遞給該屬性,但Mojarra 2.0.3總是會拋出一個錯誤... – 2010-11-28 12:54:34

2

我們有與@ViewScoped bean結合使用required =「true」的相似問題。

我們的情況bean不再像@ViewScoped bean(每次都有新的構造函數)一樣工作。

你的問題可能是因爲這個bean失去了它的範圍,這些variabels又是空的?

無論是哪種情況,我可以給你的唯一一種方法是不使用required =「true」或使用@SessionScoped bean。

(也許這涉及到鑽嘴魚科不能夠處理在@ViewScoped豆綁定屬性的問題)

0

這似乎已經this issue,這似乎已經在不久前關閉的,雖然我不能似乎發現它包含在哪個版本中。