newbie: [Help] struts JSP & iterate, also scoping?

R

Russ Perry Jr

We're working on our first struts application, and having a little
trouble. I've done some searching through the posts here and have
found some tantalizingly similar things to what we need, but
nothing exactly relevant. Perhaps someone can help?

We'd like the mapping.findFoward("failure") to take us to an error
page from the Action class, but we'd also like some relevant
messages to show up.

What I've been trying to do is create a Vector of error messages
and do a request.setAttribute to put it in request scope. Now,
perhaps that's the problem -- does it have to be in session
scope instead? I admit that my understanding of the request
scope is a little hazy...

Once I've come to the JSP page, the logic:iterate tag gives me
some error about pageContext (sadly, I can't give an exact error,
since the project is in a state right with which I can't replicate
the error). Perhaps I have something set up wrong? It looks like
this currently:

<logic:iterate id="errors" name="ErrorReport" scope="request"
type="java.util.Vector">
<bean:write name="errors"/><br />
</logic:iterate>

"ErrorReport" is the attribute name from the Action class:

request.setAttribute("ErrorReport", errorMessages);

"errorMessages" is the Vector of error messages I create in the
Action class.

Does anything here look obviously wrong? Like I said above, I
suspect it may be just that the request scope I'm setting the
Attribute in is different than the request scope when we go to our
errors.jsp page. If so, is there ANY way to forward my vector
without putting it in session scope? For that matter, is there
some way to use the <html:errors /> tag? I'm guessing no, since
that seems to apply only to the ActionForm's validate method, as
far as I understand it.

Perhaps another related question... Currently, I'm running into
this issue on our login process. Basically, we're only validating
the fields from login.jsp in the validate procedure, and then doing
the actual database connection and lookup in our LoginAction.java
class -- but is it better form to put this part in the validation
as well? In this case, we'd just be back to login.jsp with our
errors right there, and perhaps that's a cleaner model, but we'll
run into the error.jsp thing at some point just because that's the
way "they" want it right now...

Anyway, thanks for any help you fine folk can offer...
 
S

Sudsy

Russ Perry Jr wrote:
Does anything here look obviously wrong? Like I said above, I
suspect it may be just that the request scope I'm setting the
Attribute in is different than the request scope when we go to our
errors.jsp page. If so, is there ANY way to forward my vector
without putting it in session scope? For that matter, is there
some way to use the <html:errors /> tag? I'm guessing no, since
that seems to apply only to the ActionForm's validate method, as
far as I understand it.
<snip>

I just posted this URL in response to another query:
<http://www.sudsy.net/technology/struts-messageresources.html>
It contains code samples showing how to add errors messages
programmatically.
 
R

Russ Perry Jr

For anyone following along, I figured out eventually that the problem
was the type -- the collection is a Vector, but the type that I'm
iterating over is String. Duh. But that's how we learn, right?
I just posted this URL in response to another query:
<http://www.sudsy.net/technology/struts-messageresources.html>
It contains code samples showing how to add errors messages
programmatically.

Thanks, it looks interesting, though I haven't had time to read it
yet. I'll hopefully absorb it later this afternoon. I appreciate
the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top