• 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

Can we call Bean methods in javascript?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to java and jsf. previously used to work in .net 3.5. I am trying to figure out how can i invoke a bean method from javascript. Here is the problem.

I have a richfaces tabPanel on a jsf page having a switchType="ajax". There are several tabs in this tab panel. What i want to accomplish is that when a tab is clicked or enetered the backing bean initialization method is invoked. The problem is whenever a tab is clicked all methods for different tabs are invoked and data is fetched for all tabs. So i thought i would use a javascript function to be called on "ontabenter" method which will in turn call the relevant backing bean method but i dun know if its the right approach and if it is how to do it (dun know the syntax). i am complete blank.

Here is my code:




With the above code all the methods are invoked every time page loads or a tab is clicked\enetered. Hope i made my problem clear. Waiting for help
 
Saloon Keeper
Posts: 27763
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
OK, first thing, and this applies to ALL J2EE, not just JSF: When you have a Model/View/Controller architecture, you shouldn't be putting code in the View template. Doing so violates the Separation of Concerns aspect, and in more practical terms it makes the application a lot more expensive (and less fun) to support.

Aside from that, the whole "JSP" concept went out the window in JSF2, so all those JSP elements and scriptlets lose support entirely. Scriptlets will get you yelled at even in our JSP forum, anyway. They were a hack until better things came along.

JavaScript runs on the Client. The backing beans are on the server. To make the twain meet, you need AJAX. You could roll your own AJAX from raw JavaScript, but if you value your sanity, I recommend using an AJAX support library such as jQuery. Many of the JSF extension frameworks use jQuery internally, as a matter of fact.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic