You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Stephan Heilner <SH...@studeo.com> on 2005/11/11 00:37:04 UTC

Integrating AJAX into Struts

With all the momentum towards AJAX, has anyone started to undertake
integrating AJAX into Struts.  I think that it could be relatively easy
using DWR (http://getahead.ltd.uk/dwr/).  Here's how I'm thinking you
could do it:
 
Since Struts uses custom tag libraries for forms (ie <html:form>) you
could change the JavaScript that it spits out to print out a JavaScript
function.  
 
So you'd go from :
------------------------------------------
<form name="MyForm" action="postForm.do">
    ..
    <input type="submit" value="Submit" />
</form>
 
 
 
to:
------------------------------------
<script language="JavaScript">
    function validate() {
    
  var myMap = new Object();
  
  myMap["prop1"] = DWRUtil.getValue("prop1");
  myMap["prop2"] = DWRUtil.getValue("prop2");
  
  StrutsDWRUtil.validate(fillForm, myMap, FORM_NAME);
  
  return false;
    }

    function fillForm(retMap) {
    
  if(retMap["errors"] != null) {
   DWRUtil.setValue("errors", retMap["errors"] );
  } else  {
   document.MyForm.submit();
  }
}
</script>
<form name="MyForm" action="postForm.do" onsubmit="return validate();">
    .. 
    <input type="submit" value="Submit" />
</form>
 
 
The "StrutsDWRUtil" there is actually a java class and "validate()" is a
java method.  This could just call the existing validate method that is
already being called (validation.xml and validate(request, response) to
validate a form when it is posted.
 
The benefit of validating forms this way, is that you won't have to
actually post the form to validate it.  You can have real-time
validation (done with java) and not have to reload the page.  It looks
like someone has already attempted to do this
(http://getahead.ltd.uk/dwr/server/struts) although I'm not sure I'm
totally sold on his approach.
 
-Stephan

Re: Integrating AJAX into Struts

Posted by Hubert Rabago <hr...@gmail.com>.
Oops, I was actually replying to this part:

>  I wish I could
> remember what it was, but I don't.


On 11/11/05, Hubert Rabago <hr...@gmail.com> wrote:
> On 11/11/05, Frank W. Zammetti <fz...@omnytex.com> wrote:
> > Hell, it's quite possible I simply didn't think it through enough to
> > realize the simple solution :)
>
> I remember.

Hubert

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


Re: Integrating AJAX into Struts

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Well, at the end of the day it doesn't really matter any more anyway... 
I believe the AjaxTags in JWP is a better, more powerful and more 
flexible solution, and is non-invasive to an existing app, be it Struts 
or not.  In a way, the fact that everyone didn't fall in love with the 
original idea actually turned out better in my opinion :)

If anyone likes the idea of a declarative, taglib-based AJAX approach, I 
suggest taking a look at it and of course contributing if it strikes 
your fancy.  I know a lot of people already are using AjaxTags and 
liking it quite a bit.  I have no illusions that it's perrect, but I 
don't think it's a bad answer.

All the concerns about getting mods into the core (or the taglib 
subproject now) is completely rendered moot, and I like that too :)

Frank

Hubert Rabago wrote:
> On 11/11/05, Frank W. Zammetti <fz...@omnytex.com> wrote:
> 
>>Hell, it's quite possible I simply didn't think it through enough to
>>realize the simple solution :)
> 
> 
> I remember.  You had something you wanted to modify in BaseHandlerTag.
>  Niall's validatorjs extension modifies a base class, too:
> BaseFieldTag.  html2 modifies both - BaseFieldTag and BaseHandlerTag. 
> :)
> 
> Well, it's still a fork, so that might really bother you.  Me, I just
> wanted to see what it would look like, how much code the fork
> contained, etc.  Turned out to be much less than I anticipated.  Of
> course, html2 doesn't really do much.
> 
> Hubert
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com

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


Re: Integrating AJAX into Struts

Posted by Hubert Rabago <hr...@gmail.com>.
On 11/11/05, Frank W. Zammetti <fz...@omnytex.com> wrote:
> Hell, it's quite possible I simply didn't think it through enough to
> realize the simple solution :)

I remember.  You had something you wanted to modify in BaseHandlerTag.
 Niall's validatorjs extension modifies a base class, too:
BaseFieldTag.  html2 modifies both - BaseFieldTag and BaseHandlerTag. 
:)

Well, it's still a fork, so that might really bother you.  Me, I just
wanted to see what it would look like, how much code the fork
contained, etc.  Turned out to be much less than I anticipated.  Of
course, html2 doesn't really do much.

Hubert

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


Re: Integrating AJAX into Struts

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Hubert Rabago wrote:
> I was (still am) among those who think that we don't need it to be
> made part of the struts download to be useful.  You could use html2
> just by including its jar and changing the TLD URI you specify in your
> JSP: http://www.rabago.net/struts/html2/#tlds

I admit the details are now fuzzy, I've long since moved on, but I 
recall there being a show-stopping technical reason why this wouldn't 
work for what I was doing.  I wish I could remember what it was, but I 
don't.  I know that one of my original goals was that an existing app 
should not have to be changed AT ALL, just added to, and changing a TLD, 
while minor, is still a change.  I can't imagine that would have stopped 
me from doing what you've done though.

Hell, it's quite possible I simply didn't think it through enough to 
realize the simple solution :)

> Then again, html2 may not be the best example for this, since I wasn't
> really attempting to reach the widest audience and get mass
> acceptance, so I guess I don't blame you if you're not convinced. :)

I admit I haven't looked at your html2 work.  Just quickly glancing at 
it now.  I am not unconvinced :)  (parse that double-negative, I dare you!)

> Hubert

Frank

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


Re: Integrating AJAX into Struts

Posted by Hubert Rabago <hr...@gmail.com>.
On 11/10/05, Stephan Heilner <SH...@studeo.com> wrote:
> The benefit of validating forms this way, is that you won't have to
> actually post the form to validate it.  You can have real-time
> validation (done with java) and not have to reload the page.

I also played around with this idea, just as an experiment.  I put the
results of my experiment at http://www.rabago.net/struts/html2/

html2 tags will use Validator javascript support on the client if the
form has it, or will call the ActionForm's validate() through a nAJAX
call if it doesn't.  Either way, you'd get your validation done
without submitting the whole form.  (Uhm, nAJAX cause it's not an
async call.)

On 11/10/05, Frank W. Zammetti <fz...@omnytex.com> wrote:
> Unfortunately, the idea was not especially well-recieved when I offered
> to continue the work and make it a real, official part of the Struts
> taglibs

I was (still am) among those who think that we don't need it to be
made part of the struts download to be useful.  You could use html2
just by including its jar and changing the TLD URI you specify in your
JSP: http://www.rabago.net/struts/html2/#tlds

Then again, html2 may not be the best example for this, since I wasn't
really attempting to reach the widest audience and get mass
acceptance, so I guess I don't blame you if you're not convinced. :)

Hubert

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


Re: Integrating AJAX into Struts

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Been there, done that :)

http://struts.sourceforge.net/ajaxtags/index.html

Unfortunately, the idea was not especially well-recieved when I offered 
to continue the work and make it a real, official part of the Struts 
taglibs, so there is now a frankly much better non-Struts-specific 
version in Java Web Parts that spawned from that:

http://javawebparts.sourceforge.net/

Check out the ajaxtags package in the javadocs.

I think one of the original objections, and a reasonable one, is which 
toolkit do you build on?  Some will say DWR, some will say Dojo, others 
have numerous other ideas.  With my work, I choose to not build on any 
toolkit, but the current incarnation has the flexibility to allow you to 
very easily use them if you wish.

The Struts taglibs can do the same, and ultimately what I did would have 
evolved into what is in JWP today, but as a first-class part of the 
Struts taglibs, exactly what your talking about.

Frank

