How to get properties of a bean from another java class

Hi,
I am new to JSF. Currently I am facing a problem, and hope you experts can give me some guidance.
The JSF app i am working on has one Java class for handling a tree structure, MyTreeNode.java, and it also has a bean, NameBean.java, which has two properties, username and password.
I can easily associate an input text with the #{name.username} to store the user's login... but later on, I need to fetch that information inside of MyTreeNode.java. How do I do that? Thanks!
-- Jim

<managed-bean>
     <managed-bean-name>Person</managed-bean-name>
     <managed-bean-class>demo.PersonBean</managed-bean-class>
     <managed-bean-scope>session</managed-bean-scope>
     <managed-property>
          <property-name>bank</property-name>
          <property-class>demo.BankBean</property-class>
          <value>#{bank}</value>
     </managed-property>
<managed-bean>
<managed-bean>
     <managed-bean-name>bank</managed-bean-name>
     <managed-bean-class>demo.BankBean</managed-bean-class>
     <managed-bean-scope>session</managed-bean-scope>
<managed-bean>this version doesnt work for me.
does the single beans have to look any special?
some demo code out there?
thx!

Similar Messages

  • How to call a Java class from another java class ??

    Hi ..... can somebody plz tell me
    How to call a Java Class from another Java Class assuming both in the same Package??
    I want to call the entire Java Class  (not any specific method only........I want all the functionalities of that class)
    Please provide me some slotuions!!
    Waiting for some fast replies!!
    Regards
    Smita Mohanty

    Hi Smita,
    you just need to create an object of that class,thats it. Then you will be able to execute each and every method.
    e.g.
    you have developed A.java and B.java, both are in same package.
    in implementaion of B.java
    class B
                A obj = new A();
                 //to access A's methods
                 A.method();
                // to access A's variable
                //either
               A.variable= value.
               //or
               A.setvariable() or A.getvariable()

  • Call Bean from normal java class

    Dear Friends,
    Is it ok to call an entity bean or session bean frm normal Java class.
    (Java class is in the same application as the beans).
    Is there a special way to lookup the beans from normal java classes.
    Thanking You,
    Chamal.

    it is ok and very commonly done.
    Note that the simple java program must be running in the same local network. You cannot have the java program and EJBs distributed over internet. (I m not certain of it, but mostly I shoudl be correct. If you have the resources, try it out and let me know)
    In most of the cases, EJBs are called by
    1. A servlet
    2. Another EJB
    3. a simple java program.
    In the first 2 cases, you can go for Local Interfaces (more so in the second case than the first). The reason being that the the client and server will be in the same JVM (typically the Application server). Thus, in the first case, if the Web container and the ejb container are in the same app server, EJBs can be local.
    However, in the third case, it is unlikey that you will have the client runnng and the same jvm as the server, because the app server has its own jvm.
    sample code (this method is being called from the main method of a simple java program. it is self explanatory):
    public  void processRequestForSessionBean()
             System.out.println("REQUEST RECEIVED");
             try
                   Hashtable nameHashtable = new Hashtable();
                   nameHashtable.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
                   nameHashtable.put( Context.PROVIDER_URL, "t3://localhost:7001" );
                   InitialContext context = new InitialContext(nameHashtable);
                   System.out.println("created initial context");
                   Object lookupObject = context.lookup("CustomerBean");
                   System.out.println("Got the lookup object");
                   CustomerDataHome home = (CustomerDataHome) PortableRemoteObject.narrow(lookupObject,
                             Class.forName("com.shiv.business.CustomerDataHome"));
                   System.out.println("Home interface");
                   customerData = home.create();
                   System.out.println("Remote Interface");
                   addDataToSB(customerData);
                   ArrayList namesList = customerData.getNames();
                   System.out.println(namesList.toString());
                   //customerData.remove();             
              catch (Exception exception)
                   System.out.println("FATAL ERRORS");
                   exception.printStackTrace();
              }

  • How to interact with a COM component from a Java class

    Hi, could someone give a hint on what API I should explore in order to interact with a COM component from a Java class?
    Thanks in advance
    Luis

    jacob sounds nice...http://danadler.com/jacob/

  • How to get value in backing bean from application module

    Hi all.. I'm new in jdeveloper and adf..
    I need to use value from backing bean and use that value in application module.
    But I don't know how to get it.
    Do you a have any solution?

    suppose you have myMethod(String argumentName1,String argumentName2) in your Application Module
    then to access a method binding from a managed bean, use the following code,
      BindingContext bctx = BindingContext.getCurrent();
      BindingContainer bindings = bctx.getCurrentBindingsEntry();
      OperationBinding operationBinding =
           bindings.getOperationBinding("name_of_method_binding");
      //Here you can pass the parameters value to the AM method
      operationBinding.getParamsMap().put("argumentName1",value1);
      operationBinding.getParamsMap().put("argumentName2",value2);
      //invoke method
      operationBinding.execute();
      if (!operationBinding.getErrors().isEmpty()) {
         //check errors
         List errors = operationBinding.getErrors();
      //optional
      Object methodReturnValue = operationBinding.getResult();

  • How to get the Weblogic Server Id from within java code

    I would like to log which server (among a cluster) a certain job is running on. Is there a way to get the server id from within Java code (this code is in a session bean if that is relevant.)
    By server id I mean the "Name" column in the summary of servers on the weblogic console.
    Thanks,
    ken

    Use the two entries close to the bottom of the page: "list WebLogic
    MBeans:listMBeans.jsp
    display MBean attributes and operations:showMBean.jsp"
    Nils
    Anatoly wrote:
    >
    Cameron,
    That page has these items on it:
    which one do you think helps with my issue?
    Misc WebLogic examples
    LongRunningTask
    Execute tasks in parallel using WebLogic Execute Threads
    Weblogic stats (5.1)
    Reload Servlet(s) programmatically (5.1)
    Network classload from WebLogic:using reflection,or the launcher
    Weblogic 5.1 debugging properties
    Seppuku pattern readme
    Using dynamic proxies to intercept EJB invocations (6.1)
    list WebLogic MBeans:listMBeans.jsp
    display MBean attributes and operations:showMBean
    Thanks to Marcelo Caldas for filter by type option and nice UI!
    Using com.sun.jdmk.comm.HtmlAdaptorServer with WebLogic 6.1
    Cool
    EJBGen
    Dimitri
    back
    "Cameron Purdy" <[email protected]> wrote in message news:<3c7a745d$[email protected]>...
    JMX ... see http://dima.dhs.org/misc/ for some info on JMX in Weblogic.
    Peace,
    Cameron Purdy
    Tangosol, Inc.
    Clustering Weblogic? You're either using Coherence, or you should be!
    Download a Tangosol Coherence eval today at http://www.tangosol.com/
    "Anatoly" <[email protected]> wrote in message
    news:[email protected]..
    Does anyone know who to get the managing server URL's port
    from within the EJB code running on Weblogic 6.1?
    The URL port is not default (not 7001), but when creating
    initial context, I am not specifying the URL in properties.
    Due to that, trying to the the PROVIDER_URL property from
    environment does not return anything.
    Appreciate any responses.
    -Anatoly
    ============================
    [email protected]

  • How to get change a GUI component from another class?

    Hi there,
    I'm currently trying to change a GUI component in my 'Application' class from my 'Dice' class.
    So the Application class sets up some GUI including a JLabel that initially displays "Change".
    The 'Dice' class contains the ActionPerformed() method for when the 'Change' button (made from Application class) is clicked.
    And it returns an 'int' between 1 and 6.
    Now I want to set this number back int he JLabel from the Application class.
    APPLICATION CLASS
    import javax.swing.*;
    import java.awt.*;
    import java.util.Random;
    import java.awt.event.*;
    public class Application extends JFrame implements ActionListener{
         public JPanel rollDicePanel = new JPanel();
         public JLabel dice = new JLabel("Loser");
         public Container contentPane = getContentPane();
         public JButton button = new JButton("Change");
         public Dice diceClass = new Dice();
         public Application() {}
         public static void main(String[] args)
              Application application = new Application();
              application.addGUIComponents();
         public void addGUIComponents()
              contentPane.setLayout(new BorderLayout());
              rollDicePanel.add(dice);
            button.addActionListener(diceClass);
            contentPane.add(rollDicePanel, BorderLayout.SOUTH);
            contentPane.add(button,BorderLayout.NORTH);
              this.setSize(460, 655);
              this.setVisible(true);
              this.setResizable(false);
         public void changeDice()
              dice.setText("Hello");
         public void actionPerformed(ActionEvent e) {}
    }DICE
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class Dice implements ActionListener
         public Dice() {}
         public void actionPerformed(ActionEvent e)
              //super.actionPerformed(e);
              String event = e.getActionCommand();
              if(event.equals("Change"))
                   System.out.println("Will be about to change the 'dice' label");
                   Application application = new Application();
                   application.dice.setText("Hello");
    }

    It's all about references, baby. The Dice object needs a way to communicate with the Application object, and so Dice needs a reference to Application. There are many ways to pass this. In my example I pass the application object directly to Dice, but a better way would use interfaces and some indirection. Look up the Observer pattern for a better way to do this that scales much better than my brute-force approach.
    import javax.swing.*;
    import java.awt.*;
    public class Application extends JFrame // *** implements ActionListener
        // *** make all of these fields private ***
        private JPanel rollDicePanel = new JPanel();
        private JLabel dice = new JLabel("Loser");
        private Container contentPane = getContentPane();
        private JButton button = new JButton("Change");
        // *** pass a reference to your application ("this")
        // *** to your Dice object:
        private Dice diceClass = new Dice(this);
        public Application()
        public static void main(String[] args)
            Application application = new Application();
            application.addGUIComponents();
        public void addGUIComponents()
            contentPane.setLayout(new BorderLayout());
            rollDicePanel.add(dice);
            button.addActionListener(diceClass);
            contentPane.add(rollDicePanel, BorderLayout.SOUTH);
            contentPane.add(button, BorderLayout.NORTH);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setPreferredSize(new Dimension(460, 655));
            pack();
            setLocationRelativeTo(null);
            setVisible(true);
            setResizable(false);
        // *** I'm not sure what this is supposed to be doing, so I commented it out.
        //public void changeDice()
            //dice.setText("Hello");
        // *** ditto.  I strongly dislike making a GUI class implement ActionListeenr
        //public void actionPerformed(ActionEvent e)
        // *** here's the public method that the Dice object calls
        public void setTextDiceLabel(String text)
            dice.setText(text);
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class Dice implements ActionListener
        // *** have a variable that holds a reference to your application object
        private Application application;
        private boolean hello = true;
        public Dice(Application application)
            // *** get that reference via a constructor parameter (one way to do this)
            this.application = application;
        public void actionPerformed(ActionEvent e)
            String event = e.getActionCommand();
            if (event.equals("Change"))
                System.out.println("Will be about to change the 'dice' label");
                if (hello)
                    // *** call the application's public method
                    application.setTextDiceLabel("Hello");
                else
                    application.setTextDiceLabel("Goodbye");
                hello = !hello;
                //Application application = new Application();
                //application.dice.setText("Hello");
    }

  • How to call a PL/SQL procedure from a Java class?

    Hi,
    I am new to the E-BusinessSuite and I want to develop a Portal with Java Portlets which display and write data from some E-Business databases (e.g. Customer Relationship Management or Human Resource). These data have been defined in the TCA (Trading Community Architecture) data model. I can access this data with PL/SQL API's. The next problem is how to get the data in the Java class. So, how do you call a PL/SQL procedure from a Java program?
    Can anyone let me know how to solve that problem?
    Thanks in advance,
    Chang Si Chou

    Have a look at this example:
    final ApplicationModule am = panelBinding.getApplicationModule();
    try
         final CallableStatement stmt = ((DBTransaction)am.getTransaction()).
                                                                                         createCallableStatement("{? = call some_pck.some_function(?, ?)}", 10);
         stmt.registerOutParameter(1, OracleTypes.VARCHAR);
         stmt.setInt(2, ((oracle.jbo.domain.Number)key.getAttribute(0)).intValue());
         stmt.setString(3, "Test");
         stmt.execute();
         stmt.close();
         return stmt.getString(1);
    catch (Exception ex)
         panelBinding.reportException(ex);
         return null;
    }Hope This Helps

  • How to get the status of Javascript inside a java class

    Hi,
    Can anybody let me know the way by which I can get the status of Javascript (enabled/disabled) in browser inside a Java Class.
    I do have a trick -
    <input type="hidden" name="jstatus" value="disabled">
    <input type="submit" name="submit" onClick="doChecking()">
    <script language= javascript>
    function doChecking()
    document.form.jstatus.value = "enabled";
    submit();
    Now inside our java class we can check the value of "jstatus" if it is disabled then it is disabled else it is enabled.
    Ha ha wat a stupid trick...... ;-)
    Plz let me know a real approach to determine the Javascript status.
    Cheers !!!
    Irshad

    Actually, I don't think that trick is stupid at all. Javascript and Java are normally in no way related (javascript is just plain text content to your servlets / jsp's). So a good way of getting such information to your server is submitting it, like you do.
    Another possibility would be to do it with Ajax in the background, but that all depends on what you do with the information.

  • How to use PropertyChangeSupport for a bean from another bean

    Hi all,
    I have a bean A that doesnot implements the PropertyChangeListener or have a PropertyChangeSupport as one of its member and I cant change its design. I want to fire an PropertyChangeEvent when a property is changed. I added A to PropertyChangeSupport of another bean B. The problem is that even if the Property of Bean A is changed it doesnot fire a event. Can anybody let me know how to do it?
    Thanks,
    Amit

    You need to wrap bean A inside another bean (B) that
    implements the accessor and mutator methods of Bean A
    and adds property change support in those methods
    where appropriate. You hide the actual instance of
    bean A inside an instance of bean B so no instances of
    bean A are visible to the application.This is OK, unless you don't want to change all places where A is referenced. You could subclass B from A, as long as the accessor and mutator methods are not final. Of course, instantation still has to know about B and you will have to cast to B, or use reflection, to add and remove the listeners.

  • How choose between post and get when calling a servlet from a java class ??

    Hi !!
    I have an urgent question : in fact some java programs that call servlets are published on the web, and the principle is to make an url.openconnection() to reach the servlet.
    What I don't understand is how we choose if we want to call the get or the post method on the servlet ?????
    please answer very fast.....
    thanks...

    from the URL documentation of openConnection():
    "If for the URL's protocol (such as HTTP or JAR), there exists a public, specialized URLConnection subclass belonging to one of the following packages or one of their subpackages: java.lang, java.io, java.util, java.net, the connection returned will be of that subclass. For example, for HTTP an HttpURLConnection will be returned, and for JAR a JarURLConnection will be returned."
    Obviously, in case of a http servlet, normally an instance of HttpURLConnection will be returned. If you don't change the request method, GET is the default.

  • How to get the current process Id from a java program

    Can we fetch the process id froma a program as we do it in c++ as getCurrentProcessId()

    why not to launch a process like ("rundll.exe _params_") and get its output data
    sorry, i'm not in WinAPI to continue with params, but you should know i think or consult somebody.
    or there is special java package, which can call windows functions. you can find it in Microsoft Java SDK.

  • How to get JSP to include content from another WAR

    I'm writing a group of web applications that are all going to be run out of the same web server with the same domain name. Since these applications are all independent, I want to give them separate wars.
    I've created a directory application that lets the user create an account, log in, and pull up a listing of each of the other applications on the server. However, rather than just posting a hyperlink to each of the other apps, I'd like to call a custom .jspf in the respective wars so that they can return a block of HTML that gives a richer user experience (the HTML will contain some formatted text that describes the link, given the user ID and a couple of other parameters).
    Anyhow, jsp:include seems to have me sandboxed inside my directory app. <jsp:include page="../MyOtherApp/link.jspf"/> causes an error. Is there someway I can have my directory call custom pages in my other wars and include the results in the generated webpage?

    use <%@include file="../MyOtherApp/link.jspf" %>

  • How to start a independant Daemon program from another java daemon?

    Hello,
    I made two java daemon program Daemon_A and Daemon_B. By definition these two program work whithout any user interaction but most of it they should never fall down.
    So in order to be sure that the both daemon are up (and to prevent any failure) I create a mechanism to check each other and if one is down it will be restart by the other one.
    Up to now I succeed to restart the one who fall down. But ... there is always a but ...
    At start:
    - 1) Daemon_A and Daemon_B start.
    - 2) Daemon_B fall down.
    - 3) Daemon_A restart Daemon_B using this:
       String[] commandArray = new String[3];
       commandArray[0] = "../bin/java";
       commandArray[1] = "-jar";
       commandArray[2] = "Daemon_B.jar";
       Process oProcess = runtime.exec ( commandArray, (String[]) null);- 4) Daemon_A and Daemon_B are UP again.
    - 5) Daemon_A crash then Daemon_B is kill too.
    So once the Daemon_B is restarted it seems that there is still a link between Daemon_A and Daemon_B.
    As I use a command system to restart the daemon I don't understand why my Daemon_B is dependant from the Daemon_A.
    Is there another way of doing this?
    How can I restart my Daemon_B (from the Daemon_A) in a independant process?
    As i'm running out of idea any help will be apreciate,
    thanks
    Emmanuel

    Because you do not need javaw on Unix. You can achieve
    what you want in the normal Unix way. Confer: nohup,
    &, stderr and stdout redircetion.That's not correct, I can not achieve what I want on Unix.
    Well with the above piece of code if I use javaw for launching my command through a system command (runtime.exec) on windows it will start a 100% independant process which is find.
    But under unix if I keep using simply java the process will stay a child process. Which mean if the "father daemon_A" die daemon_B will die too.
    So that's why I woudering if there is a similar program as javaw on unix to avoid create chid process using 'runtime.exec'.
    You mentioned crontab: it does not make an item to act
    as a deamon, it rather periodically runs it. Yhea you right my mistake I don't use the crontab to launch the program. I use "etc/init.d" (for sun solaris) and service for windows. Otherwise the daemons are "real" daemon: one's they are started they keep listening and should never fall. But to get a hight level of security I want to be sure if one fall it will be restarted whithout beeing a child process of the other one.
    so any idea on unix of how can I re-start a daemon in a independant way?
    regards,
    emmanuel

  • How to pass a "object" as a prameter from one java class to another java

    hi experts, I want to know "How to pass and get object as a parameter from one java class to another java class". I tried follwoing code just check it and give suggetions..
    import Budget.src.qrybean;
    public class ConfirmBillPDF extends HttpServlet
    qrybean db = new qrybean();
    SimplePDFTable pdfTable = new SimplePDFTable();
    pdfTable.simplePDFTableShow("2010","2011","1","2","1","131","102");
    }Here i want to pass db with simplePDFTableShow method. simplePDFTableShow is in another java class. So how can i do this.
    And also i want to know, how this obj will get.
    please help me.
    Edited by: andy_surya on Jul 14, 2010 7:51 AM

    Hi andy_surya
    what is this i am not understand
    pdfTable.simplePDFTableShow("2010","2011","1","2","1","131","102");but i am try to solve your problem try this
    qrybean db = new qrybean();
    SimplePDFTable pdfTable = new SimplePDFTable();
    pdfTable.simplePDFTableShow(db);and access like this in SimplePDFtable class update your method
    simplePDFTable(qrybean tempDB)
    // write your code
    }

