2014-09-23 100 views
1

你知道在faces-config中沒有匹配的導航箱時是否有一個選項將commandbutton設置爲disabled =「true」嗎?如何在faces-config.xml中沒有導航的情況下禁用commandbutton

當時我正在學習JSF寫一個應用程序。該應用程序包含各種頁面。我使用默認模板,我插入navigatontemplate。

這裏是我的導航模板

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<ui:composition 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:pt="http://xmlns.jcp.org/jsf/passthrough"> 


<ui:insert name="navigation"> 
      <nav>   
       <h:panelGroup> 
       <h:form> 
       <h:commandButton value="GO BACK" styleClass="button" action="GOBACK"/> 
       <h:commandButton value="Reset" pt:type="Reset" styleClass="button" action="RESET"/> 
       <h:commandButton value="GO FORWARD" action="GOFORWARD" styleClass="button"/> 
       </h:form> 
      </h:panelGroup> 
      </nav> 
    </ui:insert> 
</ui:composition> 
在faces-配置

現在我有一些導航規則,例如:

<navigation-rule> 
    <display-name>firstPage.xhtml</display-name> 
    <from-view-id>/firstPage.xhtml</from-view-id> 
    <navigation-case> 
     <from-outcome>GOFORWARD</from-outcome> 
     <to-view-id>/secondPage.xhtml</to-view-id> 
    </navigation-case> 
</navigation-rule> 

現在我想,當用戶禁用GoBack的-按鈕在第一頁上(並且在faces-config.xml中沒有導航規則)。

任何人的想法如何?

謝謝。

+0

有時候也有全球導航規則也必須受到尊重。你可以在'action'執行時動態地添加導航規則,所以我認爲沒有標準的方法! – 2014-09-23 12:26:36

+0

如果根據視圖bean屬性禁用按鈕是可行的?然後,你可以將第一頁和最後一頁存儲在視圖bean中,並且每次添加一個新頁面時,都會更新「最後一頁」頁面(我猜第一頁從未改變過)「 – Smutje 2014-09-23 12:41:14

+0

@Smutje和PeterRader感謝您的幫助。沒有最佳實踐?我發現了一些也適用:我在Navigation-template的命令按鈕中添加了以下內容:'disabled =「#{view.viewId =='/firstPage.xhtml'}'。你認爲這是好的,不違反公約? – javaProgrammer 2014-09-23 13:17:15

回答

1

我現在找到了一個有效的解決方案:

<h:commandButton value="GO BACK" styleClass="button" disabled="#{view.viewId=='/firstPage.xhtml'} action="GOBACK"/> 

的EL表達式view.viewId返回用戶visting的頁面。

相關問題