Subscribe via Feed
, Jul 4, 2010 11:46:10 PM
9 responses to Writing a Managed Bean to Automate Server Side Functionality in XPages
vayasin, October 4, 2010 8:57 PM
i have a library of custom java classes in my WebContent, working together nicely with my xpages. :)
but now i want to use these same classes inside my java agents and webservice providers.
im still unable to refference my namespace from the databases WebContent.
is this even possible? it seems java agents run in an isolated enviroment.
tye, July 20, 2010 6:03 AM
good,do you have any xpages data,please shared it,thank you
mort, July 8, 2010 2:13 AM
Thanks for that Jeremy :-) Thats given me a few things to try. I'll post back here if I discover a good way to get it working
Jeremy Hodge, July 7, 2010 12:57 PM
@mort - I have actually been doing some work with web services and managed beans lately ... There are a couple of issues you could be running into .. one is the java policy ... depending on the classes used, and what is(n't) allowed to do, you may have issues. Take a look at that file, temporarily grant wide-open permissions and see if it works, and if it does, you know you have a policy issue.
If it doesn't, I have had problems with other classes that will fail to load for whatever reasons (dependencies, version issues, security policy, etc) ... In my case I ended up building my own transport class to handle the communication between the webservice and my objects ... it was a name-value pair webservice, and not soap, which made it easier.
@Demha - The bean is accessed via the name you give it in the faces-config.xml file, in the <managed-bean-name> parameter. Then in EL, or SSJS, you can access it directly via that name. To access it in other code (like other managed beans) you have to do a little bit more to get to it. I'll post more on that soon, or you can read Karsten's blog (linked in the article) and he shows you how.
As for the instance per user, that depends on what you specify in the faces-config.xml for <managed-bean-scope>, if you specify request or session, it is one instance per user, however, if you specify application, there is one instance for the entire application. it is not store in the sessionScope or applicationScope however, those are seperate object, pretty much on an equal level as your managed bean.
I'll have more posted soon that will delve deeper in to real world uses and how to utilize this, along with some other added functionality I have not yet covered.
Demha, July 7, 2010 10:38 AM
How can I access this bean from the serverside?
I will have one instance of HellowWorld per user, this instance is stored in the sessionScope?
I'm working in a PureMVC implementation for Xpage, and I'm looking for the best way to make reusable component.
mort, July 7, 2010 3:12 AM
I have a web service on another service that returns a 'cost to date' figure from an SQL table. The input parameter is a job number. I've added a web service consumer to my Xpage database and this works fine when calling from an agent. I was thinking it would be great if I could make calls to the webservice in this back-end java bean. I followed your instructions to create the bean then I tried referencing the consumer classes so I could make calls to the web service. But the consumer classes are not visible to the bean. Do you have any suggestions as to how I could consume a web service in the bean? Is this approach a bad idea? I have also been struggling to work out how to consume a web services using clientside Dojo but no luck so far.
Jeremy Hodge, July 6, 2010 11:03 AM
@Nick ... Yes, I see SSJS libraries under a managed bean implementation at least having much less significance, however, its "the best tool for the job" ... so depending on the need/code re-usability, etc, I don't know if they are are redundant.
Nick Wall, July 6, 2010 7:28 AM
Great article. A few days ago I found a couple of similar articles over at www.mindoo.com
Just starting quite an XPage app and this is all really useful as I am trying to implement proper MVC.
A random thought came into my head: if we can set up our Model and Controller packages in the beans, these can be accessed from pretty much anywhere through EL or SSJS (think am right on this point), does it make SSJS libraries redundant? I have not played with accessing the UIComponent (the article above), but if you can also access the Ui then all I need is a Client side JS Controller and my beans?
Look forward to any other articles you do on this.
Eric Mack, July 5, 2010 1:38 AM
Had to smile, wondering what my wife would guess the article would be about from subject alone...