3
votes

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); 
    }`
1
Please describe in detail how exactly it fails. Please mention exact JSF impl/version.BalusC
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" />Smith
"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.BalusC
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.BalusC
@BalusC Its javascript issue. Thanks for directing me to look at the javascript console. JS error "Uncaught ReferenceError: mojarra is not defined"Smith

1 Answers

4
votes

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.