How to access form data after submitting

I have a problem that I cannot solve.

Suppose we call a method (in the bean library) from a web page (possibly jsp, xhtml, portlet ...), by 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.

Suppose also that in the process of action we get a problem (exception).

I wrote (and registered) an ActionListener that will catch an Unhandled Exception (and this 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();
}
}
}

This works fine ... BUT ... I need to know the data that (was?) In the form presented.

How can I get this information? I need a generic method, since an error can occur throughout the application (I really don't know clientId or other unique information about objects).

: !!

, JSF 1.2.

?

!

+3
1

, ?

bean :

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

( JSP) :

<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>

${paramValues} HttpServletRequest#getParameterMap(), Map<String, String[]>.

+5

Source: https://habr.com/ru/post/1769306/


All Articles