Use Bean in another one

Hi everyone,
i have a jsp-file where i instantiate a bean
with <jsp:usebean ...
Now i want to use this object in anoter bean.
How is this possible without creating a new
object of the bean?
Thanks in advance
Schoki

<jsp:useBean id="myBean" scope="session" class="beans.MyBean" />
Put that in every page that will use this istance of MyBean. The first time it's executed, it will create a new instance of MyBean and put it in the session. The next time, "myBean" is assigned as a reference to the bean object that is already in the session.

Similar Messages

  • How do you use one managed session bean from another?

    Hello -
    I am a complete newbie to JSF coming from Struts 1. My question is how do you use one managed bean from the method of another one? I think this would be a common senario. For example I put a bean in session scope when a user logs in and in a different method within a different bean I want to get some of this user's information. What is the correct way to retireve one bean from a method in another with session scope?
    Also what would the code look like to retieve another bean from the method of a managed bean where the bean you want to retrieve has application scope?
    Thank you in advance.

    Sinplicity wrote:
    Could you be a bit more specific? If a bean is configured in the faces config file then all of it's properties are managed, correct?Not necessarily.
    What would the code look like to retireve the bean?You don't retrieve it, it has been injected.
    Can I retrieve the whole bean or just a property of the bean. I would be really interested in seeing how this is done in code? And would really love a bit more information on what it means to be a managed property?Time to consult a JSF tutorial.

  • Use bean to pass  dynamic parameter from one jspto another

    Hi Everyone
    I am trying to use a bean to pass parameter instead of passing param through querystring . This is the situation:
    in jsp1 I query a table and get the result listed, when I click every row of the record , I want some special parameters passed to jsp2 through bean, I found I can't get these param in jsp2 simply using getProperty method, It seems I must use form in jsp1 to activate jsp2 which use bean to pass param, Can I do it using linking archor? Because I don't want my params to list in the URL whem activate jsp2, I do not want to use the following format:
    <a href="ViewQueryDetail.jsp?string_num=<%=string_num %>&depart=<%=depart %>&l_time=<%=l_time %>&title=<%=encode_title %>  target="_top"><%=title%>
    If anybody had done this, kindly guide me.
    Thanks in advance.
    xufang</a>

    Thanks for your kindly reply, I followed your direction and now I get java.lang.NullPointerException when I link to jsp2. My code is here:
    jsp1:
    <%
    prjxnxx.db.BnParamDtxx MyBean = new prjxnxx.db.BnParamDtxx();
    prjxnxx.db.BnParamDtxx MyBean1 = new prjxnxx.db.BnParamDtxx();
    while(bean.next()) { %>
    <tr>
    <%!
    int conflag ;
    String depart ;
    String l_time;
    int dtnum ;
    String title ;
    String encode_title;
    String content ;
    //Object object_content ;
    %>
    <%
    conflag = bean.getDataInt("conflag");
    depart =bean.getDataString("depart");
    l_time =bean.getDataString("l_time");
    dtnum = bean.getDataInt("dtnum");
    //String string_num =String.valueOf(dtnum);
    title = bean.getDataString("title");
    //request.setAttribute("title",title);
    //request.setAttribute("depart",depart);
    //request.setAttribute("l_time",l_time);
    //request.setAttribute("dtnum",string_num);
    %>
    <%
    //if(request.getAttribute("MB")==null){
    MyBean.setDepart(depart);
    MyBean.setTitle(title);
    MyBean.setL_time(l_time);
    MyBean.setDtnum(dtnum);
    request.setAttribute("MB", MyBean);
    MyBean1 = (prjxnxx.db.BnParamDtxx)request.getAttribute("MB");
    depart = MyBean1.getDepart();
    title = MyBean1.getTitle();
    l_time = MyBean1.getL_time();
    dtnum = MyBean1.getDtnum();
    System.out.println(depart);
    System.out.println(title);
    jsp2:
    <%!
    String content ;
    int conflag ;
    String depart ;
    String l_time;
    int dtnum ;
    String title ;
    String query;
    %>
    <%
    prjxnxx.db.BnParamDtxx MyBean2 = new prjxnxx.db.BnParamDtxx();
    MyBean2 = (prjxnxx.db.BnParamDtxx)request.getAttribute("MB");
    depart = MyBean2.getDepart();
    title = MyBean2.getTitle();
    l_time = MyBean2.getL_time();
    dtnum = MyBean2.getDtnum();
    %>
    Everything is ok until I run the code
    MyBean2 = (prjxnxx.db.BnParamDtxx)request.getAttribute("MB");
    depart = MyBean2.getDepart();
    Can you explain why I can use getAttribute in jsp1 right yet not in jsp2?
    What is the difference between request.getAttribute and pagecontext.getRequest().getAttribute ?
    I am alway grateful for there are someone like you who can help person when they are in need!
    xufang

  • How to use a session bean in another session bean (or an EJB in a session)

    JDev 11.1.1.4, WLS 10.3.4, Windows 7 x64
    I have a login controller with a session-scoped bean that manages logins.
    I have another session-scoped bean that manages menu security.
    both modules compile and work fine now I need to share the data from one to another.
    I need to reference the login controller in the menu security bean. How do I reference (include) the login bean in the security bean?
    I tried an EJB - what a farce - these are supposed to be universal and easy ( basis of the oop in Java).
    the bean is defined:
    @Stateless(name = "SecurityEJB", mappedName = "ZITASApplication-ZITASModel-SecurityEJB")
    I have tried :
    ic = new InitialContext();
    session = (SecurityEJBLocal)ic.lookup("ZITASApplication-ZITASModel-SecurityEJB#model.security.logic.SecurityEJB");
    session = (SecurityEJBLocal)ic.lookup("ZITASApplication-ZITASModel-SecurityEJB#model.security.logic.SecurityEJBLocal");
    session = (SecurityEJBLocal)ic.lookup("java:ejb/model.security.logic.SecurityEJB");
    session = (SecurityEJBLocal)ic.lookup("java:ejb/SecurityEJB");
    session = (SecurityEJBLocal)ic.lookup("java:app/SecurityEJB");
    session = (SecurityEJBLocal)ic.lookup("java:module/SecurityEJB");
    All return null pointers and claim the name cannot be resolved.
    As you can see - I have found various claims to how to do this.
    One way says create a sevlet, generate a listener and use the sevlet. Basically one for every EJB - a lot of work to use the EJBs
    I would assume that this would be one of the easiest parts of java - as it is the foundation of re-usability and oop.
    I can do either in the application - the added complexity of the EJB is less desirable - but better programming?

    Hi,
    ic.lookup("ZITASApplication-ZITASModel-SecurityEJB#model.security.logic.SecurityEJB");This should work with remote interface. If you want to lookup local interface, you need to register it in web.xml. Quote:
    To access the business local interface you need to define ejb local references for your component environment (i.e. from your servlet environment). You can do this by defining references in your web.xml. For example:
    <ejb-local-ref>
    <ejb-ref-name>ejb/BusinessLogicBean</ejb-ref-name>
    <local>packagename.BusinessLogicBean</local>
    </ejb-local-ref>
    To lookup your local reference from your servlet you need to use the following JNDI reference:
    java:comp/env/ejb/BusinessLogicBean Another one
    First, declare a local ejb reference in your web.xml file (This will add it to JNDI):
    <ejb-local-ref>
    <ejb-ref-name>ejb/Foo</ejb-ref-name>
    <local>simple.ejb.FooLocal</local>
    </ejb-local-ref>
    Then it can be looked up from JNDI:
    InitialContext ctx = new InitialContext();
    FooLocal foo = ctx.lookup("java:comp/env/ejb/Foo");Hope this helps.
    Pedja
    Helpful links (judging from your first post, you are probably sick of these :) )
    How to lookup local EJB in Oracle Weblogic 10.3
    http://m-button.blogspot.com/2008/07/reminder-on-how-to-use-ejb3-with.html
    http://www.coderanch.com/t/451012/EJB-JEE/java/EJB-Local-Lookup-not-working

  • Can I use two webservices in one Java Bean?

    Hi,
    I have created two webservices (deployed on my local J2EE Engine). I want to use both services in one application and create a new webservice that combines the functionality of both services.
    Is this possible to combine the two services with a java bean? If yes, have I to do something special?
    Is this possible at all?
    Is there another way to do it?
    Thank you!
    Bye
    Julia

    Hi Julia,
    Yes, you can call to different web services from another service.
    For that, do one thing.
    Make deployable proxies for both Web services. Then use these both deployable proxies in your main web service from where you want to call these web services.
    Code for calling these both web services is same as you are calling web services from any other J2ee or Java project.
    Regards,
    Bhavik Devisha

  • I lost my iPhone device, how can I get my data back on another one without using an iCloud backup just back up on i Tunes, Please Help.

    I lost my iPhone device, how can I get my data back on another one without using an iCloud backup just back up on i Tunes, Please Help.??

    You can find the backup files and then copy them to a safe place if you are worrying about this.
    iTunes places the backup files in these places:
    Mac: ~/Library/Application Support/MobileSync/Backup/
    The "~" represents your Home folder. If you don't see Library in your Home folder, hold Option and click the Go menu.
    Windows Vista, Windows 7, and Windows 8: \Users\(username)\AppData\Roaming\Apple Computer\MobileSync\Backup\
    To quickly access the AppData folder, click Start. In the search bar, type %appdata%, then press Return.
    Windows XP: \Documents and Settings\(username)\Application Data\Apple Computer\MobileSync\Backup\
    To quickly access the Application Data folder, click Start, then choose Run. In the search bar, type %appdata%, then click OK.

  • I have a Ipod Nano and want to get another one , and use both. Can I use the same computer and library for both?

    I have a Ipod Nano and want to get another one , and use both. Can I use the same computer and library for both?

    Yes

  • I have DocsToGo premium installed on my iPhone4s; can I use the same app on an iPad mini or do I have to purchase another one?

    I have DocsToGo premium installed on my iPhone4s; can I use the same app on an iPad mini or do I have to purchase another one?

    It shows up in the store as a universal app, so you should be ok to go.

  • How to deactivate adobe photoshop cc on one machine so that to be able to use it on another machine?

    how to deactivate adobe photoshop cc on one machine so that to be able to use it on another machine?

    Use Photoshop CC menu Help>Sign Out.... to deactivate the activated install.

  • Why can´t I use original HPinkcartridges from one HP printer to another HPprinter it says use origin

    why can´t I use original HPinkcartridges from one HP printer to another HP printer, it says use original cartridges -
    but they are original?

    If the printers are identical that should not be a problem. If the printers are not identical then it simply will not work. Each printer uses different cartridges unless it is from the same model group as the other.  
    In analogy that would be like asking why the spark plugs from a Porsche don't work in your PT Cruiser. 
    ****Please click on Accept As Solution if a suggestion solves your problem. It helps others facing the same problem to find a solution easily****
    2015 Microsoft MVP - Windows Experience Consumer

  • How to use ABAP stack of one with Java stack of another PI Server

    Hi Friends,
    We need to use the Java Stack of one server with the Abap stack of another PI server,
    will that be possible ? and if yes what are the things need to be taken care of. please suggest on the same.
    Regards,
    Nitin

    Hi Michal,
    Thank you very much for your answer, but want to know in detail (Technical Point of view) why it is not
    possible. As we can use SLD of another server by maintaining details in SLDAPICUST transaction,
    similarly cant we use java stack components of one server from ABAP stack of another PI Server.
    Just a query ??
    If you can put a light on this area it will be very helpful for us.
    Regards,
    Nitin

  • Game center id used by another one though i had change my apple password...

    My game center id used by another one. after that i changed my password. but he is still operating my game center account. i just knew it when i go to play my game Clash of Clans and my exp is 114 now...he is giving a lot of bad words by using my game id. what is the process that he will automatic log out from my game center id? Please help.

    Thank you very much for the helpful start. My Version is 6.1.3 (10B329).
    Under settings, however, on my phone there is no "iTunes @ App Stores" so that I can't implement your suggestion.
    Under "General", there is only
        About    Softare Update  Usage
        Siri
        Cellular  VPN  iTunes Wi-FI Sync
        Spotlight Search
        Auto-Lock  Passcode Lock   Restrictions
        Date & Time   Keyboard   International   Accessibility
        Reset
    So any further suggestion?  Thanks, Lee

  • If I buy an IPad to use it in another country, which one would you recomend?

    If I buy an IPad to use it in another country, which one would you recomend?

    http://www.apple.com/ipad/specs/
    http://www.apple.com/ipad/LTE/
    Post iPad 2 iPads all work world wide. Read the specs I provided links to.

  • I gave the iphone for servis and they gave me back another one used. Is that legal, I gave the iphone for servis and they gave me back another one used. Is that legal

    I gave my iphone for servis and the sailman return to me another one that has been used, without giving more details, telling me that this is the way apple does business. IS THAT TRUE?

    A refurbished until should appear identical to a new unit...you should not be able to tell the difference. If your unit is truly "used"...scratches, signs of use, etc., then Apple's warranty terms were not followed.
    All refurbished units receive new cases & batteries, at a minimum...that's why you can't tell the difference.

  • Using the results of one recordset to filter another.

    Hi
    I have a dynamically generated web page that uses a recordset to gather most of the relevant information that is needed on it. However, what i need to do is create a second record set on the same page and filter that second recordset using one of the results generated from the first recordset. The problem that i am having is that the first recordset displays its information as an echo <?php echo $row_Recordset1['move_type']; ?> but i obviously cannot use this echo code in the filter for the second recordset, the code obviously needs tweaking but i am not sure how.
    If it were as simple as copy and paste the query i would need for the recordset2 is as follows but i am unsure how to code the echo from the first recordset. I am well aware that the following code could never work but i hope it works as simplified example of my intention.
    SELECT ID, move_name, catagory_link_path, move_type, mem_on_off
    FROM moves
    WHERE move_type = <?php echo $row_Recordset1['move_type']; ?>
    ORDER BY move_name ASC
    Any help would be appreciated

    I can think of two ways this can be done. One way, (which may or may not be appropriate in your case) is to use an INNER JOIN. Here is an example:
    $presenterset1=mysql_query("SELECT * FROM presenters INNER JOIN presenters_course USING (presenter_id) WHERE course_id='$course_id' ORDER BY presenter_rank");
    Do a search for tutorials on INNER JOIN for information about how to use it.
    Another possible solution is to nest one SQL statement within the result of another: like this:
    $sql1=mysql_query("SELECT one, two, three from table1 WHERE one='$one'");
    while ($result1=mysql_fetch_assoc($sql1)){
    extract ($result1);
    $sql2=mysql_query("SELECT apple, orange, pear from table2 WHERE fruit='$three'");
    while ($result2=mysql_fetch_assoc($sql2)){
    extract ($result2);
    echo "$apple and $orange" and $pear<br/>";

Maybe you are looking for

  • How to fix Authentication error in scanning device using spiceworks?

    http://yourserver:port/fix It should show the unscanned devices and give hints on how to fix it. Usually with some reg keys.

  • How to view videos in iCloud published iPhoto Journal using web browser?

    If I publish an iPhoto Journal containing videos to iCloud and then attempt to view the journal from a web browser e.g. Safari, I see a single image corresponding to each video, but when I select one of them, I get a backwards, play/pause and forward

  • Installing antivirus on new Satellite L50B

    hello Toshiba forum i need to install kaspersky internet security 2015 (i've got the third license) on my new laptop but there is McAfee allready installed (but not configured yet) how do you suggest to proceed ? do i need to uninstall McAfee before

  • Menus and Contact Forms

    I am currently looking for a tutorial on how to create a drop-down Flash Menu very similiar to the one found on http://www.perseny.com as well as a Contact Form listed under their Private Dining section called "Request More Info" Any and all help is

  • TS3048 "Mouse buttons don't work as expected"

    When I consulted the troubleshooting page, the fix was identical to the fix listed for tracking problems, and that won't fix my problem.. Probably won't fix other peoples problems either When my Magic mouse is connected, it acts like the left button