tags:

views:

53

answers:

2

Hi to all,

I have a problem that I am not able to solve.

Well, let's suppose that we are invoking a method (in a backing bean) from a webpage (maybe jsp, xhtml, portlet ...) pressing a button.

<h:form>
....
<h:inputText value="#{errorManager.errorTestDataBean.errore00}" />

<h:commandButton id="go" value="GO" action="#{errorManager.triggerError}" />
...
</h:form>

The form is submitted with its values.

Let's also suppose that we will get a problem (Exception) during the action process.

I wrote (and registered) an ActionListener that will catch the Unhandled Exception (and that will do something to handle it):

public class ExceptionHandlingActionListener extends ActionListenerImpl
{

public void processAction(ActionEvent event)
{
try
{
super.processAction(event); //+THE ERROR HAPPENS IN THE SUPER CLASS+ 
}
catch(Exception exception)
{
exception.printStackTrace();
......... do something here ...............

FacesContext facesContext = FacesContext.getCurrentInstance();
Application application = facesContext.getApplication();
NavigationHandler navigationHandler = application.getNavigationHandler();
navigationHandler.handleNavigation(facesContext, null, "error"); /* FORWARD TO AN ERROR PAGE */
facesContext.renderResponse();
}
}
}

It works great ... BUT ... I need to know data that are (was?) in the submitted form.

How can I get this information? I would like a generic method, since the error can happen everywhere in the application (I don't really know the clientId or other peculiar information about objects).

It's also ok to get ALL posted data and write them down in the database: I will analyze data later!!

Unfortunately, we're still at JSF 1.2.

Any ideas?

Many thanks! Tommaso

A: 

You can use this code

 (MyBean1) FacesContext.getCurrentInstance().getExternalContext()
            .getRequestMap().get(MANAGED_BEAN_NAME);
org.life.java
Hi, so I have to know the Bean Name. I have many beans and I don't really know the name. I will try anyway.
Tama
@Tama You can also get the page from which action has been executed using `getViewId()` That will be more helpful i guess
org.life.java
Well, as far as I can see FacesContext.getCurrentInstance().getExternalContext().getRequestMap() is always empty, indeed getViewId() returns the correct value. But is not so usefull since I need to log data input from user side.
Tama
A: 

So, you want to obtain all request parameters?

In a bean you can do like follows:

ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
Map<String, String[]> paramValues = ec.getRequestParameterValuesMap();

In the view (assuming JSP) you can do like follows:

<ul>
    <c:forEach items="${paramValues}" var="entry">
        <li>${entry.key}:
            <c:forEach items="${entry.value}" var="value" varStatus="loop">
                ${value}${!loop.last ? ', ' : ''}
            </c:forEach>
        </li>
    </c:forEach>
</ul>

The ${paramValues} refers implicitly to HttpServletRequest#getParameterMap() which returns a Map<String, String[]>.

BalusC