Add FacesMessage to FacesContext in an session scoped bean HOWTO?

I have an simple question. How can I add an FacesMessage to the FacesContext in a session scoped bean.
This code works fine for request scoped beans.
String message = "Some message";          
FacesMessage curentMessage = new FacesMessage(message, message);
curentMessage.setSeverity(FacesMessage.SEVERITY_ERROR); //Mark as ERROR
context.addMessage(�userForm�, curentMessage);          When I change bean scope to "session" I am getting java.lang.IllegalStateException at the last line when adding message to context.
Thanks:
-- Nermin

I have an simple question. How can I add an
FacesMessage to the FacesContext in a session scoped
bean.
This code works fine for request scoped beans.
String message = "Some message";          
FacesMessage curentMessage = new FacesMessage(message,
message);
curentMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
//Mark as ERROR
context.addMessage(�userForm�, curentMessage);          When I change bean scope to "session" I am getting
java.lang.IllegalStateException at the last line when
adding message to context.
Thanks:
-- NerminHow do you get "context"? If you are storing it as an instance variable of the bean, then you
should expect to get an exception. The FacesContext is scoped only to one request. Instead
of storing it in the bean, use FacesContext.getCurrentInstance() each time you need to use it.

Similar Messages

  • Using Query String Parameters with Session Scoped bean

    I would like to pass query string parameters from a product page (user clicks on a specific product commandLink) that is request scope to a details page that is session scoped.
    The problem is that the session scoped page only handles the first request. If you view the details of a product and then navigate back to the product page and choose another product ... the details page will not handle the new query string parameters and display the details for the first product chosen.
    Is there a way to make the session scoped bean recognize the query string parameters past the first request?

    I was able to replicate this problem with a very simple app that performs a redirection... just like the real app. Here's the simple app that I put together:
    From request scope page:
    <f:view>
             <h:form>
               <h:commandButton value="Link 1" action="#{reqbean.Link1}"/>
               <br/><br/>
              <h:commandButton value="Link 2" action="#{reqbean.Link2}"/>
            </h:form>
           </f:view>
    From request scope bean:
    public String Link1() throws IOException
        // Add event code here...
        //redirect the user
        FacesContext.getCurrentInstance().getExternalContext().redirect("untitled2.jspx?p=1");
        return null;
      public String Link2() throws IOException
        // Add event code here...
        //redirect the user
        FacesContext.getCurrentInstance().getExternalContext().redirect("untitled2.jspx?p=2");
        return null;
      }At this point... I put a println in the constructor of the session scoped bean because this is where I want to get the query string params. The constructor only gets called the first time a redirect is performed.

  • NullPointerException When trying to Get Session Scoped Bean data in another ManagedBean

    hello
    i wont to access to some data in my session scoped bean from a request bean so when i try to get this data all i get is 
    com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection
    on managed bean «discussionlaoder»
    in the end of the exception there is
    Caused by: java.lang.NullPointerException at Hiber.discussionlaoder.init(discussionlaoder.java:35)
    this is my code:
    1-the request scoped bean
    @ManagedBean
    @RequestScoped
    public class discussionlaoder {
      private MyadmninHelper halper;
    @ManagedProperty(value="#{serviceBean}")
         private ServicesBean  serviceBean;
        @PostConstruct
        public void init() {
          halper=getServiceBean().getHalper();  // line 35
    //seter and geter code
    2-the sesions scoped bean
    @ManagedBean (eager=true)
    @SessionScoped
    public class ServicesBean {
        private MyadmninHelper halper;
    //seter and geter code
    am using glassfish server 3.1
    thank's for help

    What you need to do is fix all those typos in your code, then you don't have to override names.
    - the proper Java class name is DiscussionLoader, not discussionlaoder (fix english typo also)
    - if you want to inject a class named ServicesBean, then also call the property the same.
    @ManagedProperty
    public ServicesBean servicesBean;
    But what you're doing now is call the class 'ServicesBean' and then in your managed bean declaration you seem to change your mind and it should all of a sudden be 'serviceBean'. Well then rename the class so you don't have your typo anymore!

  • Are session-scoped beans singleton

    Hi all, I miss something in the bean lifecycle within JSF. Assume that a page action navigates toward another page, linked to a session-scoped bean: this is created for the duration of this session. Then a button leads back to the original page, so that another action will lead to another page with its associated bean. Is this a new bean or the previous one ?
    This question is linked to the topic of bean dependencies through managed properties: it works fine, but since a bean is declared per class and not per instance, I miss the overall instantiation philosophy.

    Once the bean is created the first time in session, it will not be created again (until the session dies and you attempt to access the bean again of course).
    So in your scenario, the first time you access the page the bean gets created. When you go back and then go forward to the page again, a new bean is not created. The originally created one is re-used. Which means the constructor is not called again.
    CowKing

  • Session scoped beans other than SessionBean1

    Let's say I want to provide a logout action. I can end the session by using the below in my logoutButton_action method:
    try {
    FacesContext context = FacesContext.getCurrentInstance();
    HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
    session.invalidate();
    this.getExternalContext().redirect("Page1.jsp");
    } catch (Exception e) {
    log("Logout exception: " + e.getMessage());
    I would not have been able to figure out even that much if it wasn't for this forum. BUT, what about if I have other managed beans (i.e. just plain classes registered in managed-beans.xml) that have session scope, such a class to a hold a logged-in user's details during the session. How do I destroy that when the user logs out?

    {color:#333399}*hi*
    you can set any Object in ur sessionBean1 to be NULL,, by this way , ur session will hold no more data.
    {color}

  • Spring framework - Error with session scoped Beans

    Hello guys,
    I'm trying execute my Java Application inside Netweaver Application Server, but I'm having problems with serviceBeans with scope session. Anyone have already used Spring with session scope?
    Thanks,
    Cleiton.

    After many attempt, when I declared the bean with <aop:scoped-proxy  /> it works, however it could cause performance problem. I don't need refer this bean by another singleton bean, i did a wrong configuration in order to make a work a round...
    When I run my application on tomcat server, the DWR starts perfectly the "session scope bean form IOC container", but in the WEBAS maybe it's running in other thread. Is it possible?
    Anyone had a problem like this?
    I got a detailed error with log4j,
    ERROR Application [1] org.directwebremoting.impl.DefaultCreatorManager - Error loading class for creator 'SpringCreator[CounterSpringFacade]'.
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'counterSpringFacade': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
         at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:312)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
         at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881)
         at org.directwebremoting.spring.SpringCreator.getInstance(SpringCreator.java:145)
         at org.directwebremoting.spring.SpringCreator.getType(SpringCreator.java:107)
    Edited by: Cleiton dos Santos Garcia on Jan 7, 2009 5:02 PM

  • Create session scoped bean in servlet?

    I am working on a log in porgram for a jsp page using servlet.
    I need to create a bean in that servlet after user enter correct username and password, and the bean must have scope of session.
    How do I do this?
    How do I control the scope of variables in a servlet?
    thank you

    come on people! i just answered this 2 minutes ago! search the forums first! or a servlet book.
    servlet...
    Bean bean = new Bean();
    bean.setValue("value");
    request.getSession().setAttribute("bean", bean);
    jsp...
    <jsp:useBean id="bean" class="Bean" scope="session" />
    <%= bean.getValue() %>
    OR
    <%
    Bean bean = (Bean)session.getAttribute("bean");
    %>

  • PLZ Help: how to get value of a request scoped Bean/Attribute in JSF ?!!!

    hi,
    I noticed this part of code to retrieve session scoped beans/vars in an ActionListener or other jsf classes, but it does not work for request scoped beans/vars :( what's the problem then ? what shall i do ?
    Type var = (Type)Util.getValueBinding("myBeanInRequest")).getValue(context);
    I have also set that getPhaseId() returns UPDATE_MODEL_VALUES or APPLY_REQUEST_VALUES.
    Any comment or idea ?

    I have declared my Bean in my JSP page not in the
    faces-config.xml. Does this make any problem ? Also I
    have tried the way you told me as well, but still the
    returned attribute is null.
    P.S. My bean is declared in my JSP page this way:
    <jsp:useBean id="newSurveyVar" class="SurveyModel"
    scope="request" />
    This declaration causes the SurveyModel instance to be created in request scope when the page is rendered, but that doesn't help you when the form is submitted -- that is going to happen on the next request (so the request attribute created here goes away). Basically, <jsp:useBean> is not typically going to be useful for request scope attributes (it's ok for session or application scope, though).
    and further I have this jsf code:
    <h:command_button label="Create" commandName="create"
    action="create" >
    <f:action_listener
    r type="CreateNewSurveyActionListener"/>
    </h:command_button>
    and this is my
    CreateNewSurveyActionListener.processAction(ActionEvent
    e) {
    if (actionCommand.equals("create_the_survey")) {
    FacesContext context =
    t = FacesContext.getCurrentInstance();
    SurveyModel survey =
    y =
    (SurveyModel)(Util.getValueBinding("newSurveyVar")).get
    alue(context);
    if (survey==null) // returns true :(((
    And since I've declared my beans here there is nothing
    special declared in my faces-config.xml
    For me again it is really strange why it is not
    working !!!
    Any idea ? Because the event listener is fired in a separate request, so the one you created in the page is gone.
    This is why the managed bean creation facility was created. If your component contains a valueRef that points at the bean name (or you evaluate a ValueBinding as illustrated earlier in the responses to your question), then the bean will get instantiated during the processing of the form submit.
    Craig McClanahan

  • We should NEVER use the session back bean?

    Because the user can open a new window by right click the link, and the session scope back bean is not thread-safe.
    So we should forget it?

    Your concern makes really no sense, or you must be storing request scoped data in a session scoped bean instead of a request scoped bean, which can indeed lead to undesireable behaviour in multiple requests on the same session.

  • Store Session scoped variable in RequestScoped FormHandler?

    Hi All,
    I need to store a value into session scoped variable in formHandler. Is it possible? For Example, i need to no.of times handleApplyShippingGroups is being called by a User (Session scoped) and write a condition based on that value whose effect is to that User only? But, ShippingGroupFormHandler's scope is "Request"? How to get through this?
    Thanks,
    VishnuVardhan

    Hi,
    You can use the below logic.
    In ShippingGroupFormHandler.properties
    $class = your.custom.Shippinggroup.fomhandler
    profile=/path/to/your/profile/component
    In YourShippingGroupFormHandler.java
    Inside handleApplyShippingGroups(),
    //increment the value
    getProfile.setApplySgCallCount(getApplySgCallCount()++);
    Before that, add the property - applySgCallCount -  to your profile with getter and setters.
    Hope this helps.
    Please keep posting the issues / updates.
    Thanks,
    Gopinath Ramasamy

  • JSF problem Session Scoped and dialog

    Hello All! i have one problem with using ajax and session scoped .
    I'm using JSF 2.0 and Primefaces for build 2 dialog.
    I have one icon to click on it dialog 1 will display and show all list of customers and when i click details of customer on dialog 1, dialog 2 will display , and details of customer show base on <h:form>
    but my problem is when i click details of customer with id #1 it not show details of customer it return null, i must refresh this page and click on customer #1 and it display, but when i click on customer with id #3 it still display customer with id #1,and i must refresh page again to view customer with id #3 and after that if i want see details of other customer such as customer with id #5 i must click and refresh page, after refresh page i click on any id of customer if always show the last id of customer before refresh page, it mean because i use p:commandButton with ajax and 2 dialog inside one page, i know , if using session scoped i must pass value from one page to another page. But i want get id in the same page with session scoped this mean when i use p:commandButton call dialog 2 for pass id value from dialog one to dialog two it will get value don't refresh page . How can i do it? or can i call dialog from another show on the same page contain dialog 1?
    Primefaces dialog http://www.primefaces.org/showcase/ui/dialogHome.jsf

    Hello All! i have one problem with using ajax and session scoped .
    I'm using JSF 2.0 and Primefaces for build 2 dialog.
    I have one icon to click on it dialog 1 will display and show all list of customers and when i click details of customer on dialog 1, dialog 2 will display , and details of customer show base on <h:form>
    but my problem is when i click details of customer with id #1 it not show details of customer it return null, i must refresh this page and click on customer #1 and it display, but when i click on customer with id #3 it still display customer with id #1,and i must refresh page again to view customer with id #3 and after that if i want see details of other customer such as customer with id #5 i must click and refresh page, after refresh page i click on any id of customer if always show the last id of customer before refresh page, it mean because i use p:commandButton with ajax and 2 dialog inside one page, i know , if using session scoped i must pass value from one page to another page. But i want get id in the same page with session scoped this mean when i use p:commandButton call dialog 2 for pass id value from dialog one to dialog two it will get value don't refresh page . How can i do it? or can i call dialog from another show on the same page contain dialog 1?
    Primefaces dialog http://www.primefaces.org/showcase/ui/dialogHome.jsf

  • Resolving session scoped component in global scope component.

    Hi,
    I am implementing batch process and i am need to resolve session scoped component in global scoped component.
    In global scope component (one of the component referred by my scheduler which also in global scope as usual) and i need to resolve session scoped "/atg/epub/workflow/WorkflowView" component in my scheduler.
    I tried all possibilities but nothing worked out. I do not have access to current request, because its batch process. following ways i tried,
    1. getResolveName("/atg/epub/workflow/WorkflowView") method of GenericService which is extended by my global scope component -- This returns null.
    2. Tried to get the current request on ServletUtils to use resolveName() method on request.
    ServletUtlis.getCurrentRequest() - This returns null as expected.
    Is there any way to resolve session scoped component in global scope component. Thanks in advance.
    Edited by: 938890 on Jun 30, 2012 4:59 AM

    Try below :
    If you want to resolve the name of a Nucleus component from Java code that is not itself a Nucleus service, you must first initialize Nucleus with this construct:
    Nucleus.getGlobalNucleus().resolveName("target component")
    where target component is the name of the component you are looking up. Note that this construct works only for components with global scope.
    You can also resolve names of Nucleus components using the Java Naming and Directory Interface (JNDI). The following example shows how you can use JNDI to access the Scheduler component:
    String jndiName = "dynamo:/atg/dynamo/service/Scheduler";
    Context ctx = new javax.naming.InitialContext ();
    Scheduler s = (Scheduler) ctx.lookup (jndiName);
    reference - oracle ATG docs.
    ~ Praveer

  • Session scoped form handler

    hi all,
    what are all the session scoped form handlers in OOTB in atg
    regards
    shya

    What are Session Components in ATG OOTB
    http://www.techanuva.com/session-scoped-components-as-part-of-atg-dps/
    -RMishra
    Edited by: RMishra on Nov 21, 2012 7:26 PM

  • What is the best way or best practise to access the session scoped component in servelt pipeline?

    Hi Experts,
    What is the best way or best practise to access the session scoped component in servelt pipeline?
    Please share your thoughts.
    Thanks,
    ankV

    To resolve components in the session scope you should be using DynamoHttpServletRequest.resolveName(). And of course the DynamoHttpServletRequest can also be used to resolve global and request scoped components so it is pretty handy to use. You can get the DynamoHttpServletRequest request associated with the current thread from ServletUtil.getCurrentRequest().
    You can also reference a session scoped component from another session (or request) scoped component's property file. E.g. to access profile component (which is session scoped) from your custom session scoped component you would typically do this:
    $class=com.company.MyCustomComponent
    $scope=session
    profile=/atg/userprofiling/Profile

  • Session Scoped obSSOCookie

    Hi all,
    In my application if the user clicks on the "Sign Out" link, the obSSOCookie is removed. Later when the user logs into the site with the same browser, every thing work perfectly. But if the user closes the browser without properly signing off, I see some strange results when the user logs in next time in the same browser.
    How can I configure the webgate to create a Session scoped obSSOCookie? I mean the obSSOCookie has to be removed when the user close the browser (without siging off properly).
    A * R

    Hi Rajesh,
    By default, the ObSSOCookie is a session cookie. The problem might be your browser - in Firefox and other such tabbed browsers, browser instances share cookies and even closing the browser does not get rid of it. You can try using a HTTP tracing tool to verify that the ObSSOCookie is still there even when you "close" the browser and try logging in the next time.
    -Vinod

Maybe you are looking for

  • Open url link in custom workflow. SharepPoint 2010

    Hi, i created custom workflow in Visual studio 2010. I want my workflow opened page of the site. In workflow i using method - Process.strart("http:\\mysite\myform.aspx") try to open the page. But my workflow is completed after his the start. Browser

  • Connecting a WRT54G Wireless Broadband Router to a Westell DSL Modem

    For some reason I can't get my wireless router to finalize the last step on installation on my desktop. I followed all the tutorials from the linksys help center and I still can't get the router to install correctly. I did ipconfig/release and ipconf

  • How can I buy A new battery for my Iphone 5?

    Hello I need help, My iphone 5 it is giving problem with the battery, I just can try to turn on connnecting the iphone to the electricity but It is impossible, it tries to turn on the apple appear but then it just disappear again, and over again repe

  • BI LSO - use of business content: problem and limitation

    Hi, we are working on BI to develop some reports from LSO data. We are using 0HR_LSO_1 and 0HR_LSO_3 for participation and resource reservation and a lot of custom datasources from infotype 1001, 1000, 1042, 5007, and so on. We have met lot of proble

  • Search Broken

    I have a standalone Sharepoint 2013 and search was working on it.  However now it returns this error: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+msbin1). If using