2014-03-13 105 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