0

我知道之前有人问过这个问题,但是即使在仔细查看了包括 Balus 优秀答案“ h:commandLink / h:commandButton 没有被调用”+“侦听和调试 JSF 生命周期阶段”在内的各种帖子之后,我仍然无法理解为什么我无法在我的选项卡中呈现 JSF 页面。

我在 CSS 选项卡“规则”下有一个 PrimeFaces 选项卡“规则管理”,它成功显示了以下 Jsf 文件 RuleAdmin2.xhtml。在该页面中,我有一个按钮来创建新规则。

它应该使用新屏幕 (RuleDetails.xhtml) 的值更新支持 bean 目标属性 (ruleAdminBK.target) 并在“规则管理”选项卡中呈现此文件。

当我调试时,我注意到确实调用了“创建新规则”,并且目标填充了正确的文件“RuleDetails.xhtml”。但是,该选项卡仍显示父表单“RuleAdmin2.xhtml”。

当我单击“规则”链接时,整个页面都会刷新,“规则管理”选项卡会显示正确的页面 (RuleDetails.xhtml)。

在我看来,它比 bean 更新之前的选项卡呈现。

日志文件中没有相关信息,也没有消息。

任何提示都非常感谢,因为我的想法已经不多了。

这是我的代码:我的 Facelet 模板 (matTemplate.xhtml)

<!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:c="http://java.sun.com/jsp/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="sessionTimeout" http-equiv="refresh" content="#{session.maxInactiveInterval};url='/mat/errorExpired.xhtml?faces-redirect=true&amp;viewName=#{view.viewId}'" />
        <f:metadata>
            <ui:insert name="metadata">Placeholder Data</ui:insert>
        </f:metadata>

        <title><ui:insert name="title">Placeholder Title</ui:insert></title>
        <ui:insert name="head"></ui:insert>
        <style type="text/css">
            @media print {
                #header, #mainmenu, #footer
                {
                    display: none !important;
                }
                #wrapper {
                    width:760px;
                    border-left:0px solid #013f7a;
                    border-right:0px solid #013f7a;
                    margin:0 auto;
                    background:#fff;
                    padding:0 5px;
                }
            }
         </style>
    </h:head>

    <h:body>
        <h:form id="templateForm">

        <div id="wrapper">
            <ul id="mainmenu">
                <li><h:link outcome="/home3.xhtml">Home</h:link></li>        
                <li><h:link outcome="/admin/rules/RuleAdmin.xhtml">Rules</h:link></li>
            </ul>
            <div id="content"  >
                <ui:insert name="content">Content</ui:insert>
            </div>
        </div>        
        <div id="footer">
            <ui:insert name="footer" >
            </ui:insert>
         </div>
        </h:form>
    </h:body>
</html>

我定义标签的主页:

<?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:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en"
      xmlns:c="http://java.sun.com/jstl/core"
      xmlns:p="http://primefaces.org/ui" >
       <ui:composition template="./../../WEB-INF/matTemplate.xhtml">
            <ui:define name="content">
                <p:tabView id="tabView" dynamic="true" cache="false" activeIndex="0">
                        <p:tab id="tab1" title="Rules Administration">     
                              <ui:include src="#{ruleAdminBK.target}" />            
                        </p:tab>  
                  </p:tabView>       
            </ui:define>
        </ui:composition>
</html>

并且调用了backing bean。

@Component
@Scope("session")
public class RuleAdminBK extends BaseBean {

    private static final String _RULE_DETAILS = "/admin/rules/RuleDetails.xhtml";
    private static final String _RULE_ADMIN = "/admin/rules/RuleAdmin2.xhtml";
    private String target = _RULE_ADMIN;

public void cmdCreateNew_Click() {
        setTarget(_RULE_DETAILS);
    }

最后是 2 个 JSF 文件:RuleAdmin2.xhtm

<?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:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en"
    xmlns:p="http://primefaces.org/ui">
<ui:composition>
    <h:panelGroup layout="block" id="rulesAdministration">
        <h:outputText id="lblStatus" value="#{ruleAdminBK.lblStatus}" />
        <table width="100%">
            <tr>
                <td align="center"><br />
                    <h1>Rules Administration</h1> <br /> <h:outputLabel
                        id="lblErrorText1" value="#{ruleAdminBK.lblErrorText}"
                        styleClass="ValidateMsg" /></td>
            </tr>
            <tr>
                <td align="right"><p:commandButton
                        action="#{ruleAdminBK.cmdCreateNew_Click}" value="create rule" /></td>
            </tr>
        </table>
    </h:panelGroup>
</ui:composition>
</html>

RuleDetails.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:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en"
    xmlns:p="http://primefaces.org/ui">


<f:view beforePhase="#{ruleDetailsBK.Page_BeforePhase}">
    <h:outputText value="TBD" />
</f:view>
</html>
4

1 回答 1

0

更新组件的代码部分在哪里?也许您可以尝试以下方法 - 在方法 *cmdCreateNew_Click()* 中以编程方式更新组件,如下所示:

public void cmdCreateNew_Click() {
    setTarget(_RULE_DETAILS);
    //add this line and check the path to the component
    RequestContext.getCurrentInstance().update("templateForm:content:tabView");
}
于 2013-11-22T11:40:23.663 回答