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); 
    }`
Smith
  • 131
  • 3
  • 13
  • Please describe in detail how exactly it fails. Please mention exact JSF impl/version. – BalusC Mar 29 '12 at 23:07
  • 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: PATRICK CARROLL output generated with command link: – Smith Mar 30 '12 at 02:54
  • "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 `` approach doesn't work as you'd expect it would work, but this is a different problem. – BalusC Mar 30 '12 at 02:56
  • 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 `` 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 Mar 30 '12 at 03:16
  • @BalusC Its javascript issue. Thanks for directing me to look at the javascript console. JS error "Uncaught ReferenceError: mojarra is not defined" – Smith Mar 30 '12 at 03:17
  • I will try with mojarra 2.1.7 and try to dig deeper into the javascript. Thanks for now. – Smith Mar 30 '12 at 03:19
  • The JavaScript error helped much in understanding the cause and thus the solution simply became obvious. I have posted an answer. – BalusC Mar 30 '12 at 03:19

1 Answers1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555