Stephan Heilner wrote:
> With all the momentum towards AJAX, has anyone started to undertake
> integrating AJAX into Struts.  I think that it could be relatively easy
> using DWR (http://getahead.ltd.uk/dwr/).  Here's how I'm thinking you
> could do it:
>  
> Since Struts uses custom tag libraries for forms (ie <html:form>) you
> could change the JavaScript that it spits out to print out a JavaScript
> function.  
>  
> So you'd go from :
> ------------------------------------------
> <form name="MyForm" action="postForm.do">
>     ..
>     <input type="submit" value="Submit" />
> </form>
>  
>  
>  
> to:
> ------------------------------------
> <script language="JavaScript">
>     function validate() {
>     
>   var myMap = new Object();
>   
>   myMap["prop1"] = DWRUtil.getValue("prop1");
>   myMap["prop2"] = DWRUtil.getValue("prop2");
>   
>   StrutsDWRUtil.validate(fillForm, myMap, FORM_NAME);
>   
>   return false;
>     }
> 
>     function fillForm(retMap) {
>     
>   if(retMap["errors"] != null) {
>    DWRUtil.setValue("errors", retMap["errors"] );
>   } else  {
>    document.MyForm.submit();
>   }
> }
> </script>
> <form name="MyForm" action="postForm.do" onsubmit="return validate();">
>     .. 
>     <input type="submit" value="Submit" />
> </form>
>  
>  
> The "StrutsDWRUtil" there is actually a java class and "validate()" is a
> java method.  This could just call the existing validate method that is
> already being called (validation.xml and validate(request, response) to
> validate a form when it is posted.
>  
> The benefit of validating forms this way, is that you won't have to
> actually post the form to validate it.  You can have real-time
> validation (done with java) and not have to reload the page.  It looks
> like someone has already attempted to do this
> (http://getahead.ltd.uk/dwr/server/struts) although I'm not sure I'm
> totally sold on his approach.
>  
> -Stephan
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com

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


Re: Integrating AJAX into Struts

Posted by Martin Cooper <ma...@apache.org>.
On 11/10/05, Stephan Heilner <SH...@studeo.com> wrote:
>
> With all the momentum towards AJAX, has anyone started to undertake
> integrating AJAX into Struts. I think that it could be relatively easy
> using DWR (http://getahead.ltd.uk/dwr/). Here's how I'm thinking you
> could do it:
>
> Since Struts uses custom tag libraries for forms (ie <html:form>) you
> could change the JavaScript that it spits out to print out a JavaScript
> function.


In my "day job", we're just wrapping up a fairly large Struts app that's
heavily "AJAX"-enabled. We use the Commons Validator for client side
validation, and haven't found the need for any special integration with
Struts. It just works.

Now, if we were talking data binding, *that* is where I see a need / use for
integration. ;-)

--
Martin Cooper


So you'd go from :
> ------------------------------------------
> <form name="MyForm" action="postForm.do">
> ..
> <input type="submit" value="Submit" />
> </form>
>
>
>
> to:
> ------------------------------------
> <script language="JavaScript">
> function validate() {
>
> var myMap = new Object();
>
> myMap["prop1"] = DWRUtil.getValue("prop1");
> myMap["prop2"] = DWRUtil.getValue("prop2");
>
> StrutsDWRUtil.validate(fillForm, myMap, FORM_NAME);
>
> return false;
> }
>
> function fillForm(retMap) {
>
> if(retMap["errors"] != null) {
> DWRUtil.setValue("errors", retMap["errors"] );
> } else {
> document.MyForm.submit();
> }
> }
> </script>
> <form name="MyForm" action="postForm.do" onsubmit="return validate();">
> ..
> <input type="submit" value="Submit" />
> </form>
>
>
> The "StrutsDWRUtil" there is actually a java class and "validate()" is a
> java method. This could just call the existing validate method that is
> already being called (validation.xml and validate(request, response) to
> validate a form when it is posted.
>
> The benefit of validating forms this way, is that you won't have to
> actually post the form to validate it. You can have real-time
> validation (done with java) and not have to reload the page. It looks
> like someone has already attempted to do this
> (http://getahead.ltd.uk/dwr/server/struts) although I'm not sure I'm
> totally sold on his approach.
>
> -Stephan
>
>

Re: Integrating AJAX into Struts

Posted by Martin Cooper <ma...@apache.org>.
On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
>
> On 11/11/05, Martin Cooper <ma...@apache.org> wrote:
> > On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
> > > On 11/10/05, Martin Cooper <ma...@apache.org> wrote:
> > > > In my "day job", we're just wrapping up a fairly large Struts app
> that's
> > > > heavily "AJAX"-enabled. We use the Commons Validator for client side
> > > > validation, and haven't found the need for any special integration
> with
> > > > Struts. It just works.
> > >
> > > Struts client validator as it is, sucks in usability and page style.
> > > First, popup window lists errors, but does not pinpoint them on a
> > > page. Second, after you close popup, your errors are gone. And, when
> > > server verified complex business/persistence rules, it returns a page
> > > with embedded error messages that totally differ in style with popup
> > > window. Yucky.
> >
> > I agree with you that the default behaviour is, um, less than optimal.
> But
> > that can be worked around, which is what we have done. (It's icky, so
> I'm
> > not going to say how. ;)
>
> Looks icky, or coded icky?


Oh, it looks great - much better than the default.

If looks ok, then tell it! :-))


It's JavaScript. Any function can be hooked, or even replaced. That's all
I'm saying. Beyond that, I take the 5th. ;-)

--
Martin Cooper


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

Re: Integrating AJAX into Struts

Posted by Michael Jouravlev <jm...@gmail.com>.
On 11/11/05, Martin Cooper <ma...@apache.org> wrote:
> On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
> > On 11/10/05, Martin Cooper <ma...@apache.org> wrote:
> > > In my "day job", we're just wrapping up a fairly large Struts app that's
> > > heavily "AJAX"-enabled. We use the Commons Validator for client side
> > > validation, and haven't found the need for any special integration with
> > > Struts. It just works.
> >
> > Struts client validator as it is, sucks in usability and page style.
> > First, popup window lists errors, but does not pinpoint them on a
> > page. Second, after you close popup, your errors are gone. And, when
> > server verified complex business/persistence rules, it returns a page
> > with embedded error messages that totally differ in style with popup
> > window. Yucky.
>
> I agree with you that the default behaviour is, um, less than optimal. But
> that can be worked around, which is what we have done. (It's icky, so I'm
> not going to say how. ;)

Looks icky, or coded icky? If looks ok, then tell it! :-))

Michael.

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


Re: Integrating AJAX into Struts

Posted by Martin Cooper <ma...@apache.org>.
On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
>
> On 11/10/05, Stephan Heilner <SH...@studeo.com> wrote:
> > With all the momentum towards AJAX, has anyone started to undertake
> > integrating AJAX into Struts. I think that it could be relatively easy
> > using DWR (http://getahead.ltd.uk/dwr/). Here's how I'm thinking you
> > could do it:
> ...
> > The benefit of validating forms this way, is that you won't have to
> > actually post the form to validate it. You can have real-time
> > validation (done with java) and not have to reload the page.
>
> If you send data to the server, you send data to the server. The form
> _will_ be posted (or its data will be sent with GET, whatever), and
> the remote request will be made. The difference is in refreshing only
> portions of the page instead of reloading the whole page.
>
> If you want to do this when a user submits a form, this is a good
> thing, it reduces traffic. But I hope you don't want to do this in
> background, verifying data as the user types, this would be a horrible
> idea traffic-wise.
>
> I saw a very nice client-only script to validate simple things like
> numbers, dates, emails and is field is empty or not:
> http://www.themaninblue.com/writing/perspective/2005/10/05/form/form4.htm
>
> Combining the above with Ajax validation would be very-very nice.
> Someone on the list told me she was looking into that ;-)
>
> On 11/10/05, Martin Cooper <ma...@apache.org> wrote:
> > In my "day job", we're just wrapping up a fairly large Struts app that's
> > heavily "AJAX"-enabled. We use the Commons Validator for client side
> > validation, and haven't found the need for any special integration with
> > Struts. It just works.
>
> Struts client validator as it is, sucks in usability and page style.
> First, popup window lists errors, but does not pinpoint them on a
> page. Second, after you close popup, your errors are gone. And, when
> server verified complex business/persistence rules, it returns a page
> with embedded error messages that totally differ in style with popup
> window. Yucky.


I agree with you that the default behaviour is, um, less than optimal. But
that can be worked around, which is what we have done. (It's icky, so I'm
not going to say how. ;)

--
Martin Cooper


Struts client-side validator should be changed to use DOM and CSS to
> stick messages directly into the page, like in the link above. Ajax
> for making background request will be a logical addition to this. This
> will allow to blend client-only validation and server-side validation
> so user would not be able to tell the difference.
>
> Michael.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>

Re: Integrating AJAX into Struts

Posted by Hubert Rabago <hr...@gmail.com>.
On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
>
> You are right, multiwindow thing breaks this idea. Maybe I could
> introduce a flag "this formbean was submitted to" and remove only
> submitted beans. Or flag "this form bean was processed"... Got a
> better idea by any chance?

Sorry, I don't.  I gave up on that a long time ago.  I just tried to
reduce my use of session variables.  :)

Hubert

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


Re: Integrating AJAX into Struts

Posted by Michael Jouravlev <jm...@gmail.com>.
On 11/11/05, Hubert Rabago <hr...@gmail.com> wrote:
> On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
> > > > I added a "scenario" attribute to <action> element, and on each
> > > > request I am going to check session and to clean all form beans that
> > > > do not correspond to action's scenario ("scenario" attribute can
> > > > enlist several scenarios that action participates in). It would be
> > > > simpler to define scenario for <form-bean> themselves, but I think it
> > > > is easier for developer to think in terms of grouped actions, not
> > > > grouped forms.
> > >
> > > What happens if the user uses multiple windows?
> >
> > Nothing different from having multiple windows of a regular action
> > with session-scoped form. As long as action was called, form is used,
> > so no reason to dispose it. Or am I missing something?
> >
> Say I have Window A doing Scenario A.  From there I open up another
> window and for whatever reason end up exploring Scenario B.  If I
> submit either window, the one I didn't submit gets its session object
> hosed.

You are right, multiwindow thing breaks this idea. Maybe I could
introduce a flag "this formbean was submitted to" and remove only
submitted beans. Or flag "this form bean was processed"... Got a
better idea by any chance?

On 11/11/05, Hubert Rabago <hr...@gmail.com> wrote:
> On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
> > It is hard for people to use a library
> > if it is not endorsed by Struts dev team, and even behaves in a
> > different manner? Even harder for them to make a mind shift.
>
> This is what I'm talking about.  It's a matter of, uhm, "marketing".
> With Eclipse, they made it so using plugins is not only accepted, but
> expected.  Why should it be different with Struts?

