views:

58

answers:

1

Here is my code. When I click the link Comment, a inputTextarea and commandButton suppose to appear

    <h:outputLink id="link" value="javascript:void(0)">
            <h:outputText value="Comment"/>
            <p:effect type="fade" event="click" for="reply">
                <f:param name="mode" value="'show'"/>
            </p:effect>
        </h:outputLink>
        <h:panelGrid id="reply" style="display:none;">
            <h:inputTextarea id="keyword" rows="2" /> &nbsp;                
        </h:panelGrid>
    </h:outputLink>

When I click on the link, nothing seem to happen, nothing appear. Any idea. I run this on Glassfish. The showcase from primeface.org is running under Tomcat.

+1  A: 

There are two problems:

First, according to the PrimeFaces User Guide the appear effect is not supported.

Following is the list of effects supported by PrimeFaces.

  • blind
  • clip
  • drop
  • explode
  • fold
  • puff
  • slide
  • scale
  • bounce
  • highlight
  • pulsate
  • shake
  • size
  • transfer

So change the p:effect to:

<p:effect type="blind" event="click" for="reply">
    <f:param name="mode" value="'show'" />  
</p:effect>

Second, the generated source of the link tells the following:

<a href="javascript:void(0)">Comment<script type="text/javascript">
YAHOO.util.Event.addListener('j_idt6:j_idt7', 'click', function(e) {
  jQuery(PrimeFaces.escapeClientId('j_idt6:reply')).effect('blind',{mode:'show'},1000);
});</script></a>

The client ID j_idt6:j_idt7 doesn't appear anywhere in the source. It has to be the link itself. So adding an id to the h:outputLink should fix it. Look like a bug in PrimeFaces.

BalusC
yup.Thank you balusC. It is sad that Primeface forum no longer have the support like before anymore. It used to be that Catay himself answering almost every question. Thanks a lot BalusC
Harry Pham
Hi BalusC, I notice that, when I click the link, the textbox slowly appear, during that time, it is focus, but then when it done loading, it is no longer in focus. Is there away to fix that BalusC? I try to put p:focus in it but it only work when the text box stay display. If it first hidden then make to display, p:focus does not work.
Harry Pham
I've yesterday seen that you've posted a question about this problem, I was going to post an answer in there today, but you seem to have deleted the question?
BalusC
oh man, sorry. Because I was playing with focus using PF and jQuery. So I was worry that the post content is close to this post http://stackoverflow.com/questions/4038456/primefaces-javascript-and-jsf-does-not-work-well-together-or-am-i-doing-somethi, so I delete that post, will repost later, got to go to work now
Harry Pham
Anyway, the answer boils down that there's no support for `jQuery.effect()` callback option in `p:effect` and that you've got to post a feature request at PF guys.
BalusC
Does it mean that, from the way I set up, there is no way to put focus on the textbox when I click the link to make the appear. Correct? Essentially, I want to mimic what stackoverflow, `add comment` feature, that when u click on a link, a textbox appear and it got focus. Do u mind explain a bit in detail of why jQuery.effect() callback option for p:effect essentially the solution for my problem?
Harry Pham
Check the `jQuery.effect()` [documentation](http://docs.jquery.com/UI/Effects/effect). There's a callback argument wherein you can pass a function which is to be executed when the effect is finished. The `<p:effect>` doesn't offer any way to define it the JSF way. You would like to have for example an `oncomplete` attribute on it. Of course, you can drop the `<p:effect>` completely and take it in your hands with "plain" jQuery.
BalusC
uhmm I like the idea of switch to jQuery but the reason I choose p:effect is: I need a link and a textbox at every row of the dataTable, and when I click on the link, only the textbox on the same row appear, and p:effect achieve that so easy. With jQuery, if u remember my other post, I have to add `prependId=false` to form, meaning that I can only add effect to one textbox. Can u think of a way to do it with jQuery?
Harry Pham
I have made a different post for this particular issue: Thank you BalusC: http://stackoverflow.com/questions/4048261/jsf-jquery-how-to-achieve-stackoverflow-collapsible-comment-box
Harry Pham