javajsfjsf-2.2managed-beanfacescontext

Not getting request parameters in @RequestScoped ManagedBean


I have one JSF page and have a Managedbean associated with it.

My xhtml page looks like this:

<h:head>

</h:head>

<h:body id="configuratorWrapper">
<h:form method="post" id="form" name ="name" prependId="false">
    <f:view>
        <div class="container">
        <input type="hidden" name="exception" id="exception" value="aaa" /> 
        </div>  
         <h:input type="hidden" name="email" id="email" value="#{emailManagedBean.sendEmailForErrorPage()}" /> 
    </f:view>
</h:form>
<h:outputScript library="resources/bower_components/boostrap-sass/assets/javascripts" name="bootstrap.js"></h:outputScript>
</h:body>

emailManagedBean is the associated Managedbean which is a @RequestScoped ManagedBean.

The method sendEmailForErrorPage() in EmailManagebean looks like :

public Boolean sendEmailForErrorPage() {
        this.exception = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("exception");
    }

I need to get the exception value as "aaa", which I gave in xhtml page. But I am getting null as value now.

I tried using

<p:commandButton name ='email' action="#{emailManagedBean.sendEmailForErrorPage()}">
    <f:param name="exception" value="aaa" />
</p:commandButton>

Still the result was null.

Can someone help me out to solve this issue.


Solution

  • I have find a way out to fix this issue. Instead of passing it as a parameter, I passed it as an argument to the method. It worked nicely. I was able to get the value for exception.

    <f:event type="preRenderView" listener="#{emailManagedBean.sendEmailForErrorPage('aaa')}" />