Actually, that would be a great new idea for Struts. I would support
it. Considering that 1.3 codebase should be much more flexible in
terms of plugins, that should work.

Michael.

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


Re: Integrating AJAX into Struts

Posted by Hubert Rabago <hr...@gmail.com>.
On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
> > > I added a "scenario" attribute to <action> element, and on each
> > > request I am going to check session and to clean all form beans that
> > > do not correspond to action's scenario ("scenario" attribute can
> > > enlist several scenarios that action participates in). It would be
> > > simpler to define scenario for <form-bean> themselves, but I think it
> > > is easier for developer to think in terms of grouped actions, not
> > > grouped forms.
> >
> > What happens if the user uses multiple windows?
>
> Nothing different from having multiple windows of a regular action
> with session-scoped form. As long as action was called, form is used,
> so no reason to dispose it. Or am I missing something?
>
> Michael.

Say I have Window A doing Scenario A.  From there I open up another
window and for whatever reason end up exploring Scenario B.  If I
submit either window, the one I didn't submit gets its session object
hosed.

Hubert

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


Re: Integrating AJAX into Struts

Posted by Michael Jouravlev <jm...@gmail.com>.
On 11/11/05, Hubert Rabago <hr...@gmail.com> wrote:
> On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
> > Please keep this in mind
> > if you will work on action/form combo :)
>
> Why not make sure by taking a look at what I'm doing and maybe working
> on it, too?
>
> Oh, waitasec, I've no plans yet of nominating what I'm doing into the
> core, so if that's a requirement for you, well, I understand.

Riiight. I guess this will not cut it then. :-) Actually, I would like
to take a look :-)

> > I added a "scenario" attribute to <action> element, and on each
> > request I am going to check session and to clean all form beans that
> > do not correspond to action's scenario ("scenario" attribute can
> > enlist several scenarios that action participates in). It would be
> > simpler to define scenario for <form-bean> themselves, but I think it
> > is easier for developer to think in terms of grouped actions, not
> > grouped forms.
>
> What happens if the user uses multiple windows?

