You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andy <an...@fritter.net> on 2005/05/26 14:54:44 UTC

Blank page returned from ActionForm

Hi All,

I'm unable to output any errors using <html:errors/> tag, in Tomcat
5.5.7 with Struts 1.2.4. I've tried *numerous* configurations and have
now ran out of patience entirely. As I haven't been using Struts for more
than three days I hope somebody more experienced can point help me out.

When I select Submit, entering data into my form fields so the form is
parsed as valid, the forward works correctly. When I leave the fields
empty, so the form is parsed as invalid, I just get an empty page back -
which must be generated by Struts as it doesn't match any HTML I have.

Here is what I have in various files -

----------------------------------------------------------------------------
----

logon.jsp -

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<html>
<head>
<title><bean:message key="logon.title"/></title>
</head>
<body>
<html:errors/>
<html:form action="/SubmitLogonForm.do">
    <table>
    <tr>
        <td>Username</td>
        <td><html:text property="username"/></td>
    </tr>
    <tr>
        <td>Password</td>
        <td><html:text property="password"/></td>
    </tr>
    <tr>
        <td>
        <html:submit/>
        <html:cancel/>
        </td>
        <td></td>
    </tr>
    </table>
</html:form>

</body>


----------------------------------------------------------------------------
----

In LogonAction.java -


    public ActionForward execute(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request,
HttpServletResponse response)
                                throws Exception {

        if (isCancelled(request)) {
            log.debug("cancel pressed");
            return mapping.findForward(Constants.FAILURE);
        }

        LogonForm logonForm = (LogonForm)form;
        log.debug("username "+logonForm.getUsername());
        log.debug("password "+logonForm.getPassword());

        return mapping.findForward(Constants.SUCCESS);
    }


----------------------------------------------------------------------------
----

In LogonForm.java (I have getters/setters for HTML fields, and a reset
method,
not shown) -

    public ActionErrors validate(ActionMapping actionMapping,
HttpServletRequest httpServletRequest) {

        log.debug("validate");
        ActionErrors errors = new ActionErrors();

        if
(FormUtils.isNullOrEmpty(httpServletRequest.getParameter("username"))) {
            log.debug("logon.form.username.invalid");
            errors.add(ActionErrors.GLOBAL_MESSAGE,new
ActionMessage("logon.form.username.invalid"));
        }
        if
(FormUtils.isNullOrEmpty(httpServletRequest.getParameter("password"))) {
            log.debug("logon.form.password.invalid");
            errors.add(ActionErrors.GLOBAL_MESSAGE,new
ActionMessage("logon.form.password.invalid"));
        }

        return errors.isEmpty() ? null : errors;
    }


----------------------------------------------------------------------------
----

Two tags of interest from struts-config.xml -

       <!-- Process a user logon -->
       <action   path="/SubmitLogonForm"
                 type="template.action.LogonAction"
                 name="LogonForm"
                 scope="request"
                 input="/logon.jsp">
          <forward name="success" path="/welcome.jsp" />
       </action>

    <!-- Logon form -->
    <form-bean name="LogonForm" type="template.form.LogonForm"/>

----------------------------------------------------------------------------
----

ApplicationResources.properties - Note this is found and read by Tomcat, I
can
pull values from it using bean:message.

index.heading=Index Page Heading
index.logon=Logon
index.register=New User
#
struts.logo.path=/struts-power.gif
struts.logo.alt=Powered by Struts
# form fields
logon.form.username.invalid=Username invalid
logon.form.password.invalid=Password invalid
# page titles
error.title=Error Title
logoff.title=Logoff Title
logon.title=Logon Title
register.title=Register Title
welcome.title=Welcome Title
#
errors.header=Errors
errors.prefix=Error prefix

----------------------------------------------------------------------------
----

Here is debug from the Tomcat log -

DEBUG [http-8080-Processor24] (LogonForm.java:66) -
logon.form.username.invalid
DEBUG [http-8080-Processor24] (LogonForm.java:66) -
logon.form.username.invalid
DEBUG [http-8080-Processor24] (LogonForm.java:70) -
logon.form.password.invalid
DEBUG [http-8080-Processor24] (LogonForm.java:70) -
logon.form.password.invalid
DEBUG [http-8080-Processor24] (RequestProcessor.java:951) -  Validation
failed, returning to '/logon.jsp'

