0

I'm doing blog system in JSF. I have an idea similar to Facebook's 'like' system. I want to do my own such system in this blog. I ran into a problem because of tag. I mean, the page is refreshing when user clicked the like button. How can I fix that? Here is my JSF code:

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

1 Answers1

0

The onclick attribute on the button is a DHTML event attribute to call client side javascript. If you need to do a form submit. Use like this:

<h:commandButton value="Like" action="#{likePost.like2Post(post.id)}" />

And to pass a parameter, you need to have el-api-2.2.jar and el-impl-2.2.jar. See this answer for more alternatives.

Moreover

<h:button> 

is used for GET requests.

<h:commandButton> and <h:commandLink> are used to generate POST requests.
Community
  • 1
  • 1
Ravi Kadaboina
  • 8,494
  • 3
  • 30
  • 42