这个问题在这里已有答案:
我在JSF做博客系统。我有一个类似Facebook的“喜欢”系统的想法。我想在这个博客中做我自己的这样的系统。我因为标签而遇到了问题。我的意思是,当用户点击“赞”按钮时,页面会刷新。我该如何解决这个问题?这是我的JSF代码:
<ui:repeat value="#{blogPost.queryPosts}" var="post">
<div style="border:1px;border-color: #333;" >
<li><h1>#{post.title}</h1></li>
<li><h:outputText value="#{post.content}" escape="false" /> </li>
<li>Like :<h:button value="Like" onclick="#{likePost.like2Post(post.id)}" title="Like" />
</li>
<li>reBlog</li>
<li>Comments:</li>
</div>
</ui:repeat>
按钮上的onclick属性是一个DHTML事件属性,用于调用客户端javascript。如果您需要提交表单。使用这样:
<h:commandButton value="Like" action="#{likePost.like2Post(post.id)}" />
要传递参数,您需要有el-api-2.2.jar和el-impl-2.2.jar。有关更多替代方案,请参阅此answer。
此外
<h:button>
用于GET请求。
<h:commandButton> and <h:commandLink> are used to generate POST requests.