2

I had a very simple task today that I needed help with. First let me explain my environment. We are on a Java/Hibernate/SEAM/Facelets/JSF/RichFaces & A4J setup.. and I don't know to much about it.

I work with it when all of the work on the old asp platform is complete.

SO I had something like this (I just cannot remember if I had () after stockCheck.. I am home now):

<h:commandLink value="Submit" action="session.stockCheck()"/>

The stockCheck() method would NOT run though! It does not return a value it's job is to create a record in a DB, and it does that perfectly.

So I tried a few things and nothing would work, I asked my co-worker and he said to just change it to a4j and it should work. I asked him why, but he did not know.

See now I get REALLY hung up when I do not understand WHY things are or are not working.

The solution to submit the email to the database was:

<a:commandLink value="Submit" action="session.stockCheck()"/>

BTW: we have our namespace for a4j set to just a.

I am here hoping somebody can explain some things about this to me.

What went on behind the scenes and what needs to be understood about the failure of <h:commandLink> in this situation?

Thank you.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
JoJo
  • 4,643
  • 9
  • 42
  • 65
  • 3
    That can happen if the form containing the standard command link is re-rendered by another ajax request beforehand. Is this true for your case? This is a bug in ajax4jsf. All other possible causes are outlined in [this answer](http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183). Nested forms is another possibility, but that would have been an obvious mistake. – BalusC Oct 24 '12 at 22:51
  • @BalusC Thank you for the link to that very detailed answer! I did have nested forms btw, and when I removed the nested form the h:commandLink action attribute fired the appropriate method. So it was not because of another ajax request. I do find it interesting that in .NET for example the page would have failed right away and thrown the error on nested forms.. But I guess JSF does have some 'tolerance'?... – JoJo Oct 25 '12 at 21:59
  • JSF indeed doesn't validate that. – BalusC Oct 25 '12 at 23:22

1 Answers1

1

That can happen if you're nesting forms. This is illegal in HTML and the behaviour is unspecified and dependent on the webbrowser used. The ajax link doesn't submit the form, it just collects the input values by JavaScript and then sends a XMLHttpRequest in the background.

See also:

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