You *need* a means of telling your application whether the validation
was successful or a failure.  All you're currently doing is reiterating
to your server of a successful or failed validation...which it already
knows by virtue of your validation method.  As Dave and I have both
suggested, a JSON response is probably the best and simplest method to
tell your client what's going on.

I didn't read through this, but looks promising for your use case:
http://www.selfcontained.us/2008/08/29/teaching-an-old-framework-new-tri
cks/ 

...oooor:
http://www.google.com/search?q=struts1+json&ie=utf-8&oe=utf-8&aq=t&rls=o
rg.mozilla:en-US:official&client=firefox-a


Beez
r 5347 

-----Original Message-----
From: Anjib Mulepati [mailto:anji...@hotmail.com] 
Sent: Thursday, December 02, 2010 3:34 PM
To: Struts Users Mailing List
Subject: Re: Struts 1 and AJAX

I am trying with simple things but result are not as I expected.

After call to Struts action I get either SUCCESS or FAILURE view. And
these same page are displayed in the row itself. I was planning to
display email if it is valid(SUCCESS) or error message on page (in div
area fro error) if the email is invalid.

As shown before both view are mapped to different page. And in AJAX call
upon success it is calling function to add row.

I think these are two conflicting or equivalent steps I am taking. So I
am missing some point.

Can anyone tell me how can I solve this issue?

Anjib

On 12/2/2010 2:09 PM, Dave Newton wrote:
> You *could* do that, or do it in the view layer, or just serialize a 
> rational JSON object to the response and skip all the other issues, 
> and make things easier.
>
> Dave
>
> On Thu, Dec 2, 2010 at 2:06 PM, Anjib Mulepati<anji...@hotmail.com>
wrote:
>
>> So do I need to map two different view in action class as follow
>>
>>
>> {
>>         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); //View 1
>>
>>         } catch (Exception e) {
>>            //If email is invalid it retun null with error message and

>> map to blank page.
>>             request.setAttribute("returnValue",  "-1");
>>
>>             ActionErrors errors = new ActionErrors();
>>             errors.add("error", new ActionMessage(e.getMessage(),
false));
>>             this.saveErrors(request, errors);
>>             return mapping.findForward(FAILURE); //View 2
>>
>>         }
>> }
>> On 12/2/2010 1:42 PM, Dave Newton wrote:
>>
>>> On Thu, Dec 2, 2010 at 1:25 PM, Anjib Mulepati wrote:
>>>
>>>   But problem I am having is I can't tap the condition where email 
>>> is
>>>> invalid.
>>>>
>>>> $.post(
>>>>         "validateEmail.do",
>>>>         {sendValue: email},
>>>>         function(returnValue){
>>>>             addToTable(returnValue); //add email to table
>>>>
>>> "Tap it" in that function: isn't the returnValue either the email 
>>> (if
>>> successful) or nothing (if not)?
>>>
>>> Although personally I'd still use JSON; easier.
>>>
>>> Dave
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> For additional commands, e-mail: user-h...@struts.apache.org
>>
>>


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




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

Reply via email to