• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help - More specific question on JSF + jQuery

 
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

On the other hand, if you're seriously into AJAX, you might want to forgo the manual coding and enlist an extension tagset such as RichFaces. RichFaces makes it easy for JavaScript on JSF pages to invoke JSF functionalities, and can even help with partial page updating. Better yet, in many cases, RichFaces generates all the logic itself, so you can simply declare page elements and it will whip up the required (browser-tuned!) JavaScript code behind the scenes. A lot less work.

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.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After getting some more help from another forum I found out that I had the wrong methods setup in my bean and that I have to get the parameter from the following class in JSF:

FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("parameterName");

I'm moving forward again and appreciate the help from both this forum and the HTML/Javascript forum.

Hopefully I can get this done to get my page completed.

Thanks again.
 
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic