jsf html标签里面的值

Joh*_*lez 8 html jsf-2 twitter-bootstrap-3

我有这个命令按钮,我需要使用Bootstrap 3添加一个图标.

<h:commandButton  id="logoutButton" action="#{loginController.logout()}" class="btn btn-primary" style="margin-top: 10px;margin-left: 10px;" value="Log Out"></h:commandButton>
Run Code Online (Sandbox Code Playgroud)

由于引导3的原因,图标在span标记中,所以我试图将它添加到命令按钮中的value属性,如下所示:

<h:commandButton  id="logoutButton" action="#{loginController.logout()}" class="btn btn-primary" style="margin-top: 10px;margin-left: 10px;" value="<span class="glyphicon glyphicon-log-out"></span>Log Out"></h:commandButton>
Run Code Online (Sandbox Code Playgroud)

我有一个错误,我想我不能在value属性中添加html标签,有没有一种简单的方法可以做到这一点?

Bal*_*usC 18

您不能将标记放在valueJSF组件的属性中.您应该像在普通HTML中一样将标记放在标记正文中.但是,这不受支持<h:commandButton>(原因很简单,因为它生成一个<input>元素,任何子代都会以无效的HTML结尾).它将在生成的元素之后呈现<input>.

只需使用<h:commandLink>.虽然它生成了一个<a>元素,但Bootstrap CSS也只支持它以及btn样式类.

<h:commandLink id="logoutButton" action="#{loginController.logout}" styleClass="btn btn-primary">
    <span class="glyphicon glyphicon-log-out"></span>Log Out
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)

(注意我修正了错误的class属性styleClass)