Rendering HTML5 buttons (button, reset and submit) in JSF2

风流意气都作罢 提交于 2020-01-15 15:31:13

问题


As you may know that you can render button in HTML5 in 2 methods:

  • Using void element <input type="button" /> or
  • If you want content, use the <button></button> element (which isn't a void element).

In JSF2, there are 2 ways to generate buttons; either with UICommand or UIOutcomeTarget component. I understand what these 2 components are for, my question what would be the best component for the 2 HTML5 button types, should one create these HTML5 components in JSF2?

So far, the best aspects is to create a UICommand and UIOutcomeTarget for each HTML5 elements.


回答1:


The UICommand component should be used for a POST button like <h:commandButton type="submit"> and the UIOutcomeTarget component should be used for a GET button like <h:button>. The void button is in JSF represented by <h:commandButton type="button"> which is essentially UICommand, but it doesn't do anything.

JSF2 doesn't have any component which generates a <button>. The mentioned components generate a <input>. PrimeFaces' <p:commandButton> and <p:button> however generates a fullworthy <button> (for the sole reason because it allows easier control over look'n'feel by CSS).

If you intend to create a custom component which generates a <button> and want to decide between UICommand and UIOutcomeTarget, then you should base it on whether the desired HTML representation of the button ultimately fires a POST or a GET request. If your button should support both, then go for UICommand.

See also:

  • Difference between h:button and h:commandButton

Unrelated to the concrete problem, none of those buttons are HTML5 specific. They existed in previous HTML versions already.



来源:https://stackoverflow.com/questions/17842929/rendering-html5-buttons-button-reset-and-submit-in-jsf2

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