JSF backing bean accessibility from external class

I am using JSF in my application. Consider i am assigning a value of the inputtext field to a string in my managed bean. This bean has the getters and setters for the string.
Now my requirement is to get the value of the string i.e. the string value entered in the input text field in another class file. If "A" is a backing bean, I want a class B to access the values(in this case the inputtext value) from A.
Thanks in Advance.

Below is the code where i am using the inputtext tag in the JSP page
<h:inputText value="#{person.name}" />
"person" is the backing bean which is declared in the faces-config.xml
PersonBean code:*
package jsfExample;
public class PersonBean {
     private String name;
public void setName(String name) {
          this.name = name;
public String getName() {
          return this.name;
Now i have another class in the same package as shown below.
package jsfExample;
public class worker extends PersonBean{
//this function should use the variable name present in the backing bean//
     public void access(){
     PersonBean person= new PersonBean();
     String str=person.getName();
     System.out.println(str);
//I am getting null value in the str variable inside here//
but if i print the variable inside the backing bean(*PersonBean*) it is working fine.

Similar Messages

  • JSF Backing bean / JSP interaction questions

    A few questions about JSF beans and JSP page interactions. Bear in mind that I'm new to both JSP and JSF, so a solution that might be obvious to the rest of the world may be new to me.
    1. Can I pass a parameter to the backing bean method from an "action" attribute:
    <h:commandLink action="#{TableData.SortRec}">
    <h:outputText value="#{msgs.selectedHeader}"/>
    </h:commandLink>
    I'd like to call the same method from several controls, but pass it a parameter to determine which field to sort on.
    2) Is there a way for a backing bean method to determine which control invoked it?
    3) Is there a way to access JSF backing bean methods from JSP tags. I'd like to do some conditional page assembly based on a JSF bean property... JSF doesn't appear to have a conditional like JSP's <c:if>, but I could use JSP's if it could access the JSF bean.

    Could you pl tell me how to pass parameter thru CommandButton
    I have the following situation
    1) greetingList.faces which list the Ids & greeting Text
    Id Text
    1 Hello World
    2 Hello World
    2) Pl note Ids are h:commandLink. A click on the Id will render greetingForm.faces with data pertaining to that Id and with Update h:CommandButton
    3) When i click Update button it results in the following error
    javax.faces.FacesException: Error calling action method of component with id greetingForm:_id4
    Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{greetingForm.update}
    Caused by: java.lang.NullPointerException
    So i verified with h:message that Id is passed as Null when click on Update button. I also checked greetingForm.faces has a not null value by printing <h:outputText value="#{greetingForm.message.id}"/>
    So i guess the Id value is overwriteen with null. Also i have defined Id as property in managed bean
    <managed-bean-name>greetingForm</managed-bean-name>
    <managed-bean-class>com.mycompany.GreetingForm</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
    <property-name>id</property-name>
    <value>#{param.id}</value>
    </managed-property>
    Any pointers/suggestions at the earliest on how to pass the value of Id on a click of update button from greetingForm.faces to greetingForm.java will be highly appreciated
    I am willing to upload my war file
    Regards
    Bansi

  • How to call Backing Bean method from href tag in JSF. -- URGENT

    Hi guys,
    i am new to JSF. i want one option. how to call a backing bean method from href.
    I searched a lot. i found one component <commandLink>, but i cann't use <commandLink> i have to use only href which is client instructions.
    If anyone knows pls help me. Its Urgent. If u can, give me the code also.
    Suggestions will be appreciated.
    Thanks
    Rajesh

    You can make use of the constructor of the backing bean or the @PostConstruct annotation if you want to use managed properties.
    You may get some ideas out of this: [http://balusc.blogspot.com/2006/06/communication-in-jsf.html].

  • How to call backing bean method from java script

    Hi,
    I would like to know how to call backing bean method from java script.
    I am aware of serverListener and [AjaxAutoSuggest article|http://www.oracle.com/technology/products/jdev/tips/mills/AjaxAutoSuggest/AjaxAutoSuggest.html]
    but i am running in to some issues with [AjaxAutoSuggest article|http://www.oracle.com/technology/products/jdev/tips/mills/AjaxAutoSuggest/AjaxAutoSuggest.html]
    regarding which i asked for help in other thread with subject ....Question on AjaxAutoSuggest article (Ajax Transactions Using ADF and J...)
    The reason why i posted is ( though i realise both are duplicates) .. that threads looks as a specific question to that article hence i would like to ask the quantified problem is asked in this thread.
    So could any please letme know how to call backing bean method from java script
    Thanks
    Murali
    Edited by: mchepuri on Oct 24, 2009 6:17 PM
    Edited by: mchepuri on Oct 24, 2009 6:20 PM

    Hello,
    May know how to submit a button autoamtically on onload of page with clicking a welcome alert box. the submit button has managed button too to show a message on console using SOP.
    the problem is.
    1. before loading the page a javascript comes on which i clicked ok
    2. the page gets loaded and the button is there which gets automatically clicked and the managed bean associated with prints a message on console using SOP.
    I m trying to do this through server listener and click listener. the code is(adf jspx page)
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
    <af:document id="d1" binding="#{backingBeanScope.backing_check4.d1}">
    <af:form id="f1" binding="#{backingBeanScope.backing_check4.f1}">
    <af:commandButton text="commandButton 1"
    binding="#{backingBeanScope.backing_check4.cb1}"
    id="cb1" action="#{beanCheck4.submit1}"/>
    <af:clientListener type="click" method="delRow"/>
    <af:serverListener type= "jsServerListener"
    method="#{backingBeanScope.backing_check4.submit1}"/>
    <f:facet name="metaContainer">
    <af:resource type ="javascript">
    x=confirm("hi");
    // if(x){
    delRow = function(event){
    AdfCustomEvent.queue(event.getSource(), "jsServerListener", {}, false);
    return true;
    </af:resource>
    </f:facet>
    </af:form>
    </af:document>
    </f:view>
    <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_check4-->
    </jsp:root>
    the backing bean code is -----
    public class classCheck4 {
    public classCheck4() {
    public String submit1() {
    System.out.println("hello");
    return null;
    }

  • Transferred backed-up data from external hard disk to new hard drive on my MacBook Pro which seemed to be successful. I now find that some (or maybe all) old emails have been resent. Can anyone tell me what has happened?

    Transferred backed-up data from external hard disk to new hard drive on my MacBook Pro which seemed to be successful. I now find that some (or maybe all) old emails have been resent. Can anyone tell me what has happened?

    Greetings,
    I've never seen this issue, and I handle many iPads, of all versions. WiFi issues are generally local to the WiFi router - they are not all of the same quality, range, immunity to interference, etc. You have distance, building construction, and the biggie - interference.
    At home, I use Apple routers, and have no issues with any of my WiFi enabled devices, computers, mobile devices, etc - even the lowly PeeCees. I have locations where I have Juniper Networks, as well as Aruba, and a few Netgears - all of them work as they should.
    The cheaper routers, Linksys, D-Link, Seimens home units, and many other no name devices have caused issues of various kinds, and even connectivity.
    I have no idea what Starbucks uses, but I always have a good connection, and I go there nearly every morning and get some work done, as well as play.
    You could try changing channels, 2.4 to 5 Gigs, changing locations of the router. I have had to do all of these at one time or another over the many years that I have been a Network Engineer.
    Good Luck - Cheers,
    M.

  • Local variable can't be accessed from inner class ???????? Why ??????

    Plesae help, help, help. I have no idea what to do with this bug.........
    <code>
    for ( int i = 0; i <= 2; i++ ) {
    for ( int j = 0; j <= 2; j++ ) {
    grids[i][j] = new MyButton ();
    grids[i][j].setBorder(but);
    getContentPane().add(grids[i][j]);
    MyButton sub = grids[i][j];
    sub.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    if ( sub.getState() == 0 ) {
         sub = new MyButton( (Icon) new ImageIcon(imageFile));
         if ( imageFile.equals("cross.jpg") ) {
              sub.changeState(1);
         else {
              sub.changeState(2);
    </code>
    The compiler complains that "sub" is in the inner class, which is the ActionListener class, must be declared final. Please tell me what to do with it. I want to add an ActionListener to each MyButton Object in the array. Thanks ......

    OK, now I changed my code to this :
    for ( int i = 0; i <= 2; i++ ) {
      for ( int j = 0; j <= 2; j++ ) {
        grids[i][j] = new MyButton ();
        grids[i][j].setBorder(but);
        getContentPane().add(grids[i][j]);
        grids[i][j].addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            if ( grids[i][j].getState() == 0 ) {
               grids[i][j] = new MyButton( (Icon) new ImageIcon(imageFile));
              if ( imageFile.equals("cross.jpg") ) {
               grids[i][j].changeState(1);
              else {
              grids[i][j].changeState(2);
    [/cpde]
    Thanks for your advice !!!!!!
    Now the compiler says that i and j are local variables accessed from inner classes, needs to be declared final. How can I solve this then ???

  • Calling from an EJB into a JSF Backing Bean

    Hello all,
    I'm looking for some help in making calls from an EJB into a Backing Bean (the converse is fairly straightforward). My basic question is: what is regarded as the best way to do this?
    However, for anybody who's interested, I'll describe what I've been trying...
    Here's my situation (I'm working with OC4J 10.1.3.2). I have a simple application-scoped backing bean:
       public class BackingBean implements SimpleInterface, Serializable {
           private String greeting = "Hello, World";
           private SessionEJBRemote blBeanRemote = null;
           public BackingBean() {
               // get hold of EJB
               // [ ... code to obtain EJB's remote interface snipped ... ]
               // set the callback with the EJB       
               try {
                   blBeanRemote.setCallback(this);
               } catch (Exception ex) {
                   ex.printStackTrace();
           // methods to manipulate the greeting string
           public String getGreeting() {
               return greeting;
           public void setGreeting(String greeting) {
               this.greeting = greeting;
       }SimpleInterface, which my Backing Bean implements is, well, a simple interface:
       public interface SimpleInterface {
           public void setGreeting(String greeting);
       }And my EJB is also pretty straightforward:
       @Stateful(name="SessionEJB")
       public class SessionEJBBean implements SessionEJBRemote, SessionEJBLocal {
           private SimpleInterface callback = null;
           public void setCallback(SimpleInterface callback) {
               this.callback = callback;
               callback.setGreeting("Goodbye, World");
       }Now, by using SimpleInterface, my intention was to ensure a one-way dependency: i.e. the JSF-level code would depend on the EJB-level code, but not vice versa.
    However, my experimentation has shown that when I make the call to blBeanRemote.setCallback, the parameter appears to be passed by value rather than by reference. This means firstly that, at runtime, by EJB needs to have access to my backing bean class and secondly, that the call to callback.setGreeting has no effect.
    Can anybody suggest how to work around this? Is it possible to pass the backing bean by reference? Is there a better way to achieve this callback? I appreciate that these questions might be more general Java/AppServer queries rather than JSF-specific ones - but hopefully this is something that all you JSF experts have encountered before.
    (Incidentally, I realise that what I'm doing in this example is pointless - what I'm building towards is using the ICEFaces framework to have the EJBs prod a backing bean which will in turn cause a user's browser to rerender.)
    Many thanks - any help very much appreciated!
    Alistair.

    Hi Raymond - yes, you've pretty much got that spot on: an event occurs (say receipt of a JMS message - which is spontaneous, as far as the users are concerned). As a result of that event, the client's view (in their browser) needs to be re-rendered.
    ICEFaces uses the AJAX technique to allow server-pushes, and rather than refreshing the whole page it uses "Direct-to-DOM" rendering to maninpulate the page components. If you've not come across it, and you're interested, then there are some pretty interesting demos here: http://www.icefaces.org/main/demos/ - the "chat" feature of the Auction Monitor demo (if you open it up in two browsers) is the nearest to the effect I'm looking for.
    The Auction Monitor demo uses a number of session-scoped beans, each implementing the ICEFaces "Renderable" interface, and each of which registers itself with an application-scoped bean. The application-scoped bean can thus iterate through each of the session-scoped beans and cause the corresponding browser to refresh.
    Unfortunately, in the Auction Monitor demo, the entry point is always from a browser - albeit the result is then mirrored across all connected browsers. I haven't found any examples of this processing being driven by an external event, hence my experimentation in this area!

  • Redirect from JSF backing bean to another application

    Hi,
    I need to open another (non-JSF) application in a new window from the backing bean of my JSF application.
    My JSF application is in frames. - heading, menu, content.
    I've a commandlink in the menu frame.
    I tried with
    FacesContext.getCurrentInstance().getExternalContext().redirect(loginUrl);
    This is opening in the menu frame itself.
    I tried using target="new" , but no result.
    I also need to pass the userId to the external application.
    Any ideas?
    ~Thanks.

    Thanks.
    Yes, GET works. I used a <h:outputLink and used target="new" and
    window.open("url?userId=someId")
    But i donot want to pass userid in GET in the url, since that is a sensitive information.
    Please let me know if there's any other way.
    Thanks,

  • Open URL in a new browser from a JSF backing bean

    I want to use commandButton action in jsf to launch a new browser instead of using commandLink.
    How do you launch url in a new browser window by firing up a method in backing bean?
    So far I am able to launch a URL within the same browser window. Here is my code:
    In jsp file:
    <h:commandButton rendered="#{openDataList.valueModifiable}" value="link" action="#{openDataList.link}" />
    In backing bean:
    public void link()
         try{
         FacesContext faces = FacesContext.getCurrentInstance();
         faces.responseComplete();
         ExternalContext context = faces.getExternalContext();
         context.redirect("http://www....");      }
         catch(java.io.IOException e)
    ...

    with a commandButton i dont belive you can
    well there are ways you can use javascript window.open
    or you can use a commanLink ans set the target
    but from my understanding there is no way to open a new browser from the backing beans ( this is because this is a client function and your backing beans are on the sever )

  • How can fill javascript array from list in jsf backing bean

    Hello
    i have an array in javascript and i want to fill in from the list which is coming from the backing bean how can i do that.
    Regards

    Hi,
    using the ExtendedRenderkitService class you can send JavaScript calls from a managed bean to the client. So in your case you call a client side javaScript method and pass the array information as an argument. The way you pass the array data is up to you. You may just pass a character delimited list, or use JSON object notation in case the list shows objects. Note that this is for JDeveloper 11.In 10.1.3 there is no server side JavaScript API. Here you would have to add the JavaScript to the page when rendering it.
    Frank

  • How-to remove a jsf backing bean from session?

    How can I find the reference to a backing bean (with session scope) and then remove the bean?
    I may have painted myself into a corner. When most of my pages are navigated to, they get key info from session and then initially populate the page fields. I populate the fields in the constructor with values from the database based on the keys found in session. So the second time a particular page is called the values may be stale or completely unrelated to the page navigated from because the bean already exists and, naturally, the constructor is never called.
    I'm thinking if I could remove the backing bean, jsf wouldn't find it so it would be recreated on subsequent navigations. Since the constructor would be called with every navigation to the page, the values would not be stale or unrelated.
    Any help would be greatly appreciated.
    TIA,
    Al Malin

    //To reset session bean
    FacesContext
         .getCurrentInstance()
         .getApplication()
         .createValueBinding( "#{yourBeanName}").setValue(FacesContext.getCurrentInstance(), null );
    //To get session bean reference
    Object obj = FacesContext
              .getCurrentInstance()
              .getApplication()
              .createValueBinding("#{yourBeanName}")
              .getValue(FacesContext.getCurrentInstance());
    YourSessionBean bean = (YourSessionBean)obj;

  • Calling a backend bean method from another class

    Hi,
    I'm new in JSF & in this forum so maybe this question is already aswer.
    My problem is that I made a jsf component to deal with a tree menu. The resources in the leaf nodes of the menu are stored in a action calling pattern (i.e.: #{myBean.myMethod}) & I'm looking for a way to bind & execute the call from the class of the component that treats the events.
    I suppose that I need to get the current instance of the context, get the bean location, instance it & invoke the method, but I don�t know how.
    I have another more question, may this resource invocation have any kind of undesirable side effect, I meen, it's me & not the faces context who is making the call so I'm not sure if that the best way to solve the problem.
    Thanks in advance.

    If I understand what you're saying correctly... you have a component which enables a user to select an action (leaf nodes in the menu). You are processing this selection in your component and now have a EL expression that looks like #{myBean.myMethod}. You now need to know how to use that expression from Java code to invoke it. Is that correct?
    If so:
    FacesContext ctx = FacesContext.getCurrentInstance();
    MethodBinding mb = ctx.getApplication().createMethodBinding("#{myBean.myMethod}", new Class[] {});
    mb.invoke(ctx, null);
    This should do what you want. If you need to pass arguments to the method, you can do that as well... you need to pass in the types via the Class[], and the objects via an Object[] instead of null.
    Note also that the API's for EL change for JSF 1.2 to the standard EL API's, however, the older API's (above) are still supported.
    Ken Paulsen
    https://jsftemplating.dev.java.net

  • Best practice for initializing objects in a JSF backing bean?

    Hi,
    What is the best practice for initializing some objects in the JSF to-page backing bean before the to-page is displayed for the first time? The initialization would vary and depend upon a command link in the from-page.
    Regards,
    Al Malin

    f:view has two new attributes in 1.2: beforePhase and afterPhase
    which allows you to specify a phase listener method
    which will be called before and after the view is processed.

  • Getting (incrementally) backed up files from external HD to new mac

    Hi everyone,
    The hard drive on my ibook died. I was running Tiger, and regularly backed up all the files on my home folder to an external hard drive. I use the software that came with the computer (Backup) to do this.
    Yesterday, I purchased a MacBook. When I attach my external hard drive and try to open my backed up files, all I see is one full backup folder and many, many incremental backups. I understand, on a conceptual level, what incremental backups are. But I have no idea how to use them to retrieve my files.
    So, my question is this: how do I retrieve files that were backed up to an external hard drive (from my old computer) and transfer them to the internal HD on my new computer? Migration assistant is absolutely no help here since I can't access the internal HD on my old, dead ibook.
    Many thanks for any tips,
    RB

    If you used Backup to create the backup, then use it to restore the files.

  • WebSphere Custering and JSF Backing Beans

    Hello All,
    Can anyone enlighten me on exactly how backing bean state is maintained by JSF?
    In what scope does JSF store the backing beans? (session perhaps)
    Does it make sense to use JSF without stateful backing beans?
    What would happen if a client post did not find its corresponding backing bean on the application server calling it?
    Background:
    In a clustered WebSphere Server environment, a client post may be directed to any one of the machines in the cluster. If the client post gets directed to a machine other then the machine that originally sent the client a response, the page will not find the corresponding page beans.
    It is possible to serialize session beans in WebSphere and have each machine share its memory with all the boxes in the cluster. However, this practice is not permitted in some environments.
    Any thoughts? Thanks in advance.

    I am probably not an expert on the subject. But here are some thoughts:
    1. A backing bean can have (application, session, request or None) as a scope.
    Less app or session scope beans the better (from server perspective). But
    There are practical reasons why you would want to use them in many cases.
    2. JSF supports Client State Saving mode. But keep in mind the overhead
    Involved (serialization, de-serialization, bandwidth,...).
    3. You probably need to read about WebSphere load balancing capability. From
    what I know it is somehow sophisticated. People typically use session affinity
    to force requests initiated by same session to be served by the same app
    server (enforced by network, hardware/software tools available to do so,...). Of
    course with failover mechanism to ensure high availability.
    Hope that helps!

Maybe you are looking for