As you can see it correctly returns the page to /login.jsp when errors are
returned,
but the page is blank and the html is - <html><body></body></html>. There
are no
exceptions in the log.

Why is something so basic turning out to be so hard?

TIA,

Andy.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Blank page returned from ActionForm

Posted by Andrew Thorell <dr...@gmail.com>.
The only other thing I can think of is in the application.properties file:

errors.header=<UL>
errors.prefix=<LI><font color="red">
errors.suffix=</font></LI>
errors.footer=</UL>
logon.form.password.invalid=Invalid Password.

all should be set to something. I've included mine as an example

<html:errors property="login" />


public ActionErrors Validate(...)
{
   ActionErrors errors = new ActionErrors();
   errors.add("login", new ActionMessage("logon.form.password.invalid"));
   return errors;
}


This should work.

Is it possible that the application.properties file is not pointed to
in the config file?

The errors are parsed at run time, and if they don't find anything
they quietly render zippo (Which should be changed to pitch a warning
message or something)

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Blank page returned from ActionForm

Posted by Andrew Thorell <dr...@gmail.com>.
I remember trying the messagesPresent tags in my jsps but found the
extra code to be not worth the extra effort. It's just a whole lot of
extra code for a quick fix by naming the error property by name. In
the example:

<html:errors property="login"/>
errors.add("login", new ActionMessage("errors.login.invalid"));

I'm using struts 1.2

I think you may be right on the point about using the constant
GLOBAL_ERRORS and GLOBAL_MESSAGES though. I think Ted was discussing
it (or I read it in his book). I forget the outcome of the discussion
however.. as to whether <html:errors> will grab the GLOBAL_MESSAGES
constant.

Andrew

On 5/26/05, Dave Newton <ne...@pingsite.com> wrote:
> Andrew Thorell wrote:
> 
> >GLOBAL_ERRORS is deprecated (sp?) Looks like they changed it to just
> >use the Super class constant.
> >
> >
> Yes, but doesn't the errors tag just look for errors, not messages?
> 
> I don't recall which release you were using; sorry if I'm just spouting.
> What happens if you check for messagesPresent?
> 
> Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Blank page returned from ActionForm

Posted by Dave Newton <ne...@pingsite.com>.
Andrew Thorell wrote:

>GLOBAL_ERRORS is deprecated (sp?) Looks like they changed it to just
>use the Super class constant.
>  
>
Yes, but doesn't the errors tag just look for errors, not messages?

I don't recall which release you were using; sorry if I'm just spouting. 
What happens if you check for messagesPresent?

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Blank page returned from ActionForm

Posted by Andrew Thorell <dr...@gmail.com>.
GLOBAL_ERRORS is deprecated (sp?) Looks like they changed it to just
use the Super class constant.

Andrew

On 5/26/05, Dave Newton <ne...@pingsite.com> wrote:
> Andy wrote:
> 
> >>>            errors.add(ActionErrors.GLOBAL_MESSAGE,new
> >>>ActionMessage("logon.form.password.invalid"));
> >>>
> >>>
> Is this the key that errors are retrieved by in html:errors? Isn't the
> key for errors GLOBAL_ERRORS?
> 
> Dave
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Blank page returned from ActionForm

Posted by Dave Newton <ne...@pingsite.com>.
Andy wrote:

>>>            errors.add(ActionErrors.GLOBAL_MESSAGE,new
>>>ActionMessage("logon.form.password.invalid"));
>>>      
>>>
Is this the key that errors are retrieved by in html:errors? Isn't the 
key for errors GLOBAL_ERRORS?

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Blank page returned from ActionForm

Posted by Andy <an...@fritter.net>.
Andrew - 

Thanks but I tried adding the property attribute, and changed the string
parameter in errors.add to be the same value, but still no luck. 

Dave - 

I tried adding validate, but still no luck. Thanks for the tip on the
saveErrors method, I can the struts mailreader example does this, as you
say, didn't RTFM enough :)

