【问题标题】:Calling another page in JSF在 JSF 中调用另一个页面
【发布时间】:2012-12-13 08:16:07
【问题描述】:

我有一个带有 2 个 .xhtml 文件的简单 JSF 应用程序。当我运行应用程序时,显示的第一页是welcome.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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Final Project</title>
</h:head>
<h:body bgcolor="white">
<div align="center" style="border:5px outset blue;">Welcome to the Product         Inventory     Application</div>
<br></br>
<br></br>
    <h:commandButton value="View All Products" action="allProducts"/>
</h:body>

它显示得很好,但是当我按下查看所有产品按钮时,我希望它显示 allProducts.xhtml facelet。但是当我单击按钮时,什么都没有发生,没有异常或任何事情。 allProducts.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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>All Products</title>
</h:head>
<h:body bgcolor="white">
<h3>Test</h3>
</h:body>
</html>

【问题讨论】:

    标签: jsf


    【解决方案1】:

    问题在于UICommand&lt;h:commandButton&gt;&lt;h:commandLink&gt; 和类似名称)必须位于表单内,即&lt;h:form&gt;。将您的 welcome.xhtml 页面更改为:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
    <title>Final Project</title>
    </h:head>
    <h:body bgcolor="white">
    <div align="center" style="border:5px outset blue;">Welcome to the Product         Inventory     Application</div>
    <br></br>
    <br></br>
        <h:form>
            <h:commandButton value="View All Products" action="allProducts"/>
        </h:form>
    </h:body>
    

    更多信息:

    【讨论】:

      【解决方案2】:

      我不知道确切的细节,但这是大致的想法。欢迎页面上按钮的 action 属性是指支持 bean 的“allProducts”方法。该方法必须返回字符串“allProducts.xhtml”才能让 JSF 显示产品页面。 因此,您必须为欢迎页面引入一个支持 bean,并赋予该类一个方法“allProducts”。

      【讨论】:

      • 不一定。您可以只写您想要转发的视图的名称,或者从一个返回 String 的支持 bean 调用一个方法,该 String 包含(检查)您想要转发的视图的名称
      猜你喜欢
      • 1970-01-01
      • 2015-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-24
      • 2017-08-20
      • 2019-09-16
      • 2012-01-30
      相关资源
      最近更新 更多