使用ui:include,rich:popupPanel和navigation-rules创建向导

时间:2013-04-02 21:12:25

标签: jsf-2 richfaces faces-config uiinclude

我正在尝试使用ui创建一个向导:包含在faces-config.xml中的RichFaces 4 popupPanel和navigation-rules中,但是在完成支持bean中的操作时,页面不会导航到目标页面。我已经检查过以确保bean按预期执行并且它提供了预期的结果。

JSF页面和包含的页面如下所示:

<rich:popupPanel modal="true" id="addSvcAcctPanel" autosized="true">

        <rich:messages id="addSvcAcctPanelMessages" globalOnly="false"
            styleClass="message" />

        <a:outputPanel id="includeAddSvcAcct">          
            <ui:include src="/layout/addSvcAccPg2.xhtml" />
        </a:outputPanel>                    

        <h:form id="closeSvcAcctForm">
            <div class="buttons">
                <a:commandButton styleClass="save" id="closeAddSvcBtn"
                    value="close"
                    onclick="#{rich:component('addSvcAcctPanel')}.hide()"
                    render="hasAgentsAccItm,svcAccAccordItm,svcAcctsTab,svcAccInfo,agentPanel,ServiceAccts,noticesAccordion">
                    <rich:tooltip direction="topRight" mode="client" showDelay="300"
                        styleClass="tooltip" layout="block">

                        <span style="white-space: wrap">Click on the 'Close'
                            button to close this panel and return to the main screen. If you
                            have any unsaved information on this page, it will be lost when
                            you click close.</span>

                    </rich:tooltip>
                </a:commandButton>
            </div>              
        </h:form>
    </rich:popupPanel>

两个面板插入的JSF代码如下:

Pg 1 .....

<?xml version="1.0" encoding="UTF-8" ?>
<h:form xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:richext="http://java.sun.com/jsf/composite/richext"
    xmlns:a="http://richfaces.org/a4j">

    <rich:panel id="addSvcAcctPanelContent" headerClass="head2" style="height:100%;">
        <f:facet name="header">
            <h:outputText styleClass="med_black_type_bold_facet"
                value="Add a Service Account" />
        </f:facet>



        <h:panelGrid columns="3">
            <h:outputText styleClass="med_black_type_bold"
                value="Department" id="companyLabel" />

            <rich:select styleClass="med_black_type" id="companySelect"
                required="true" value="#{main.selected_company}" render="acctWarning, accountLabel1" valueChangeListener="#{main.determineProperAccountName}">
                <f:selectItem
                    itemLabel="Please select an Organisation"
                    itemValue="" />
                <f:selectItems value="#{country_companies}" />
                <a:ajax event="selectitem" render="acctWarning, accountLabel1, acctNumberExplain, acctIdHeader, acctIDHelp" execute="@this"/>               
            </rich:select>

            <rich:message for="companySelect" style=" width : 330px;" />

            <h:outputText styleClass="med_black_type_bold"
                value="Account 'Nickname'" id="nicknameLabel" />


            <h:inputText styleClass="med_black_type" id="nickname"
                value="#{main.alias}" onfocus="#{rich:component('nickNameHelpPanel')}.show()"
                onblur="#{rich:component('nickNameHelpPanel')}.hide()">
                <rich:validator />  

                <!-- <f:ajax event="focus" execute="@this" onevent="#{rich:component('nickNameHelpPanel')}.show()"/>        
                <f:ajax event="blur" execute="@this" onevent="#{rich:component('nickNameHelpPanel')}.hide()"/> --> 
            </h:inputText>
            <rich:message for="nickname" style=" width : 330px;" />

            <richext:spacer width="30" />
            <h:outputText id="acctWarning" styleClass="med_blue_type_bold"
                value="Enter the #{main.accountProperName} below - numbers and letters only! No dots or dashes." />
            <richext:spacer width="30" />

            <h:outputText styleClass="med_black_type_bold"
                value="#{main.accountProperName}" id="accountLabel1" />

            <h:inputText styleClass="med_black_type" id="account"
                value="#{main.account_id}" onfocus="#{rich:component('acctIDHelpPanel')}.show()"
                onblur="#{rich:component('acctIDHelpPanel')}.hide()">
                <rich:validator />

                <!-- <f:ajax event="focus" execute="@this" onevent="#{rich:component('acctIDHelpPanel')}.show()"/>      
                <f:ajax event="blur" execute="@this" onevent="#{rich:component('acctIDHelpPanel')}.hide()"/> --> 
            </h:inputText>
            <rich:message for="account" style=" width : 330px;" />
        </h:panelGrid>

        <div class="buttons">

            <a:commandButton styleClass="save" id="addServiceCompany"
                value="save" action="#{main.addAccount}" render="includeAddSvcAcct, includeAddSvcAcct1"/>
        </div>
    </rich:panel>



</h:form>

Pg 2 .....

<?xml version="1.0" encoding="UTF-8" ?>
<h:form xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:richext="http://java.sun.com/jsf/composite/richext"
    xmlns:a="http://richfaces.org/a4j">

<rich:panel>
    <h:outputText value="The service account has been successfully added." styleClass="med_black_type"/>
</rich:panel>   

faces-config的相关摘录如下:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.1" 
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xi="http://www.w3.org/2001/XInclude"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd">

 <navigation-rule>
  <from-view-id>/layout/addSvcAccPg2.seam</from-view-id>
  <navigation-case>
   <from-action>#{main.outcome}</from-action>
   <from-outcome>success</from-outcome>
   <to-view-id>/layout/addSvcAccPg3.seam</to-view-id>
  </navigation-case>
 </navigation-rule>

 <application>
  <locale-config>
   <default-locale>en</default-locale>
   <supported-locale>bg</supported-locale>
   <supported-locale>de</supported-locale>
   <supported-locale>en</supported-locale>
   <supported-locale>fr</supported-locale>
   <supported-locale>tr</supported-locale>
  </locale-config>
 </application>
</faces-config>

支持bean的方法如下:

public String addAccount() {
        String retVal = "failed";
        try {

            getSAFctx.addService(getIntUserId(), 1, selected_company,
                    account_id, alias);         
            retVal = "success";
        } catch (Exception e) {

           System.out.println(e.getMessage());                  

        } finally {                     

            return retVal;
        }
}

我尝试使用pages.xml,* .pages.xml和rich:togglePanel(由于某种原因,不允许commandButtons使用支持bean)。有没有人有任何建议可以提供帮助?有谁知道如何使这个向导工作?

提前致谢。

戴夫。

1 个答案:

答案 0 :(得分:0)

从上面的代码中可以清楚地看到,一旦页面/layout/addSvcAccPg2.seam包含在rich:popupPanel中,那么它将导致在单个页面中具有相同ID的两个不同组件的情况。

您已为rich:popupPanel和rich:panel使用了ID =“addSvcAcctPanel”。这是richfaces的常见问题,并会产生页面导航问题。

让它们与众不同,再试一次。