I think I'll have to give up on my own template app, and just modify the 
struts mailreader example as a starting point ... at least this way if 
it breaks I can just rollback my changes.

Andy.


>-----Original Message-----
>From: Andrew Thorell [mailto:drew.thorell@gmail.com]
>Sent: 26 May 2005 14:12
>To: Struts Users Mailing List
>Subject: Re: Blank page returned from ActionForm
>
>
>/**
>* Double check the property 'Property' inside the Errors tag, it could
>be name, I just don't *have my code infront of me to double check.
>*/
><html:errors property="login" />
>
>errors.add("login", new ActionMessage("logon.form.password.invalid"));
>
>I've never been able to return an error using
>ActionErrors.GLOBAL_MESSAGE before. No idea why, I just found a work
>around that ended up working better for me in the end, because now I
>could put errors where ever I wanted.
>
>Hope that helps,
>
>Andrew T
>
>> <html:errors/>
>
>>             errors.add(ActionErrors.GLOBAL_MESSAGE,new
>> ActionMessage("logon.form.password.invalid"));
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Blank page returned from ActionForm

Posted by Andrew Thorell <dr...@gmail.com>.
/**
* Double check the property 'Property' inside the Errors tag, it could
be name, I just don't *have my code infront of me to double check.
*/
<html:errors property="login" />

errors.add("login", new ActionMessage("logon.form.password.invalid"));

I've never been able to return an error using
ActionErrors.GLOBAL_MESSAGE before. No idea why, I just found a work
around that ended up working better for me in the end, because now I
could put errors where ever I wanted.

Hope that helps,

Andrew T

> <html:errors/>

>             errors.add(ActionErrors.GLOBAL_MESSAGE,new
> ActionMessage("logon.form.password.invalid"));

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Blank page returned from ActionForm

Posted by Andy <an...@fritter.net>.
I should qualify my last e-mail. I did change the execute method, to include
amongst other things the saveError call (thanks Dave), as shown in  the
Struts example.

Andy.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Blank page returned from ActionForm

Posted by Andy <an...@fritter.net>.
I see my problem seems to be confounding all comers ! Well I went back first
principles as it were and started with the struts mailreader example, and
checked what I had done differently.

And do you know what the answer is? Take a look at this again -

       <!-- Process a user logon -->
       <action   path="/SubmitLogonForm"
                 type="template.action.LogonAction"
                 name="LogonForm"
                 scope="request"
                 input="/logon.jsp"
                 validate="true">
          <forward name="success" path="/welcome.jsp" />
       </action>

with the input field as a URL. When that field is changed to a global
forward, configured like this (as in the struts example) -

    <forward   name="logon" path="/Logon.do"/>

It works ! Ta da ! .... Error messages are displayed in all their glory.
This is somewhat of a pyrrhic victory, it having cost me several hours of
banging my fist on the desk in frustration.

Andrew, Dave and Michael thank you for help. I'm sure your posts contain
answers to problems I have yet to encounter :)

Perhaps the DTD should be updated for this field to dissallow forward
slashes.

Andy.


>-----Original Message-----
>From: Dave Newton [mailto:newton@pingsite.com]
>Sent: 26 May 2005 17:39
>To: Struts Users Mailing List
>Subject: Re: Blank page returned from ActionForm
>
>
>Michael Jouravlev wrote:
>
>>I usually get blank pages when I do not have a proper "forward"
>>defined, but in your case it is "input" and it looks ok.
>>
>>On 5/26/05, Andy <an...@fritter.net> wrote:
>>
>>
>>>When I select Submit, entering data into my form fields so the form is
>>>parsed as valid, the forward works correctly. When I leave the fields
>>>empty, so the form is parsed as invalid, I just get an empty page back -
>>>which must be generated by Struts as it doesn't match any HTML I have.
>>>
>>>
>Wow, I actually misread this thread TWICE. I thought you were just not
>getting the errors back, but you're getting a blank page.
>
>Sheesh.
>
>I agree with Michael, if a forward is wrongly-defined you'll often just
>get a blank page. I'm kind of curious as to why your debug logs
>print twice.
>
>Oh, try taking the ".do" off of the html:form action attribute.
>
>And try using html:messages rather than html:errors!
>
>Dave
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Blank page returned from ActionForm

