2

I have this:

<h:link value="Sign In" outcome="login.jsp" />

When the link is clicked it navigates to login.jsp. Works fine.

I'd also like a method in a bean to get called on the click, so I tried this:

<h:link value="Sign In" outcome="login.jsp" />
  <f:ajax event="click" listener="#{loginHandler.dismissSignUpDialog}" />
</h:link>

But it never calls the method. The method looks like this:

public void dismissSignUpDialog(AjaxBehaviorEvent e) {
    setSignUpDialogDismissed(true);
}

Any idea what I'm doing wrong? Thanks!

2 Answers2

3

The <f:ajax> indeed doesn't work on <h:link> that way. Use <h:commandLink> instead.

<h:form>
    <h:commandLink value="Sign In" action="login.jsp?faces-redirect=true" />
        <f:ajax listener="#{loginHandler.dismissSignUpDialog}" />
    </h:commandLink>
</h:form>

By the way, why are you still using JSP instead of Facelets?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks. That explains things. I have two pages login.jsp and loginError.jsp that are configured as the two pages in the in the web.xml. All the pages in my application are Facelets/XHTML but these two pages are JSP -- originally because my understanding was I could not use a "JSF" page for the login page. Any suggestions in this area? –  Aug 09 '11 at 19:04
  • Why not? You've all freedom to write plain HTML in a Facelet file. You can even use JSF components in a plain HTML GET form. See also http://stackoverflow.com/questions/2206911/best-way-for-user-authentication-on-javaee-6-using-jsf-2-0/2207147#2207147 – BalusC Aug 09 '11 at 19:07
  • There is a small typo in the code, and SO doesn't allow me to make edits smaller than 6 character. There is a closing tag for h:commandLink after action has been defined; slash should be removed. BTW BalusC rocks! :) – Nikola Jun 22 '14 at 10:27
0

I think you would be far better off using an <h:commandLink> whose action is set to your method, then alter the method to return String corresponding to your outcome. That is:

 <h:commandLink value="Sign In" action="#{loginHandler.dismissSignUpdialog}" />

And the bean:

 public String dismissSignUpDialog() {
     setUpDialogDismissed(true);
     return "login";
 }
cobaltduck
  • 1,598
  • 5
  • 25
  • 51