Nothing different from having multiple windows of a regular action
with session-scoped form. As long as action was called, form is used,
so no reason to dispose it. Or am I missing something?

Michael.

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


Re: Integrating AJAX into Struts

Posted by Hubert Rabago <hr...@gmail.com>.
On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
> Please keep this in mind
> if you will work on action/form combo :)

Why not make sure by taking a look at what I'm doing and maybe working
on it, too?

Oh, waitasec, I've no plans yet of nominating what I'm doing into the
core, so if that's a requirement for you, well, I understand.

> I added a "scenario" attribute to <action> element, and on each
> request I am going to check session and to clean all form beans that
> do not correspond to action's scenario ("scenario" attribute can
> enlist several scenarios that action participates in). It would be
> simpler to define scenario for <form-bean> themselves, but I think it
> is easier for developer to think in terms of grouped actions, not
> grouped forms.

What happens if the user uses multiple windows?

Hubert

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


Re: Integrating AJAX into Struts

Posted by Wendy Smoak <ws...@gmail.com>.
On 11/11/05, Hubert Rabago <hr...@gmail.com> wrote:

> Well, I don't know if any other committer has ever used FormDef.  Some
> of them haven't even heard of it before.  It hasn't stopped people
> from using it, though.

I had never even heard of it until very recently.  You need to
advertise more. :)

--
Wendy

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


Re: Integrating AJAX into Struts

Posted by Hubert Rabago <hr...@gmail.com>.
On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
>
> I don't agree with you.

I don't mind agreeing to disagree. :)

> Eclipse is an empty hangar, which can be
> filled up with tools, benches and other machinery. You use each
> machine as it is supposed to be used, and you use the hangar just to
> transport parts from one machine to another, or to provide some basic
> stuff like electricity, ventilation, etc.

Actually, Eclipse already comes with plenty.  The plugins make a
difference, of course.  If I had to use Eclipse, I would at least use
it with plugins.  Some people have to use Struts.  Plugins might make
their experience more pleasant, so why not use them?

> Struts is not a container, it is a framework. It not only provides
> features, it imposes a certain way of using them. For example, Struts
> Dialogs is an add-on library, but it uses Struts in a way kinda
> opposite to "official" rules.

A framework can't anticipate every need users will have.  If someone
needed functionality that Struts Dialogs provided, why not use it?

> It is hard for people to use a library
> if it is not endorsed by Struts dev team, and even behaves in a
> different manner? Even harder for them to make a mind shift.

This is what I'm talking about.  It's a matter of, uhm, "marketing". 
With Eclipse, they made it so using plugins is not only accepted, but
expected.  Why should it be different with Struts?

> Speaking
> about me, I want not just to provide an add-on library for Struts, but
> to change the way Struts applications are written. Yep, I am that
> arrogant :-) I cannot do this simply providing an add-on.

Sure you can.  The add-on I'm playing with right now would allows me
to have a POJO action by replacing two Commands on chain-config.xml
and adding a third one to put the ActionContext in a ThreadLocal
variable.

Then a fourth one to populate said Action (POJO or not) with values
from the form bean to make it look like WebWork.

That's an 18 kb jar file, but a big change in how you can write your
Struts action classes.

> The problem
> here, that I need to convince core devs themselves that my approach is
> better ;-)

An add on that's independent of the main distro but is used by a lot
of people can be pretty convincing.  :)

> Same with other core technologies like flow. HTML2 is on a fence,
> maybe better suited for an add-on. FormDef somewhat changes the usage
> of forms too, so it has to be officially endorsed for users to ebrace
> it. At least as an optional way, if not the "one and only" proper way.

Well, I don't know if any other committer has ever used FormDef.  Some
of them haven't even heard of it before.  It hasn't stopped people
from using it, though.

Hubert

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


Re: Integrating AJAX into Struts

Posted by Michael Jouravlev <jm...@gmail.com>.
On 11/11/05, Hubert Rabago <hr...@gmail.com> wrote:
> On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
> >
> > Oops, am I blind or what? Hubert, this is awesome! Thanks a
> > bunch, I would like to, er..., purloin this stuff for my use :-)
>
> Sure, have fun!  Be aware though that there's a lot of, uhm,
> "opportunities for improvement" here.  I've already thought of a few
> the past week.  (There's some that are shouting very loudly in my mind
> right now.)

I will try. I even got a book on Javascript :) (never used it before).

> > Stuff like this should be included in the Core ;-)
>
> Uhm, well no.  Read the disclaimers.  :)
>
> <rant>
> I keep hoping that I can find a way for people to get more comfortable
> about using extras that don't come with the Struts download.  Sure
> there are some lost causes out there, such as those whose bosses don't
> even want them to use the EL tags because they're not part of "The
> Distribution".  However, one of the big plusses of Struts is the
> amount of third party libraries that support it.
>
> I mean, c'mon, people say great things about Eclipse, saying its
> plugins make it very powerful.  And JSF gets praise for being highly
> extensible.  So how come we don't take advantage of the Struts plugins
> and extensions?
> </rant>

I don't agree with you. Eclipse is an empty hangar, which can be
filled up with tools, benches and other machinery. You use each
machine as it is supposed to be used, and you use the hangar just to
transport parts from one machine to another, or to provide some basic
stuff like electricity, ventilation, etc.

Struts is not a container, it is a framework. It not only provides
features, it imposes a certain way of using them. For example, Struts
Dialogs is an add-on library, but it uses Struts in a way kinda
opposite to "official" rules. It is hard for people to use a library
if it is not endorsed by Struts dev team, and even behaves in a
different manner? Even harder for them to make a mind shift. Speaking
about me, I want not just to provide an add-on library for Struts, but
to change the way Struts applications are written. Yep, I am that
arrogant :-) I cannot do this simply providing an add-on. The problem
here, that I need to convince core devs themselves that my approach is
better ;-)

Same with other core technologies like flow. HTML2 is on a fence,
maybe better suited for an add-on. FormDef somewhat changes the usage
of forms too, so it has to be officially endorsed for users to ebrace
it. At least as an optional way, if not the "one and only" proper way.

> Whoo.  Sorry.  I think that got built up for some time now.

Don't tell me :-)

> Of course, now my time is going to this other thing we talked about a
> few weeks before:
> http://marc.theaimsgroup.com/?l=struts-dev&m=112930650012896&w=2

I started to look into garbage collector for forms. POJO or not, we
should have something, that works as a container for all data used by
action, be it ActionForm or a regular Java class, implementing a
certain interface. We need to be able to easily and reliably locate
these input/output containers to manage them. Please keep this in mind
if you will work on action/form combo :)

I added a "scenario" attribute to <action> element, and on each
request I am going to check session and to clean all form beans that
do not correspond to action's scenario ("scenario" attribute can
enlist several scenarios that action participates in). It would be
simpler to define scenario for <form-bean> themselves, but I think it
is easier for developer to think in terms of grouped actions, not
grouped forms.

Michael.

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


Re: Integrating AJAX into Struts

Posted by Hubert Rabago <hr...@gmail.com>.
On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
>
> Oops, am I blind or what? Hubert, this is awesome! Thank a
> bunch, I would like to, er..., purloin this stuff for my use :-)

Sure, have fun!  Be aware though that there's a lot of, uhm,
"opportunities for improvement" here.  I've already thought of a few
the past week.  (There's some that are shouting very loudly in my mind
right now.)

> In your samples actionFormDemo.do does ajax only, while
> validatorDemo.do and customHandlingDemo.do perform client javascript
> and then submit the form (non-ajax). I believe that both approaches
> can be combined easily, so after client verified some basic rules, the
> form would be sent to server in separate request and if something is
> wrong, the errors will be displayed with ajax, right?

Yup.

> Stuff like this should be included in the Core ;-)

Uhm, well no.  Read the disclaimers.  :)

<rant>
I keep hoping that I can find a way for people to get more comfortable
about using extras that don't come with the Struts download.  Sure
there are some lost causes out there, such as those whose bosses don't
even want them to use the EL tags because they're not part of "The
Distribution".  However, one of the big plusses of Struts is the
amount of third party libraries that support it.

I mean, c'mon, people say great things about Eclipse, saying its
plugins make it very powerful.  And JSF gets praise for being highly
extensible.  So how come we don't take advantage of the Struts plugins
and extensions?
</rant>

Whoo.  Sorry.  I think that got built up for some time now.

Anyway, like I said when I first announced this thing.  I wouldn't
mind continuing to work on this add-on if people wanted.

Of course, now my time is going to this other thing we talked about a
few weeks before:
http://marc.theaimsgroup.com/?l=struts-dev&m=112930650012896&w=2

(It's funny.  At that time I said "yeah, but I'm working on this
Struts+AJAX thing right now".)

Hubert

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


Re: Integrating AJAX into Struts

Posted by Michael Jouravlev <jm...@gmail.com>.
On 11/11/05, Hubert Rabago <hr...@gmail.com> wrote:
> On 11/11/05, Michael Jouravlev <jm...@gmail.com> wrote:
> > I saw a very nice client-only script to validate simple things like
> > numbers, dates, emails and is field is empty or not:
> > http://www.themaninblue.com/writing/perspective/2005/10/05/form/form4.htm
> >
> > Combining the above with Ajax validation would be very-very nice.
> > Someone on the list told me she was looking into that ;-)
>
> Hey, didn't I say I already did?  Check out html2.  It does just that.
>  I even prepared the demo for you.  Works with or without Validator.

Oops, am I blind or what? Hubert, this is awesome! Thank a bunch, I
would like to, er..., purloin this stuff for my use :-)

> > Struts client-side validator should be changed to use DOM and CSS to
> > stick messages directly into the page, like in the link above. Ajax
> > for making background request will be a logical addition to this. This
> > will allow to blend client-only validation and server-side validation
> > so user would not be able to tell the difference.
>
> Yup.  Works just like that.

In your samples actionFormDemo.do does ajax only, while
validatorDemo.do and customHandlingDemo.do perform client javascript
and then submit the form (non-ajax). I believe that both approaches
can be combined easily, so after client verified some basic rules, the
form would be sent to server in separate request and if something is
wrong, the errors will be displayed with ajax, right?

I will play with it, but it looks great, thanks again! Stuff like this
should be included in the Core ;-)

Michael.

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


Re: Integrating AJAX into Struts

Posted by Michael Jouravlev <jm...@gmail.com>.
On 11/10/05, Stephan Heilner <SH...@studeo.com> wrote:
> With all the momentum towards AJAX, has anyone started to undertake
> integrating AJAX into Struts.  I think that it could be relatively easy
> using DWR (http://getahead.ltd.uk/dwr/).  Here's how I'm thinking you
> could do it:
...
> The benefit of validating forms this way, is that you won't have to
> actually post the form to validate it.  You can have real-time
> validation (done with java) and not have to reload the page.

If you send data to the server, you send data to the server. The form
_will_ be posted (or its data will be sent with GET, whatever), and
the remote request will be made. The difference is in refreshing only
portions of the page instead of reloading the whole page.

If you want to do this when a user submits a form, this is a good
thing, it reduces traffic. But I hope you don't want to do this in
background, verifying data as the user types, this would be a horrible
idea traffic-wise.

I saw a very nice client-only script to validate simple things like
numbers, dates, emails and is field is empty or not:
http://www.themaninblue.com/writing/perspective/2005/10/05/form/form4.htm

Combining the above with Ajax validation would be very-very nice.
Someone on the list told me she was looking into that ;-)

On 11/10/05, Martin Cooper <ma...@apache.org> wrote:
> In my "day job", we're just wrapping up a fairly large Struts app that's
> heavily "AJAX"-enabled. We use the Commons Validator for client side
> validation, and haven't found the need for any special integration with
> Struts. It just works.

Struts client validator as it is, sucks in usability and page style.
First, popup window lists errors, but does not pinpoint them on a
page. Second, after you close popup, your errors are gone. And, when
server verified complex business/persistence rules, it returns a page
with embedded error messages that totally differ in style with popup
window. Yucky.

Struts client-side validator should be changed to use DOM and CSS to
stick messages directly into the page, like in the link above. Ajax
for making background request will be a logical addition to this. This
will allow to blend client-only validation and server-side validation
so user would not be able to tell the difference.

Michael.

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