Maybe you are looking for

  • How to add a new Element to the Context

    Hello all. I created in the wdInit() ArrayList datas = new ArrayList();      for (int i = 0; i < 25; i++) {           MyData data = new MyData();           data.setMethods();           datas.add(data);      wdContext.nodeMyData().bind(datas); Now, I

  • My app will no longer run under Snow Leopard, runs fine under Lion.

    My app will no longer run under Snow Leopard, even though it was originally written for Snow Leopard.  It runs fine on my Dev machine under Lion. But when I test it on my Snow Leopard Mac Mini the app starts but the window does not appear. Going to f

  • Use of bpelx built-in methods like getVariableData in custom java classes

    Hi, how can I use bpelx built-in methods like getVariableData ... inside custom java classes embedded with BPEL project? I have large java code to embed with BPEL process and it will be very useful .... It is possible to access these methods like sta

  • Why do I have to type alle accountnames and passwords again in ff 29.

    I have to reenter my acount name and password the first time access a site after (being forced to) upgrading to ff29. Why is that? I have scores of sites I access and this is a pain in the ass! I used the remember function just to avoid remembering a

  • [Zen Micro] [Firmware] Wish to improve the ergonom

    Hi. I bought a Zen Micro, and in my opinion it sounds great...except its ergonomics, which could be easily improved. Touchpad is pleasant to browse in the menus fastly, but it's often hard to select just the next or previous item : why couldn't we us