Описание правила навигации не работает должным образом в Face-config.xml

Любая причина, почему displaypage.xhtml не перенаправляет на frontpage.xhtml при нажатии кнопки "GoBack"? Браузер перенаправляет из frontpage.xhtml в displaypage.xhtml, но не наоборот.

Спасибо

frontpage.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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="WEB-INF/templates/origin.xhtml">
    <ui:define name="content">
        <f:view>
            <h:form>
                <h:panelGrid>
                    <h:inputText value="#{user.name}" required = "true"/>
                </h:panelGrid>
                <h:commandButton

                    action="#{user.testcase2()}"
                    value="Search"></h:commandButton>
            </h:form>
            </f:view>


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

displaypage.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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/WEB-INF/templates/origin.xhtml">
    <ui:define name="content">
       <h:panelGrid>
        <h:outputText value="#{user.testclass.inputName}"/>
        <h:commandButton id="back" value="GoBack" action="frontpage"/>
       </h:panelGrid>
    </ui:define>
</ui:composition>
</html>

Лица-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    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_0.xsd"
    version="2.0">

    <navigation-rule>
        <from-view-id>/frontpage.xhtml</from-view-id>
        <navigation-case>
            <from-action>#{user.testcase2()}</from-action>
            <from-outcome>test2</from-outcome>
           <to-view-id>/displaypage.xhtml</to-view-id>
            <redirect/>
        </navigation-case>
         </navigation-rule>
   <navigation-rule>
    <from-view-id>/displaypage.xhtml</from-view-id>
            <navigation-case>
                <from-outcome>frontpage</from-outcome>
                <to-view-id>/frontpage.xhtml</to-view-id>
                <redirect/>
        </navigation-case>
    </navigation-rule>
</faces-config>

1 ответ

Решение

<h:commandButton> тег должен быть покрыт <h:form> быть активным, особенно если action атрибут <h:commandButton> содержать динамическую навигацию (например: action=#{user.testcase2()})

Иначе, если этот последний тег имеет только статическую навигацию, (строка, например: action="frontpage" )затем просто используйте <h:button> как сказал M. @BalusC, потому что он не поддерживает динамическую навигацию.

Другие вопросы по тегам