Updating Beans in Application Scope

The problem is that i dont know how to update a bean in an application scope:
in EA4 i use this instruction to update a bean property:
// get the faces context
FacesContext facesContext = FacesContext.getCurrentInstance();
// update a property in application scope
(Util.getValueBinding("BeanName.propertyName")).
setValue(facesContext,"text");
and it worked ok in jsp:
<h:output_text valueRef="BeanName.propertyName" />
Now in version 1.0 i wrote:
Application app = facesContext.getApplication();
errorAplicacion = (ErrorAplicacion)app.createValueBinding("#{beanName}").
getValue(facesContext);
How should i update this value in application scope to be used in the jsp ?
I use in jsp:
<h:output_text value="#{BeanName.beanProperty}"/>
But i receive in logs:
Expression BeanName.beanProperty does not follow the syntax #{...}
And the result is null
Thanks a lot
German

If you are quoting your 1.0 code literally, you've got a case mismatch between "#{beanName}" when you create the value binding expression and "#{BeanName}" in the JSP page. As with most things in Java, the names are case sensitive.
Craig McClanahan

Similar Messages

  • Killing a bean with application scope?

    Is there any way to kill a bean with application scope?
    I am writing a web application, that most likely the browser window will never be closed. The problem is a user is authenticated onto our site but because the bean containing the users acct info is application scope, if another user logs in it still shows the old user as logged in. So on logout i would like to kill the application, the bean, servletContext...anything that will refresh the bean and the corresponding jsp. Any help is much appreciated.

    There is an indirect way if you know servlets. The "application" implicit object that you use in your JSP is the javax.servlet.ServletContext object. Instead of declaring your bean using the jsp:useBean tag, directly put your objects into the ServletContext using ServletContext.putAttribute() method. Objects put in the ServletCOntext are available to all pages in the application. Just use the ServletContext.getAttribute() method to retrieve this bean in any other page.
    To "kill the bean", just reset the value of this object to null by calling putAttribute(null).

  • Setting Beans in Application Scope

    How do I set beans in application scope at the start of a JSF web app? I'd like to be able to do something similar to the Struts plugin.

    Hi,
    I also tried to use a servletcontextlistener. The problem is, that I cannot
    put any beans in the facescontext, because a NullpointerExcpetion
    is thrown. In the contextInitialized-Method I do the following:
    FacesContext context = FacesContext.getCurrentInstance();
    ApplicationFactory factory =
         (ApplicationFactory) FactoryFinder.getFactory(
                   FactoryFinder.APPLICATION_FACTORY);
    Application application = factory.getApplication();
    ValueBinding binding = application.createValueBinding( "#{Bean}" );
    In the createValueBinding-method a Exception is thrown. So I cannot call
    createValueBinding when I am not in a facescontext.
    Can anyone help me?
    Thanks
    Andy

  • How to create,read and update variables in application scope in ejb

    In my project currently i am using three layers
    1. Struts for the presentation web layer(jsp, form beans and action class)
    2. Business logic using ejb.(uses other classes for storing business logic)
    3. Dao for data base object
    I need to implement caching using hashmap in the business logic (ejb). I am getting a path link everytime my business logic access a file. What I need to do is that as many users use the same link , i want to cache it into a hashmap, so that if the same file link is accessed again it can directly got from the hashmap and hence the processing time decreases.
    Please help me how to implement this?
    I have tried the following
    1. get servlet context in the struts action class and pass it to the ejb
    2. Using of static hashmap for storing that....which i cant use coz that hasmap needs to be updated in some other java class
    Awaiting ur reply eagerly

    use CTAS method in your requirement, first before read [b]this
    venki
    http://venki-hb.blogspot.com/

  • Application scope bean Vs. EJB

    I want to cash some application data - and was thinking of using a singleton bean with application scope in my controller and JSP page.
    <jsp:useBean id="myBean" scope="application" class="bean.datacash" />
    I am not very familiar with EJBs - and wanted to know if it would be a mistake not to use an EJB to perform that task.
    Is there a downside to my approach?
    Thanks for any insight
    Mike

    Entity EJB'S are used as a kind of data persistence, mostly to Databases. In a way it's like a kind of cache but any changes you make to an EJB are usually persisted to the underlying data storage on a regular basis.
    Session EJB's are more for business logic and depending on the type of Session Bean you use can either remain persisted in a session state or used and thrown away.
    EJB's also require alot of code so depending on your application requirements it is kind of a big decision.
    Is the data your wanting to cache to be shared by all users using the application? Are there any race conditions that may be met by concurrent access to the data? What do you plan to do with the cached data store it in a database or just make it available to share?
    If you want to look into using EJB's then your going to require an EJB Container to run them in (this can be standalone like OpenEJB or as part of an J2EE Application server like JBoss or Oracle Application Server to name just a couple).
    Using the Singleton Javabean can keeps things simple but once you start to synchronize methods with multiple users you can find some slowing down of the logic as the singleton tries to complete a request before getting onto the next.
    The [url http://jakarta.apache.org]Jakarta team offer a package called commons pooling which is designed as a pooling framework (also a way of caching) that can come in handy, I've used it to create a custom JDBC Connection pooler and it works quite well when you get the hang of it.
    Another thing to consider is the load the application may be under at it's busiest time. How many concurrent users do you expect to access the application?
    Sorry I can't give you a real answer as that is entirely up to you and your requirements. If you have a small app that has around 20-50 users then EJBs are bit of an overkill. If you find you'll have 100+ users with lots of data to manage then EJB's are probably a good option.
    If you have a look at [url http://www.theserverside.com]the serverside web site you may find a couple of articles on data persistence or check out some of the online magazines which also have articles on this same topic.
    Anthony

  • Application scope java beans not behaving....

    I am using WL 5.1, sp8, on NT....
              I am running jsp code that declares java beans of application scope....
              However, it doesn't appear to be resolving the application scope
              properly, it seems to instantiate a new Bean each time I go to
              a new page within the same application....
              One thing I am not clear on, is whether I have properly configured
              the WebApp....I have just been assuming that all pages within
              the same path sub-directory are of the same application, but that
              doesn't appear to be working....
              I haven't found any weblogic.properties settings for defining WebApps,
              that will share application scope, etc....
              I assume there is a simple answer here, I appreciate any help...
              Thanks,
              Jason Rosenberg
              

    Jason,
              WLS 5.1.0 is up to service pack level 12 now, which you should go to
              http://support.bea.com/welcome.jsp and login to download from the "Supports
              Download" section. Note that you need to be a paying customer to see this
              section. After applying sp12 you should take a look at our web app docs
              here http://bernal.beasys.com/release/docs51/classdocs/webappguide.html for
              instructions on setting up a web app and registering it in wls 5.1.
              "Jason Rosenberg" <[email protected]> wrote in message
              news:[email protected]...
              > I am using WL 5.1, sp8, on NT....
              >
              > I am running jsp code that declares java beans of application scope....
              >
              > However, it doesn't appear to be resolving the application scope
              > properly, it seems to instantiate a new Bean each time I go to
              > a new page within the same application....
              >
              > One thing I am not clear on, is whether I have properly configured
              > the WebApp....I have just been assuming that all pages within
              > the same path sub-directory are of the same application, but that
              > doesn't appear to be working....
              >
              > I haven't found any weblogic.properties settings for defining WebApps,
              > that will share application scope, etc....
              >
              > I assume there is a simple answer here, I appreciate any help...
              >
              > Thanks,
              >
              > Jason Rosenberg
              >
              >
              >
              >
              >
              >
              >
              

  • Looking for best practice on application scope beans

    Hey – a portal newbie here. I’ve got some application scope beans that need to be initialized on startup. First thought was to create a servlet that would set the bean. Then I saw the GlobalApp setting, but I think that looks like it is more session scope than application… Looking to be corrected here if I am wrong.
    Is there a place where these type of things traditionally happen? Read only, so no cluster worries (I think) Using WLP 8.1 SP4 and looking for best practices. Thanks for the help!

    To support "code sharing" you need an integrated source code control system. Several options are out there but CVS (https://www.cvshome.org/) is a nice choice, and it's completely free and it runs on Windows, Linux, and most UNIX variants.
    Your next decision is on IDE and application server. These are usually from a single "source". For instance, you can choose Oracle's JDeveloper and Deploy to Oracle Application Server; or go with free NetBeans IDE and Jakarta Tomcat; or IBM's WebSphere and their application server. Selection of IDE and AppServer will likely result in heated debates.

  • Initializing application scope beans on startup

    Hi All,
    I need to initialize an application scope managed bean on startup, and not have to wait for it to be referenced the first time.
    I was thinking of using ContextListener, but you dont have access to the faces context in the listener.
    And you cant even extend FacesServlet, since its final.
    Any ideas on how this can be achieved.
    Thanks for your help!!

    Try with FacesContext.getCurrentInstance() or http://www.jsffaq.com/Wiki.jsp?ptitle=How+to+access+FacesContext+from+the+Filter+or+Servlet%3F&page=HowToAccessFacesContextFromTheFilterOrServlet

  • Application-scope bean finalizer ?

    Hi,
    Using JSF on GlassFish. Have an application-scope bean that creates a javax.persistence.EntityManager and holds it for the duration of the application.
    When I redeploy, however, I get strange exceptions from TopLink which suggest that the state of the persistence provider is not correctly/fully cleared when undeploying. I suspect this because if I redeploy again, it (usually) works (unusually, I have to repeat the process 3 or 4 times).
    So I'm thinking of adding calls to EntityManager.close or something, when the application bean is terminated. Is there such a thing as a bean finalizer, or some method that's called by the app server when the application is undeployed ?
    BTW, the exception happens in this line of code:
    List<Quantity> qList = em.createQuery("SELECT q FROM Quantity q").getResultList();
    and the exception is:
    java.lang.ClassCastException: cannot cast class com.xxxxxx.Quantity to com.xxxxxx.Quantity ! (needless to say that I have not changed the class inbetween)
    Cheers,
    K

    Hi,
    Using JSF on GlassFish. Have an application-scope bean that creates a javax.persistence.EntityManager and holds it for the duration of the application.
    When I redeploy, however, I get strange exceptions from TopLink which suggest that the state of the persistence provider is not correctly/fully cleared when undeploying. I suspect this because if I redeploy again, it (usually) works (unusually, I have to repeat the process 3 or 4 times).
    So I'm thinking of adding calls to EntityManager.close or something, when the application bean is terminated. Is there such a thing as a bean finalizer, or some method that's called by the app server when the application is undeployed ?
    BTW, the exception happens in this line of code:
    List<Quantity> qList = em.createQuery("SELECT q FROM Quantity q").getResultList();
    and the exception is:
    java.lang.ClassCastException: cannot cast class com.xxxxxx.Quantity to com.xxxxxx.Quantity ! (needless to say that I have not changed the class inbetween)
    Cheers,
    K

  • How to init an application scope backing bean once app server startup?

    Hi guys,
    I got an application scope backing bean but I don't know how to initialize it once the app server startup ! I need all the webpage to be able to get the 'defaultCountry' value once the app server startup !
    <managed-bean>
    <managed-bean-name>applicationScopeBean</managed-bean-name>
    <managed-bean-class>com.borneo.webapp.action.ApplicationScopeBean</managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
    <managed-property>
    <property-name>defaultCountry</property-name>
                   <property-class>java.lang.String</property-class>
    <value>Singapore</value>
    </managed-property>
    </managed-bean>
    Pls help, Thanks !
    regards,
    Mark

    write a context listener and set up your web.xml as such
    <listener>
    <listener-class>com.package.ContextListener</listener-class>
    </listener>
    Then your class should inmplement ServletContextListener interface.
    The 2 methods need to be implemented
    public void contextDestroyed(ServletContextEvent sc_event) { }
    public void contextInitialized(ServletContextEvent sc_event) { }
    Hope that helps

  • How can a session scope bean access an application scope bean - help

    Hello,
    I have a JSP page that has references to an Application Scope and a Session Scope bean...
    <jsp:useBean id="myWebApp" scope="application" class="com.my.web.WebApplication" />
    <jsp:useBean id="myWebSession" scope="session" class="com.my.web.WebSession" />
    I would like the WebSession access methods in the WebApplication ... Can/ How does the WebSession object lookup the reference to WebApplication object?

    I don't think you should make the WebSession implement the session listener.
    The session listener will be created once, at the start of the servlet context and would be listening to all sessions. So you would have one instance of the WebSession belonging to the context (though not as an attribute), and others belonging to each session. This will be confusing in your code, I think.
    I would suggest having a different class act as the HttpSessionListener. Perhaps do something like this:
    public class WebSessionInjector implements HttpSessionListener {
      public void  sessionCreated(HttpSessionEvent e) {
        WebApplication webApp = (WebApplication)(e.getSession().getServletContext().getAttribute("webapp"));
        WebSession mySession = new WebSession();
        mySession.setWebApplication(webApp);
        e.getSession().setAttribute("mySession", mySession);
      public void sessionDestroyed(HttpSessionEvent e) { ... }
    }You may be able to use the WebApplication object itself as the listener ...
    Or, you could make the WebSession implement the HttpSessionBindingListener and use the valueBound event much like the sessionCreated event above, but from inside the WebSession object:
    public class WebSession implements HttpSessionBindingListener {
      public void  valueBound(HttpSessionBindingEvent e) {
        WebApplication webApp = (WebApplication)(e.getSession().getServletContext().getAttribute("webapp"));
        this.setWebApplication(webApp);
      public void valueUnbound(HttpSessionBindingEvent e) { ... }
    }

  • Problem with beans in session scope

    Hello,
    I developped a website using JSP/Tomcat and I can't figure out how to fix this problem.
    I am using beans in session scope to know when a user is actualy logged in or not and to make some basic informations about him avaible to the pages. I then add those beans to an application scope bean that manages the users, letting me know how many are logged in, etc... I store the user beans in a Vector list.
    The problem is that the session beans never seem to be destroyed. I made a logout page which use <jsp:remove/> but all it does is to remove the bean from the scope and not actualy destroying it. I have to notify the application bean that the session is terminated so I manualy remove it from its vector list.
    But when a user just leave the site without using the logout option, it becomes a problem. Is there a way to actualy tell when a session bean is being destroyed ? I tried to check with my application bean if there are null beans in the list but it never happens, the user bean always stays in memory.
    Is there actualy a way for me to notify the application bean when the user quits the website without using the logout link ? Or is the whole design flawed ?
    Thanks in advance.
    Nicolas Jaccard

    I understand I could create a listener even with my current setup Correct, you configure listeners in web.xml and they are applicable to a whole web application irrespective of whether you use jsp or servlets or both. SessionListeners would fire when a session was created or when a session is about to be dropped.
    but I do not know how I could get a reference of the application bean in >question. Any hint ?From your earlier post, I understand that you add a UserBean to a session and then the UserBean to a vector stoed in application scope.
    Something like below,
    UserBean user = new UserBean();
    //set  bean in session scope.
    session.setAttribute("user", user);
    //add bean to a Vector stored in application scope.
    Vector v = (Vector)(getServletContext().getAttribute("userList"));
    v.add(user);If you have done it in the above fashion, you realize, dont you, that its the same object that's added to both the session and to the vector stored in application scope.
    So in your sessionDestroyed() method of your HttpSessionListener implementation,
    void sessionDestroyed(HttpSessionEvent event){
         //get a handle to the session
         HttpSession session = event.getSession();
          //get a handle to the user object
          UserBean user = (UserBean)session.getAttribute("user");
           //get a handle to the application object
          ServletContext ctx = session.getServletContext();
           //get a handle to the Vector storing the user objs in application scope
            Vector v = (Vector)ctx.getAttribute("userList");
           //now remove the object from the Vector passing in the reference to the object retrieved from the Session.
            v.removeElement(user);
    }That's it.
    Another approach would be to remove the User based on a unique identifier. Let's assume each User has a unique id (If your User has no such feature, you could still add one and set the user id to the session id that the user is associated with)
    void sessionDestroyed(HttpSessionEvent event){
         //get a handle to the session
         HttpSession session = event.getSession();
          //get a handle to the user object
          UserBean user = (UserBean)session.getAttribute("user");
           //get the unique id of the user object
           String id = user.getId();
           //get a handle to the application object
          ServletContext ctx = session.getServletContext();
           //get a handle to the Vector storing the user objs in application scope
            Vector v = (Vector)ctx.getAttribute("userList");
           //now iterate all user objects in the Vector
           for(Iterator itr = v.iterator(); itr.hasNext()) {
                   User user = (User)itr.next();               
                    if(user.getId().equals(id)) {
                           //if user's id is same as id of user retrieved from session
                           //remove the object
                           itr.remove();
    }Hope that helps,
    ram.

  • Share stateful session bean in JSF managed beans with different scope

    Hi,
    I have a JSF application and I want to try to use of stateful session beans.
    So I created a new stateful session bean and its local interface.
    @Stateful
    public class StatefulSessionBean implements StatefulSessionBeanLocalInterface{
    private String name;
    @Local
    public interface StatefulSessionBeanLocalInterface {
    ...In my JSF application I have a mananed bean with session context which registers the new interface by
    this annotation
    @EJB(name="sessionbeanref", beanInterface=StatefulSessionBeanLocalInterface.class) and set the name to something.
    Now I want to fetch this name in another managed bean with request scope. So I looked up the bean and tried to get the name.
    StatefulSessionBeanLocalInterface = (StatefulSessionBeanLocalInterface) new InitialContext().lookup("java:comp/env/sessionbeanref");
    System.out.println(currentmailingbean.getName());but the name is null.
    Why?

    The xsd was created via the netbeans J2EE enterprise application dialog and I think its the most recent.
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">All other annotations seem to work.
    Wouldnt the lookup completely fail if the deployment process thought that it is version 1.4 ?

  • Best Performance? - having a single stateless java pojo as delegate- give it application scope?

    I'm curious about which is best from a performance standpoint -<br /><br />All of our flex calls access a single java pojo. In my remoting-config.xml I'm currently declaring the destination a property scope of 'application': <br /><br /><destination id="UIServicesDelegate"><br />    <channels><br />      <channel ref="my-amf"/><br />      <channel ref="my-local-amf"/ <br />    </channels> <br />     <properties><br />        <factory>spring</factory><br />        <source>uiServicesDelegateBean</source><br />        <scope>application</scope><br />    </properties><br /></destination><br /><br />All of the UIServiceDelegate methods are stateless however, so I'm wondering if I'm gaining anything by giving it scope session. Since their all stateless I"m assuming application scope would be the best from a performance standpoint? I'm assuming in this case only one object will ever be instantiated? <br /><br />Assuming it was between Session and Request scope, is there a lot of overhead instantiating the new server side object each time? I would assume performance would be better using the Session in this case, with the only draw back of some server-side ram being chewed up storing the object in the Session. <br /><br />If you want "singleton" type approach, I figure just using application scope is the preferred approach?

    You wont get any api for directly accessing Servlet application objects from any ejb. I dont think MDB either solves your problem directly. Indirectly you can place a request to some servlet (should be there for each JVM and web application ) and update your application scope variable. I would suggest you to cache the data in database if the size of cache is large. otherwise any open caching tools may help you.

  • Accessing Application Scope from an EJB

    I'm not sure of the best way of doing this:
    The set up:
    We have a rather large J2EE application that is composed of only servlets and JSPs at the moment (When the application began development EJB was in its infancy and not feasible for the development of the app). Some of the new deployments of the app involve distributed webserver over 4 JVMs and 2 machines. When a user connects the servers load balancing decides which particular JVM they should be connected to. We perform large data caching into the servlet application scope to avoid having to access the database every time a change is made by a user to certain tables in our database. The data caches are stored in hashtables in the servlet application scope.We seem to have no way to determine what other JVMs are running or which JVM a user is currently connected to.
    The problem:
    Apparently the application scope is for a particular JVM. This means that when a user makes a change to a data cache the change doesn't effect users in the other 3 JVMs of the application, only the users who, due to load balancing, happened to be connected to the same JVM as the one where the change was made.
    Our possible solution:
    We were thinking that we could set up a queue (such as MQSeries from IBM) and any time a change is made to one of these data caches put a message on the stack saying that the particular table had been updated. Then a MDB would be listening asynchronously and digest the message from the Queue and recache the tables from the database.
    So here are my questions:
    1. Would this work? Would putting a MDB in the EJB Container give each JVM the MDB in the first place, or would this mean it would pick one of the JVMs to deploy the MDB on and still not fix our problem.
    2. If this does work, how do I access the hashtables stored in the Servlet Application scope from the MDB. I can't seem to find any method available to the MDB (or any EJBs for that matter) that can access the servlets Application scope.
    3. Is this the best way to do this? Or is there a better way to share data between seperate JVMs that I don't have a URL to (It's all ambiguous and handled by the server as to which JVM actually gets the connection.)
    Just in case this is needed:
    We are running IBM WebSphere 5 Application Server and the database could be anything from DB2 to Oracle.
    Thanks in advance for any possible help.

    You wont get any api for directly accessing Servlet application objects from any ejb. I dont think MDB either solves your problem directly. Indirectly you can place a request to some servlet (should be there for each JVM and web application ) and update your application scope variable. I would suggest you to cache the data in database if the size of cache is large. otherwise any open caching tools may help you.

Maybe you are looking for

  • How do i get airplay on a macbook pro?

    I have a macbook pro i want to be able to use it with my apple tv do i need mountain line i have the latest version of lion currently

  • Which is the best Analog to Digital Converter

    Hey everyone, Im new to this movie making digital world.  I have been using imovie for a while and looking to upgrade to FCP.  Before I spend the money, just a few questions hoping someone would know the answers. 1:  Can I use idvd to burn my movies

  • Regarding Managed server in obiee11g

    Hi all, i have one managed server in weblogic domain. i have window service for admin server but for starting managed server i am using weblogic console . my concern is that when i start it after few days it gets down automatically. but admin server

  • Object ResPersonBean of type Control Binding Definition already exists.

    hi when i run my jsff page am geting this error,am in jdeveloper 11.1.1.6.0, this is what i have follow http://www.oracle.com/technetwork/developer-tools/jdev/ccset36-all-097334.html oracle.jbo.NameClashException: JBO-25001: Object ResPersonBean of t

  • Taking a long time to retrieve 3400 values..plzz help??

    I have a page wch displays 3400 values from the database in the matrix form which looks like this.......... ..................................role1   role2   role3  role4  role5   role6..................................................role34 competen