struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anjib Mulepati <anji...@hotmail.com>
Subject Re: Struts 1 and AJAX
Date Thu, 02 Dec 2010 18:25:31 GMT
I am trying to validate email user have entered in textbox. I am using 
AJAX call for validation. So I am sending my email as post request and 
if validated it will add email in the table in the web page. This is 
what I want to happen.

But problem I am having is I can't tap the condition where email is 
invalid. Right now I am mapping blank page and null value in request 
object for invalid condition hoping to test the null value in view to 
take necessary action.

In AJAX upon successful call it simply add the email to the row of the 
table.

My code is as follow

1. I have AJAX post as follow:

$.post(
         "validateEmail.do",
         {sendValue: email},
         function(returnValue){
             addToTable(returnValue); //add email to table
         },
         "text"
     );

2. I have action as:
{
         String email = (String) request.getParameter("sendValue");
         // perform validation of email address
         try {
             insp.validate(email);
            //iF EMAIL IS VALID it return email and map email.jsp page
             request.setAttribute("returnValue",  email);
             return mapping.findForward(SUCCESS);
         } catch (Exception e) {
            //If email is invalid it retun null with error message and 
map to blank page.
             request.setAttribute("returnValue",  null);
             ActionErrors errors = new ActionErrors();
             errors.add("error", new ActionMessage(e.getMessage(), false));
             this.saveErrors(request, errors);
             return mapping.findForward(FAILURE);
         }
}


3. I have action mapping as

<action path="/validateEmail"
                 type="actions.ValidateEmailAction" >
<forward name="success" path="/pages/email.jsp" />
<forward name="failure" path="/pages/blank.jsp" />
</action>

4. Email.jsp simply display email
<%= request.getAttribute("returnValue") %>*
*
5. blank.jsp is just blank**page*

Anjib
*






On 12/2/2010 12:49 PM, Dave Newton wrote:
> On Thu, Dec 2, 2010 at 12:43 PM, Anjib Mulepati wrote:
>
>> Ok second also doesn't work.
>>
> "It doesn't work" actually isn't descriptive enough to allow anybody to help
> effectively--you'd need to say what actually happens, what you *expect* to
> happen, what's in your JavaScript console, what the action is returning to
> the Ajax call (HTML? JSON? XML?), and details like that.
>
> Otherwise we're all just guessing, and that takes too long.
>
>
>> My page display email if valid and null if invalid.
>>
> We have no idea what you're doing with the returned data other than calling
> a JS function you don't show.
>
> *Where I am doing wrong?
>
>
> Step 1: What does the action return for success? For failure?
> Step 2: How do you determine in the JS if it's a success or failure?
>
> Dave
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message