Posted by Dave Newton <ne...@pingsite.com>.
Michael Jouravlev wrote:

>I usually get blank pages when I do not have a proper "forward"
>defined, but in your case it is "input" and it looks ok.
>
>On 5/26/05, Andy <an...@fritter.net> wrote:
>  
>
>>When I select Submit, entering data into my form fields so the form is
>>parsed as valid, the forward works correctly. When I leave the fields
>>empty, so the form is parsed as invalid, I just get an empty page back -
>>which must be generated by Struts as it doesn't match any HTML I have.
>>    
>>
Wow, I actually misread this thread TWICE. I thought you were just not 
getting the errors back, but you're getting a blank page.

Sheesh.

I agree with Michael, if a forward is wrongly-defined you'll often just 
get a blank page. I'm kind of curious as to why your debug logs print twice.

Oh, try taking the ".do" off of the html:form action attribute.

And try using html:messages rather than html:errors!

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Blank page returned from ActionForm

Posted by Michael Jouravlev <jm...@gmail.com>.
It seems to me that Struts cannot find logon.jsp. Hmm... are you sure
you spelled it correctly? The case, the location? What if you removed
the leading slash?

I usually get blank pages when I do not have a proper "forward"
defined, but in your case it is "input" and it looks ok.

Not much help from me, sorry..

On 5/26/05, Andy <an...@fritter.net> wrote:
> 
> Hi All,
> 
> I'm unable to output any errors using <html:errors/> tag, in Tomcat
> 5.5.7 with Struts 1.2.4. I've tried *numerous* configurations and have
> now ran out of patience entirely. As I haven't been using Struts for more
> than three days I hope somebody more experienced can point help me out.
> 
> When I select Submit, entering data into my form fields so the form is
> parsed as valid, the forward works correctly. When I leave the fields
> empty, so the form is parsed as invalid, I just get an empty page back -
> which must be generated by Struts as it doesn't match any HTML I have.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Blank page returned from ActionForm

Posted by Dave Newton <ne...@pingsite.com>.
Andrew Thorell wrote:

>I could be wrong, but I thought saveErrors was only needed in the
>Action Class, not the ActionForm class?
>  
>
Whoops, I suck. Just drank non-carbonated Chinese Red Bull and I'm all 
confused :/

Have you tried setting validate="true" for the action mapping?

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Blank page returned from ActionForm

Posted by Andrew Thorell <dr...@gmail.com>.
I could be wrong, but I thought saveErrors was only needed in the
Action Class, not the ActionForm class?

Andrew T

> Probably because you didn't read all the docs ;)
> 
> I don't see where you're saving the errors:
> 
> saveErrors(request, errors);
> 
> This is important.
> 
> Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Blank page returned from ActionForm

Posted by Dave Newton <ne...@pingsite.com>.
Andy wrote:

>In LogonForm.java (I have getters/setters for HTML fields, and a reset
>method,
>not shown) -
>
>    public ActionErrors validate(ActionMapping actionMapping,
>HttpServletRequest httpServletRequest) {
>
>        log.debug("validate");
>        ActionErrors errors = new ActionErrors();
>
>        if
>(FormUtils.isNullOrEmpty(httpServletRequest.getParameter("username"))) {
>            log.debug("logon.form.username.invalid");
>            errors.add(ActionErrors.GLOBAL_MESSAGE,new
>ActionMessage("logon.form.username.invalid"));
>        }
>        if
>(FormUtils.isNullOrEmpty(httpServletRequest.getParameter("password"))) {
>            log.debug("logon.form.password.invalid");
>            errors.add(ActionErrors.GLOBAL_MESSAGE,new
>ActionMessage("logon.form.password.invalid"));
>        }
>
>        return errors.isEmpty() ? null : errors;
>    }
>
>As you can see it correctly returns the page to /login.jsp when errors are
>returned,
>but the page is blank and the html is - <html><body></body></html>. There
>are no
>exceptions in the log.
>
>Why is something so basic turning out to be so hard?
>  
>
Probably because you didn't read all the docs ;)

I don't see where you're saving the errors:

saveErrors(request, errors);

This is important.

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org