0

Before I was using JSF, the following code was working in JSP files:

<c:if test="${not (empty request.error)}">
    Error: ${request.getAttribute("error")}
</c:if>

Now, when I am using JSF, I am getting this error:

/login.xhtml @24,51 test="${not (empty request.error)}" /login.xhtml @24,51 test="${not (empty request.error)}": Property 'error' not found on type org.apache.catalina.connector.RequestFacade

What is the problem/solution here? The editor does not underline anything.

Whole login.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./template.xhtml"
                xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:define name="userBar">
        <form method="POST" action="Login">
            <table>
                <tr>
                    <td>Login</td>
                    <td><input type="text" name="login" /></td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td><input type="password" name="password" /></td>
                </tr>
                <tr>
                    <td colspan="2"><input type="submit" value="Login" /></td>
                </tr>
            </table>            
        </form>

        <c:if test="${not (empty request.error)}">
            Error: ${request.getAttribute("error")}
        </c:if>
    </ui:define>

    <ui:define name="content">
        content
    </ui:define>
</ui:composition>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Adrian Adamczyk
  • 3,000
  • 5
  • 25
  • 41
  • @Visher you should probably learn JSF own mechanism for validation, or you'll be in a journey of pain trying to sanely pass everything between requests... – Elias Dorneles Jul 10 '12 at 23:12

3 Answers3

3

Since JSF2/Facelets, the #{request} is an implicit EL variable referring the currently involved HttpServletRequest object. See also Communication in JSF 2.0 - Implicit EL objects.

You need to either rename your managed bean (or whatever it is which appears with exactly the same attribute name in the EL scope), or to explicitly refer it through the EL scope map. Assuming that it's request scoped, you should be using #{requestScope.request} instead.

<c:if test="#{not empty requestScope.request.error}">
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

The error is clear.
Your bean named request, of type "org.apache.catalina.connector.RequestFacade" has no attribute named "error". Or if it exists, possibly there is no getter/setter.

If your intention is getting a value from servlet request, you could do like this:

<h:outputText value="#{param['error']}" />

More information here: Get Request and Session Parameters and Attributes from JSF pages

But why do you need it? If you want to handle errors in JSF, you could catch the Exceptions and display it as you want with:

h:message tag
FacesMessage class

Some sites:
http://www.jsftoolbox.com/documentation/help/12-TagReference/html/h_message.html

http://docs.oracle.com/cd/E17824_01/dsc_docs/docs/jscreator/apis/jsf/javax/faces/application/FacesMessage.html

Community
  • 1
  • 1
RicardoS
  • 2,088
  • 1
  • 21
  • 22
  • I have no idea what I'm doing wrong, just added your code and there is no result. My intention is to pass errors like "Invalid username/password" through request's attributes to use it in JSF. – Adrian Adamczyk Jul 10 '12 at 21:20
  • 1
    @Visher That's the wrong way to do it. The correct way is via `FacesMessage.` – user207421 Jul 11 '12 at 01:35
0

It's not an 'unset value', it's a non-existent property. HttpRequest does not have an 'error' property. The request.getAttribute("error") syntax is what you should be using.

user207421
  • 305,947
  • 44
  • 307
  • 483