Access session values in Managed Bean

I want to acces session attribute values in my Managed Bean class.
This is my code in SecurityPhaseListener.java class,
HttpSession session = (HttpSession)facesContext.getCurrentInstance().getExternalContext().getSession(true);
String isAuthorized = "false";
session.setAttribute(isAuthorized, isAuthorized);
This is my configuration for My managed bean in faces-config.xml class
<managed-bean>
<managed-bean-name>setNewDayBean</managed-bean-name>
<managed-bean-class>com.hli.vipstar.uswm.setnewday.managedbean.SetNewDayBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Now i want to access the attribute "isAuthorized" in my managed bean SetNewDayBean.java.
How to do this?
Any one help me...........

The same way, but then using getAttribute() instead of setAttribute().
Another -more clean- way is to use the ExternalContext#getSessionMap(). It will make your code independent from the session implementation used. You may find this article useful as well: http://balusc.blogspot.com/2006/06/communication-in-jsf.html

Similar Messages

  • How to set hidden value in managed bean?

    Hi
    I have the following :
                           <a4j:commandButton
                                          id="commandButton3"
                                          action="#{backing_CustSearchBean.serchCustomer}"
                                          image="images/btn_search.gif"
                                          style="position: relative; margin-right: 5px;"
                                          actionListener="#{backing_CustSearchBean.checkText}"
                                          immediate="true"
                                          status="wait"
                                          oncomplete="showQuickCreate()"
                                          >  
                                <h:inputHidden id="jsfHidden" binding="#{backing_CustSearchBean.jsfHidden}" />
                                  <a4j:status id="wait">
                                    <f:facet name="start" >
                                      <h:graphicImage url="images/SpinGear2.gif" style="position: absolute; left: 378px; top: 216px; width: 19px; height: 18px;"/>
                                    </f:facet>
                                  </a4j:status>
                     </a4j:commandButton>when the action goes in the managed bean I want to set the value of hidden parameter "jsfHidden" in managed bean and catch it in showQuickCreate (oncomplete="showQuickCreate()" ) javascript function on return to the page.
    Please help, how should I do it?

    I know nothing about a4j, but if you want to pass new parameters from JSF to the backing bean, then use f:param for commandlinks or f:attribute for commandbuttons.
    The h:inputHidden just saves backing bean properties from request to request. You can't set or change it from within the JSF.
    Not sure if the f:attribute will work for the a4j commandbutton (check if they have a support forum at their website?)
    Also see http://balusc.xs4all.nl/srv/dev-jep-com.html about passing parameters and accessing objects and beans in the facescontext.

  • How to get ADF UI Component value in managed bean

    JDev version 11.1.1.1.3.0
    I have written a managed bean method and calling that method on valueChangeEvent of a Select boolean Checkbox ADF Component.
    I want to retreive the value of some other component located in the same page as the checkbox. I need the value of the component into the manged bean. I know how to get the value of the checkbox eg:
    public void selectCheckBoxListener(ValueChangeEvent evt){ 
    boolean selectedValue = (Boolean)evt.getNewValue();
    String oldvalue = (String)evt.getOldValue();
    How can I access the value of an input text component in the above managed bean ? Can someone help on this?

    Hi Sackam,
    String selectedRowId = (String)(evt.getComponent().findComponent("rowId")).getAttributes().get("value");
    The above coding will work fine
    but wht u have specified rowId???? whether the "value" field is inside a af:table????? if so i have doubt on the above code's working.....
    Regards,
    Suganth.G

  • Managed Bean "Name" Access  with in the Managed Bean

    Hi,
    I have faces-config.xml in which I have registered a managed bean
    and I have a base class for all the managed bean.
    The JSP's invoke the action/method defined in the base bean and I want to remove the managed bean from session upon a particular event.
    To remove the managed bean from session, as far as I know - we need to know the managed-bean-name in the faces config.
    I wanted to know if there is any way to get the name of the managed bean in the faces-config.xml at run time?.
    Thanks,

    Thanks for your recommendations. The issue that I get stuck on is how to call this method that retrives employee data. When I had the code in the constructor, it executed when I accessed the view.jsp page. Then I populated the fields from the Employee class fields. But once I create non-constructor method, how do I invoke it from my JSF page.

  • Reset JSF session and the managed beans with sesison scope

    Hi,
    this is a very general question and maybe stupid for most of you. I have my jsf/facelets web application and i use inside of this application some managed beans, which are session beans. I want to know how is it possible to reset this beans. I'm asking this question beacuse i have this kind of problem: i built my web application which has a login form and i use the browser to test it. When i browse to the login page and I login with my credentials i get my customized home page. Then i open another istance of the browser and i browse to the login page again but this time i login as a different user. The result home page is the same as i got before with my login credentials, so the session is always the same. Instead i want the session and all its objects to be resetted for the new user! Do youn know which is the solution?

    The fact is that i want to have two sessions in parallel, so using the same browser and opening two tabs, i want to browse to the login page and access as two totaly different users and using in parallel the application without the problem of one user's action affecting the other user beacuse of session sharing. So I want to force the application to create two different session for the two users logins, because as i told you before as it is now, they are sharing the same sesison. And i think that if i at the login time I iterate thorugh the session and delete all the objects i will be able to have only one session per time. Isn't it?

  • Accessing property of one managed bean to another in request scope

    Right now my applications managed beans are in session scope.
    I want to change them to request scope .But the problem is how to access the bean methods to another if they are in request scope

    Use RequestMap instead of SessionMap.
    Having multiple and independent managed beans in the request scope for 1 request and the need to access the other bean is somewhat odd design however. You may need to rethink about it. For example, add one of the beans as property of the other bean.

  • Binding af:selectOneChoice to value in managed bean

    Hi all,
    I am trying to create a simple screen that has a selectOneChoice that allows the user to change the value of a property in a session-scoped managed bean. I've got a View Object that will display the values for the user to select. I can easilly set the value on my managed bean in an actionlistener when the user clicks "OK"
    However, I have these problems:
    1). I can't find any way to put an af:selectOneChoice on the screen without binding it to something. I want to bind it to a value in a managed bean - how to do this?
    2). I tried creating a "dummy" view object (select :bindVariable from dual) and then put an executeWithParams in the executable of my page to set the bind variable to the backing bean value. I then bound the selectOneChoice to that field from the VO. This worked fine the first time, but the second time I tried to call it in the same session, it bombed with JBO errors. This also seems like a very inefficient and round-about way to accomplish this task.
    Can anyone provide any pointers as to how I might accomplish this? If it would help, my use case is this: a user is logged on with "super-user" athority and can review information from any of the field offices. The field office ID that the user is currently looking at is stored in the session-scoped bean. I need a way for the user to change what field office they are reviewing.
    Thanks and regards,
    John

    Wow - this is harder than I thought....
    I have got something working in a rudimentary fashion, although I'm not completely satisfied yet. What I did was to create my own List binding in the page definiton that looks like this:
    <list ListOperMode="1" IterBinding="LKUP_OfficeViewIterator" id="OfficeId">
          <AttrNames>
            <Item Value="OfficeName"/>
            <Item Value="OfficeId"/>
          </AttrNames>
        </list>
    </list>I then dropped a selectOneChoice from the component pallette (not the data control pallette) on to my page. The f:SelectItems component inside the af:SelectOneChoice, I bound the value property to "#{bindings.OfficeId.items}" I could not find any documentation on this, but it seems to work. The only issue is that my list shows both the office name and the id (I'd like to show the name and hide the id).
    Then, in my backing bean action listener bound to the OK button, I do:
        JUCtrlListBinding o = (JUCtrlListBinding) JSFUtils.resolveExpression("#{bindings.HotelId}");
        // list is bound to my af:SelectOneChoice
        Row r = (Row) o.getValueList()[((Integer)list.getValue()).intValue()];
        Integer officeID = (Integer) r.getAttribute(0);
        String officelName = (String) r.getAttribute(1);
       // getUserInfo gets my session-scoped bean
        super.getUserInfo().setOfficeInformation(officeID, officeName);
         AdfFacesContext.getCurrentInstance().returnFromDialog("ChangeOffice:OK", null);My 2 problems with this approach:
    1). How do I get the list to just show the office name (but still make the ID available)?
    2). No matter what I put for the value of the af:SelectOneChoice, I can't seem to make it have the current value from userInfo.getOfficeID selected in the list. Even when I hard-code a number in the list, nothing is selected. When I bind the value to an EL property referring to userInfo.officeID, the selectOneChoice doesn't even render!
    Regards,
    John

  • How to set ADF table cell value in managed bean

    Hi all,
    I have an ADF table on my page, let's assume with three columns with Input text box: col A, col B and col C where column C is hidden, when I click on Submit is possible to set in managed bean the value of column C for each rows?
    Thk in advance.
    L-

    Hi,
    you can create a button with an ActionListener. In the ActionListener you can iterate over the rows (using the iterator) and set the value on the attribute. If you need to save the changes you can call the commit operation binding.
    Linda

  • Accessing the ViewRowImpl in Managed Bean

    Hi,
    I am having the requiredment like setting the data to view object based on some conditions. Here after setting the data to a view object, i dont want to make my transaction as dirty, so am using the populateAttribute. since am setting the single attribute am planing to get the ViewRowImpl and want set the data in my managed bean instead of writing the service method in viewImpl.
    is it the good approach to get the viewRowImpl in managed Bean.. Please suggest...
    Reg,
    Brahma B.

    Hi Frank Thanks for your reply...
    Here i will create a record before loading the screen in add mode for accepting the user input. after creation of the record i will set some data programatically(the data may be usefull for dropdown which i attached to the a perticular column).
    Reg,
    Brahma B.

  • Accessing Managed Bean Variables in Entity Impl Class

    How can I access managed bean variables in the entity Impl class .
    While inserting a new record in DB , i want to set few entity properties values . The values of those properties are available in the managed bean .
    How can i access those values from Managed Bean and set them the entity Impl class to override the create method.
    Or is there any better recommended approaches ?
    Jdev - 11.1.1.5

    >
    While inserting a new record in DB , i want to set few entity properties values .
    >
    you can user CreateWithparams
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/13-create-with-params-169140.pdf
    http://andrejusb.blogspot.com/2011/02/createwithparams-operation-for-oracle.html

  • Managing beans based on URL query parameters

    I was just reading this thread with interest, but it didn't come to the conclusion that I need.
    http://forum.java.sun.com/thread.jsp?forum=427&thread=441432
    In that thread, there were two screens: a table of links to employees and an "edit employee" page. The solution was to use the command_action on the list create an "employee data" bean, which could then be edited on the "edit employee" page.
    My problem is that I need to create some session beans based on query parameters in the URL. Using the example above, I'd have something like: http://localhost/app/editEmployee?empNo=38
    Why? Because the user can bookmark the edit employee page, have two
    browser windows open (which would require two seperate employee data beans), etc... and we need to handle that. It looks like
    that means I can't use the solution in the above thread.
    My current thought is to create a managed-bean with request scope and have it create the EmployeeData bean.
    Another idea is to somehow initialize the bean with managed-properties
    <managed-bean>
        <managed-bean-name>EmpBean</managed-bean-name>
        <managed-bean-class>com.mycompany.EmpBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
        <managed-property>
            <property-name>employeeID</property-name>
            <value-ref>queryParamBean</value-ref>
        </managed-property>
    </managed-bean>
    <!--
      just returns FacesContext.getCurrentInstance().getServletRequest().getParameter("id")
    -->
    <managed-bean>
        <managed-bean-name>queryParamBean</managed-bean-name>
        <managed-bean-class>com.mycompany.QueryParamBean</managed-bean-class>
        <managed-bean-scope>none</managed-bean-scope>but that seems kinda hacky. Any other ideas?

    Excellent, using requestScope gets rid of the queryParamBean hack from my first post. For some reason I thought value-ref evaluatations only resolved against stuff the VariableResolver can see. That's not the case. Thanks.
    Unfortunately, this bean really wants to be cached on the session, not the request. I suppose it would be possible to have EmpBean delegate to a bean which is actually cached on the session, but that feels like a hack too (and is a lot of glue code).
    So, I think I'm back to the factory, which can handle creating the bean from the query params, caching it, and putting it on the servlet request. I also got a visit from Captain Obvious and realized that the factory could just be a scriplet.
    <% BeanCreator.createBean("com.company.EmpBean", request.getParameter("id")); %>which also isn't great, but is perhaps easier to understand than the BeanCreator from above. I looked into using EL Functions in the variable resolver for the factory, but it doesn't look like that's possible. It's probably possible to extend VariableResolver to add factory methods for managed-beans, which might be the cleanest solution. I'm thinking something like
    <managed-bean>
      <managed-bean-name>Emp</managed-bean-name>
      <managed-bean-factory>
         <factory-name>com.company.BeanFactory.getBean</factory-name>
         <bean-class>com.company.EmpBean</bean-class>
         <arg-value-ref>sessionScope.id</arg-value-ref>
      </managed-bean-factory>But for now, the current two hacks are:
    #1: to create a URL use plain html <href>.
    #2: use a factory method (varying implementions) to create the bean, cache it, and put it on the servlet request

  • Re:How to get the vo from managed bean

    Hi all,
    I am using Jdev11.1.2.3.0
    My requirement is : I have one jspx page.In that page i have created one form,so i need to get the values from managed bean.here i wont create by using data control view instance.so finally i have to get the table values from managed bean.so how can i get it.can anyone help me please.
    Thanks,
    G.Shilpa

    So you're not using ADF BC at all, right ?
    From JSF point of view, it does not matter how you provide UI control values.
    What you can do, for example, is to use pure JDBC in order to get and display the database values.
    What you need in your backing bean, is appropriate properties (setter/getter method pairs).
    In the getter, you can obtain DB values by using JDBC
    Take a look at:
    JSF 2.0 + JDBC integration example
    JSF JDBC Integration
    JDBC in JSF - YouTube

  • ADF Faces: Managed Beans

    Hi All,
    I have a situation where i need to pass the value to managed bean at runtime which inturn changes the values of menubar,menulist please can any one help me out.
    Regards
    Manasa Chanda

    What you probably want to do is expose the menubar.menulist component to your managed bean. This is fairly easy to do by editing the "Binding" property of the component. This will let you specify a Managed Bean, and a Property, or you can press a New button to create the bean, and/or the Property. Once you've exposed the component, the properties of the component are available through EL, including being able to change those properties from other components.

  • ADF BC how to access session backing bean value in servlet

    Hi everyone,
    How do I access session backing bean value in a servlet?

    Frank, thanks for your reply.
    I'm not sure how I can incorporate this example into my situation. Let me explain more detail about my problem.
    "servlet" in my post here actually means a custom servlet I wrote for rendering an image that is stored in db as ordimage. In this servlet, I get hold of my appmodule by using Configuation.createRootApplicationModule(). By doing so (If I'm not wrong) a new database session/connection is created. What I'm going to achieve is set application context for this new session/connection in db with the data stored in a session backing bean in the view layer.
    I can pass the required data to the servlet thru url parameter, but I don't want to do it this way for the reason that the data may contains sensitive information.
    I hope I have explained myself well.
    Message was edited by:
    bsmt

  • Get the current value of a managed bean.

    Hi guys
    I have a register page which takes the Login ID and the password and retype password whose values are stored in the "Managed Beans" in registerServer.java.
    I have a (PwdValidator.java) Custom validator for Re-type Password which validates itself against the password.
    Now my problem is from the PwdValidator.java how can I access the value of the password which is stored in the managed bean in registerServer.java.
    here is a copy of my faces-config.xml
         <managed-bean>
              <managed-bean-name>registerServer</managed-bean-name>
              <managed-bean-class>com.sun.registerServer</managed-bean-class>
              <managed-bean-scope>session</managed-bean-scope>
         </managed-bean>
    Help is really appreciated,
    Thanks,
    Chaprasi Baba

    Thanks for the reply but my question is how do I get
    the password value from the managed bean
    FacesContext context =
    FacesContext.getCurrentInstance();
    Application application = context.getApplication();
    CountryValueObject registerServer =
    (CountryValueObject)application.getVariableResolver().r
    solveVariable(context, "registerServer");
    String pwd = registerServer.password // So will this
    give me the current value for that session.You didn't go far enough in replacing the example code . Try this:
    FacesContext context = FacesContext.getCurrentInstance();
    Application application = context.getApplication();
    RegisterServer registerServer = (RegisterServer)application.getVariableResolver().resolveVariable(context, "registerServer");
    String pwd = registerServer.password // So will this give me the current value for that session.

Maybe you are looking for