2013-08-29 32 views
1

我開發了一個樣例項目來測試JSF2.0中的複合組件。JSF2.0複合組件未在MYFaces中渲染

這裏是我的示例代碼

我的測試文件

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:composite="http://java.sun.com/jsf/composite" 
    xmlns:tp="http://java.sun.com/jsf/composite/test" 
    > 
<h:body> 
    <h:form> 
    <h:outputLabel value="Success"/> 
     <tp:loginComponent 
      usernameLabel="Enter User Name: " 
      usernameValue="#{login.name}" /> 
    </h:form> 
</h:body> 

<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:f="http://java.sun.com/jsf/core" 
xmlns:composite="http://java.sun.com/jsf/composite" 
> 
    <composite:interface> 
     <composite:attribute name="usernameLabel" /> 
     <composite:attribute name="usernameValue" /> 
    </composite:interface> 
    <composite:implementation> 
     <h:form> 
      #{cc.attrs.usernameLabel} : 
      <h:inputText id="username" value="#{cc.attrs.usernameValue}" /> 
     </h:form> 
    </composite:implementation> 

當我在WebSphere 8.5部署的複合材料部件是沒有得到呈現請幫我確定一下起訴

感謝

+0

您在這裏發佈的兩個文件都缺少關閉標記。也是你的組合的路徑和文件名:resources/test/loginComponent.xhtml – Eelke

+0

@Eelke:我在我的代碼中有。它在這裏沒有被錯誤複製。我的複合組件名稱是success.xhtml,我已經將它在WebContent/test文件夾中 – user2462959

回答

1

您必須調整文件的位置和名稱。否則JSF將無法找到它。

xmlns:tp="http://java.sun.com/jsf/composite/test" 

點到JSF(相對於網頁的根目錄)的文件夾resources/test。假設WebContent是您網頁的根目錄,那麼資源文件夾應該位於該目錄中。

當JSF看到<tp:loginComponent .... />時,它將在文件夾中查找名爲loginComponent.xhtml的文件。

編輯

因爲可能有多種資源在你的資源文件夾中,最好創建組件的子文件夾。我通常把它稱爲comps。所以這會給你的路徑 /WebContent/resources/comps在這個文件夾中放置一個名爲loginComponent.xhtml的文件與你的組件。

將命名空間行更改爲:xmlns:tp="http://java.sun.com/jsf/composite/comps"(該資源在資源中是隱含的,但未在URL中指定)。請參閱java ee tutorial

+0

我現在已將chnaged行轉換爲xmlns:tp =「http://java.sun.com/jsf/composite/resources並將該文件重命名爲loginComponent.xhtml,但它仍然無法正常工作.resources是我的web根目錄中的一個文件夾 – user2462959

+0

請不要在URL中指定資源,請參閱我的編輯。 – Eelke

+0

非常感謝。現在爲我工作 – user2462959