0

I'm been scratching my head over this one... I have plenty of projects with a working commandLink element, however I cannot for the life of me get it to work in this project. I've followed BalusC response here: commandButton/commandLink/ajax action/listener method not invoked or input value not updated down to the letter and yet still no joy.

Currently I've boiled my code down to as simple as it can go:

@ManagedBean
@SessionScoped
public class TestBean {

    private @Inject transient Logger logger; 

    public void testEvent(ActionEvent actionEvent) {
        logger.log(Level.INFO, "Event Fired!!");
        return;
    }
}

In my xhtml file i have:

<h:form>
   <h:commandLink id="test" actionListener="#{testBean.testEvent}" value="Test Me!"/>
</h:form>

When I click the link, the method is not invoked, and I am redirected to the web-apps root (login page, despite having a login filter :/) If I change the link to a commandButton it works as expected.

The current application utilises the ui:composition tags for templating, and I've triple checked for nested h:form tags, I'm not using any ajax calls or additional JS libraries. My templates implement jsf tags where it matters i.e. h:head, h:body etc.. Could anyone provide any indication or possible causes for the weird behavior I am experiencing?

Finally I have tested this commandLink in on various pages within my web-app and the commandLink element in general just refuses to invoke.

Here is the compiled html of my link if anyone is interested:

<form id="j_idt26" name="j_idt26" method="post" action="/my-project/webpages/Login.xhtml" enctype="application/x-www-form-urlencoded">
   <input type="hidden" name="j_idt26" value="j_idt26" />
   <a id="j_idt26:test" href="#" onclick="mojarra.jsfcljs(document.getElementById('j_idt26'),{'j_idt26:test':'j_idt26:test'},'');return false">Test Me!</a><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-109553560791909389:-730254890454894147" autocomplete="off" />
</form>
Community
  • 1
  • 1
Ally
  • 1,476
  • 3
  • 19
  • 30
  • Is it working with `action` in order of `actionListener`? Try removing parameter from method's signature and changing return type to `String`. – Aritz Feb 26 '13 at 21:48
  • Yep I've tried this and it produces the same result. – Ally Feb 26 '13 at 21:51
  • The code example that you provide works as expected. Can you please post a [SSCCE](http://sscce.org) of the code you're trying to make work? – Luiggi Mendoza Feb 26 '13 at 21:52
  • Sure, its in quite a heavy jpa/ejb app, I'll clone my git repo & strip it down, but it may take me a little bit. Hopefully, I'll find the issue as I strip it down. – Ally Feb 26 '13 at 22:24
  • Do you have JS disabled in browser? `` requires JS, but I wouldn't expect it to navigate to the application root when JS is disabled. – BalusC Feb 27 '13 at 00:28
  • @Ally Have you ruled out a security plugin servlet filter like Spring Security? Often they operate as a filter in front of requests and if the proper authenticated session token is not passed then they will usually redirect to the application root or login page. – maple_shaft Feb 27 '13 at 02:08
  • @Ally, what does the generated HTML look like for the command link vs the command button? – kolossus Feb 27 '13 at 05:41
  • @kolossus I have added the generated html to the original post, as far as I can see, nothing looks out of the ordinary. – Ally Feb 27 '13 at 07:50
  • @BalusC Nope, JS is definitely enabled & I've tested on multiple browsers, which produces the same result. So its an issue with my project. – Ally Feb 27 '13 at 07:57
  • @maple_shift I have implemented JAAS, however I am not using any security filters or additional api's such as Spring. I have a single filter that redirects some1 who navigates to the Login page if they are already logged in, but I've got log statements on this method and it isnt invoked when clicking a commandlink. – Ally Feb 27 '13 at 07:58
  • Are you absolutely positive that you don't have JS errors? E.g. "mojarra is undefined"? Your security restriction might have blocked `jsf.js` file containing the mandatory `jsfcljs()` script. Look at the HTTP traffic monitor in your webbrowser's developer toolset. – BalusC Feb 27 '13 at 11:33
  • @BalusC I had looked at my console before and there was no output, however watching the console as I click the link an Uncaught Exception flashes up then disappears. If I set a breakpoint, the error is a: 'ReferenceError'. I can see that jsf.js is available via the Developer Tools > Resources folder. How can I determine if any security restriction are blocking access to jsf.js? – Ally Feb 27 '13 at 14:58
  • Check HTTP response status code in HTTP traffic monitor. Or, just open it yourself by copypasting/entering its URL in browser's address bar to see the response the browser actually retrieved. – BalusC Feb 27 '13 at 15:01
  • @BalusC Request URL:http://localhost:8085/my-project/javax.faces.resource/jsf.js.xhtml?ln=javax.faces Request Method:GET Status Code:200 OK (from cache) Get calls to the jsf.js appear to be fine, however no POST request is made, which makes sense given the 'ReferenceError' i receive. As above I am going to clone and strip my project to try and find the root cause. – Ally Feb 27 '13 at 18:59
  • Uh no, that part is unrelated. Just to exclude the one and other. Coming back to the reference error, please post its cause / stack trace. – BalusC Feb 27 '13 at 19:04

1 Answers1

0

After rebuilding the project, commandLinks work as they should and I was unable to reproduce the error in my new project. If I get time, I will try and debug my original project and determine what the original issue is/was.

Ally
  • 1,476
  • 3
  • 19
  • 30