2014-03-13 42 views
0

我有一個要求在其中一個xhtml組件中添加按鈕。當用戶點擊按鈕時,新窗口應該打開將用戶重定向到另一個xhtml文件,該文件也位於同一個組件項目中。重定向到JSF複合組件中的XHTML文件

這是我在我的組件項目,

|->src 
    |-> main 
    |->java 
     |->META-INF 
     |->faces-config.xml 
      |->resources 
      |->components 
        |->A.xhtml 
        |->B.xhtml 

我需要在將用戶重定向到B.xhtml打開一個新窗口A.xhtml文件中添加一個按鈕。此組件正在其他項目中使用。我嘗試使用target = _blank的commandButton,打開一個新窗口,但不重定向到B.xhtml。

我觀察到如果在A.xhtml文件中使用ui:include src =「B.xhtml」標籤,則B的內容出現在A中,但無法找到它爲什麼不能重定向到新窗戶。不知道我錯過了什麼,並想知道如何實現。

回答

1

@Sanjay您可以通過使用primefacescommandbutton組件將目標設置爲'_blank'並將ajax設置爲'false'來輕鬆實現此目的。

<h:form prependId="false" id="form" target="_blank" > 

<p:commandButton value="Click me to open new url" ajax="false" action="B.xhtml"/> 

</h:form> 

希望這會有所幫助。

+0

我已經嘗試過這一點。想象一下,我在「測試人員」網絡應用中使用這個組件。然後當我點擊命令按鈕時,我得到了url http:// localhost:8080/tester/B.xhtml。它正在Web應用程序中搜索B.xhtml而不是在組件中。 – Sanjay

+0

@Sanjay我也遵循類似的結構,如果'xhtml'文件在同一個地方,它應該工作。 – Java

0

您無法重定向到組件,您必須重定向到包含該組件的PAGE。

想象你有

​​

page1.xhtml含有成分A

page2.xhtml含有成分B

page1.xhtml包含

<!DOCTYPE html> 
<html 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:c="http://java.sun.com/jsp/jstl/core" 
    xmlns:fn="http://java.sun.com/jsp/jstl/functions" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:o="http://omnifaces.org/ui" 
    xmlns:of="http://omnifaces.org/functions" 
    xmlns:cc="http://java.sun.com/jsf/composite/components"> 

    <ui:composition template="/WEB-INF/templates/template.xhtml"> 
     <ui:define name="content"> 

      <cc:a value="someValue" foo="someBar"/> 

     </ui:define> 
    </ui:composition> 
</html> 

和A.xtml是

<h:form prependId="false" id="form" target="_blank" > 

    <p:commandButton value="open" ajax="false" action="page2.xhtml"/> 

</h:form> 

因此,給予好評的@Java,因爲你的答案几乎是正確的,只是改變action解決一個頁面,而不是一個組件在resources

+0

你看,我只有組件項目。此組件項目將作爲jar包含在許多其他Web應用程序中。所以無論我必須做什麼,只有組件項目。簡單地說,我想重定向到組件項目中的/ resources/components /內的A.xhtml組件項目中的一個頁面(B.xhtml)。你認爲它有可能嗎? – Sanjay