Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML 4 <button> in JSF 2.1

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

like image 765
endrigoantonini Avatar asked Oct 08 '12 00:10

endrigoantonini


3 Answers

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>.
like image 127
BalusC Avatar answered Oct 19 '22 20:10

BalusC


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

like image 34
maple_shaft Avatar answered Oct 19 '22 20:10

maple_shaft


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.

like image 2
Otávio Garcia Avatar answered Oct 19 '22 19:10

Otávio Garcia