h:commandLink actionlistener is not invoked when used with f:ajax and ui:repeat
Asked Answered
R

1

3

h:commandLink actionlistener is not invoked when used with f:ajax and ui:repeat When I click the link, I have to pass a parameter in the bean's "onload" method and refresh the panelgroup "assist". It works fine when I use the commandButton but not with commandLink.

<h:panelGroup id="assist" styleClass="tabbed-panel-vertical">
<ul id="assistlink" class="tabbed-panel-vertical-tabs">
    <ui:repeat var="assistants"
        value="#{permissions.repAssistants}">
        <li><h:commandLink 
                            actionListener="#{permissions.onload}"
            value="#{assistants.name}"
                styleClass="#{permissions.selectedAssistant==assistants.userId ? 'selected' : ''}">
                <f:ajax
                    render=":permissionsform:assist :permissionsform:permissionsContent"
                    execute="@this">
                    <f:attribute name="assistantId"
                        value="#{assistants.userId}" />
                </f:ajax>
            </h:commandLink></li>
    </ui:repeat>
</ul>

    `public void onload(ActionEvent event) {
    Long userId = Long.valueOf(541);// user.getUserId();
    Long assistantId = (Long) event.getComponent().getAttributes().get("assistantId");
    System.out.println("User " + assistantId); 
    }`
Returnee answered 29/3, 2012 at 21:25 Comment(7)
Please describe in detail how exactly it fails. Please mention exact JSF impl/version.Hithermost
Jsf 2.0, mojarra impl. The method "onload" is never invoked when I click on the commandlink. When I replace the commandLink with a commandButton, I see that the method gets invoked. output generated from commandLink: <a href="#" onclick="mojarra.jsfcljs(document.getElementById('permissionsform'),{'j_idt13:0:j_idt15':'j_idt13:0:j_idt15'},'');return false" class="">PATRICK CARROLL</a> output generated with command link: <input type="submit" name="j_idt13:0:j_idt15" value="PATRICK CARROLL" class="selected" />Returnee
"JSF 2.0" is a specification. Which Mojarra version are you using? Which browsers have you used? Are there any errors in JavaScript console when you click the link? How does the ajax request/response look like? By the way, the <f:attribute> approach doesn't work as you'd expect it would work, but this is a different problem.Hithermost
By the way, this piece of code works perfectly fine for me with Mojarra 2.1.7 on the most recent versions of all the four major webbrowsers (expect of course that the <f:attribute> doesn't work the way as you intended). So your problem is caused by something else which is not shown in the code so far.Hithermost
@Hithermost Its javascript issue. Thanks for directing me to look at the javascript console. JS error "Uncaught ReferenceError: mojarra is not defined"Returnee
I will try with mojarra 2.1.7 and try to dig deeper into the javascript. Thanks for now.Returnee
The JavaScript error helped much in understanding the cause and thus the solution simply became obvious. I have posted an answer.Hithermost
H
4

As per the comments:

@BalusC Its javascript issue. Thanks for directing me to look at the javascript console. JS error "Uncaught ReferenceError: mojarra is not defined"

Make sure that you've a <h:head> tag in your master template instead of <head>. This way JSF will be able to auto-include the necessary JavaScript file for the Ajax magic.

Hithermost answered 30/3, 2012 at 3:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.