Just a quick question if someone in this forum has worked with jQuery and JSF. Unfortunately not many people in the jQuery forums have worked with JSF and therefore I'm having major problems trying to get help on my question below.
When jQuery executes an ajax call to a specific URL where in that JSP page a specific bean is being called and jQuery is passing in the parameter and in my IDE I have a BREAKPOINT setup in that SET method and if that method is actually being called won't the processing stop at my breakpoint? And if it is NOT stopping then can I safely assume that I'm never getting to my bean?
Here is my jQuery code:
Here is the changeSelectedFacilityCode.jsp page:
If anyone can please take a look at this code and let me know what I'm doing wrong it would be appreciated. The generated SPAN from jQUERY is never getting populated and therefore I cannot see it in my alert .
Well, technically, you can never "call" a bean - JSF or not. A bean is an object, so you can call a method defined on that object, but you can't call the object. Not that I need much excuse, but I have to be pedantic here just to (hopefully) make it plainer why the expected isn't happening.
If you do a HTTP GET against a URL that's mapped to the FacesServlet, the FacesServlet will dissect the URL and locate the resource necessary to render a JSF view using that resource as a view template. At that point, only set/get methods are being called, basically.
So to execute business logic, you'd have to attach it to one of 3 places:
1. The constructor. Often that doesn't work, since the bean isn't fully initialized yet
2. One of the "set" methods. This can be hazardous, since a given property may be set multiple times on a single request. Also, you can't really depend on all the pre-requisite "set" methods having been called first.
3. A PostConstruct method. In JSF2, you can annotate a method to be invoked after the constructor has been executed and all the "set" methods have been called. However, this is only invoked once, so it works best if the bean is in Request scope.
For what you want, all of these are fairly awkward. A cleaner solution would be to get some outside help:
The ocpsoft PrettyFaces component allows you to easily kit out a JSF webapp to accept "user friendly" URLs such as what you're submitting. It will parse the URL, call setters to inject the parameters into the backing bean, then invoke a method that you specify to process the request. The great thing about it is that not only is it pretty easy to install and configure, but it doesn't require any specialized login in your application code. It's all done POJO-style.
Incidentally, I think RichFaces uses jQuery internally to get a lot of its "oomf". You can also combine PrettyFaces and RichFaces. They play well together, especially now that Red Hat/JBoss has the author of PrettyFaces on the payroll.
An IDE is no substitute for an Intelligent Developer.