HTML 4 <button> in JSF 2.1

橙三吉。 提交于 2020-01-03 07:31:08

问题


I would like to use the commands:

The JSF <h:commandButton> generates an <input...> but I would like that instead of generating the <input> I would like that this generate a HTML 4 standard<button>.


回答1:


You should look into the Primefaces p:commandButton. This will render to a <button> tag on the client.

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




回答2:


Closest what you can get with standard JSF component set is <input type="button"> which is generated by <h:button>.

<h:button value="Button" />

which generates

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

If you really insist in using <button> for some unclear reason, then you have the following options:

  • Just use plain HTML.
  • Create a custom component and/or renderer.
  • Grab a 3rd party component library. E.g. PrimeFaces' <p:button> generates a <button>.



回答3:


If you are using JSF 2.2, you can just use the <button> tag with jsf namespace mixed. The secret here is the attribute process from jsf namespace, that post the form data, and the action attribute.

<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>

In JSF 2.2 you can use any HTML tag mixing with JSF tags.




回答4:


It works for me by replacing <button> with <h:commandLink>, example: Replace

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

with

<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>


来源:https://stackoverflow.com/questions/12773907/html-4-button-in-jsf-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!