簡體   English   中英

JSF 2.1中的HTML 4 <button>

[英]HTML 4 <button> in JSF 2.1

我想使用命令:

JSF <h:commandButton>生成一個<input...>但是我想這樣做而不是生成<input>我想生成一個HTML 4標准<button>

使用標准JSF組件集最接近的是<input type="button"> ,它由<h:button>生成。

<h:button value="Button" />

產生

<input id="j_id_1" name="j_id_1" type="button" value="Button" onclick="window.location.href = '/context/currentpage.xhtml'" />

如果您確實堅持使用<button>來解決某些原因,那么您有以下選擇:

  • 只需使用純HTML。
  • 創建自定義組件和/或渲染器。
  • 獲取第三方組件庫。 例如, PrimeFaces的<p:button>生成一個<button>

您應該查看Primefaces p:commandButton 這將呈現給客戶端上的<button>標記。

http://www.primefaces.org/showcase/ui/commandButton.jsf

如果您使用的是JSF 2.2,則可以使用帶有jsf命名空間的<button>標記。 這里的秘密是來自jsf命名空間的屬性process ,它發布表單數據和action屬性。

<button type="submit" class="btn btn-primary" 
    jsf:action="#{profileController.updateProfile}"
    jsf:process="@form">
        <i class="fa fa-floppy-o" aria-hidden="true"></i>
            #{bundle['button.store']}
</button>

在JSF 2.2中,您可以使用與JSF標記混合的任何HTML標記。

它通過用<button> <h:commandLink>替換<button>來為我工作,例如:替換

<button class="RUIFW-btn-primary pull-right" 
        type="submit" 
        name="action" 
        value="Find" 
        onClick="return submitPage(this);">
     <span class="icon-search"></span>Find
</button> 

<h:commandLink styleClass="RUIFW-btn-primary pull-right" 
title="#{msg['view.button.Find']}"
action="#{anotherAccountController.doFind}"
onclick="return submitPage(this.form)">
<span class="icon-search"></span>#{msg['view.button.Find']}
</h:commandLink>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM