aspose file tools*
The moose likes Struts and the fly likes Avoiding html forms in a struts application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Avoiding html forms in a struts application" Watch "Avoiding html forms in a struts application" New topic
Author

Avoiding html forms in a struts application

Joe May
Greenhorn

Joined: Sep 28, 2009
Posts: 22
Hello,

I was just wondering if there is anyway to design a struts application without using html forms. Any kind of pointers towards such a design would be greatly appreciated

Thanks a ton,
Mec
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Sure, just don't use any forms.

That seems like a really bizarre thing to ask, though.
Joe May
Greenhorn

Joined: Sep 28, 2009
Posts: 22
Hi David,

Lets say I have a normal 3 tier application - model ,view and controller. If I do not use forms, how would i pass data without a form submit from my view to my controller? Basically I am trying to make the app totally ajax driven and avoid form submits. But where would I store the data? Only thing I can think of is Http session. Is that advisable. Would it not be unneccessary use of memory? Is it a bad design? and is there a better way?

Thanks
Mec
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Even Ajax submits are still form submits, they're just made via Ajax.
Joe May
Greenhorn

Joined: Sep 28, 2009
Posts: 22
Okay,

So are you telling me that If i load a jsp that doesnt contain a form, I will not be able to make a XmlHttpRequest from that page? Okay, I'll read up on that one.. But even then, lets say I load up all the data on the screen using my HttpRequest(I dont have a form bean) and I dont use forms... how will i get the data back in my controller?
Joe May
Greenhorn

Joined: Sep 28, 2009
Posts: 22
I dont have a concrete design in mind but this is wat i am kind of thinking of..

I'll have a Bean. say X.. it ll contain a list of AttributeVO objects... and AttributeVO will contain some member vars like label name,displayElementType, hidden,readonly,disabled etc.... basically all html attributes... And with this attributeVO, i ll draw my jsp.. but now.. i dont wanna use forms and submit it back.. sorry if i seem very confused.... its just a few ideas in mind... not taken shape yet..
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

mec fou wrote:So are you telling me that If i load a jsp that doesnt contain a form, I will not be able to make a XmlHttpRequest from that page?

Uh, no, I'm saying even an Ajax request with parameters is still a form submission, made via Ajax.
But even then, lets say I load up all the data on the screen using my HttpRequest(I dont have a form bean) and I dont use forms... how will i get the data back in my controller?

A request, either GET with params in the URL, or a POST. That's the *ONLY* way data gets back to the server--how else could it?

I think you need to do some background reading before you move forward much further--so far you're just describing a regular web app that's using Ajax, so I'm not sure where the issue is.
Joe May
Greenhorn

Joined: Sep 28, 2009
Posts: 22
Okay, this is the issue...
1) our application gets frequent changes.... and there are too many rules... like if one attribute is changed on a page, many other attributes have to change... like.. say i select a value from a drop down... it changes multiple things across the screen. So all these rules need a lot of hard coded JS code.
2) Implementing validations was quite a pain. We wanted the errors to show up on top of the screen and change the background color of the field that failed validations. All this was totally hard coded js code and the code now looks really complex and very difficult to modify.

I am just trying to implement a design that is gonna be as db driven as possible.. all the rules come from DB or something... and the application just reacts to all changes easily...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That seems completely unrelated to the Ajax part.

If this isn't Struts-related I'm going to move it to a different forum, I'm just not sure which one, because I have no idea what you're asking.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

You seem to have two topics going here:

1) Forms and Ajax are mutually exclusive (nonsense, by the way)

2) The on-page JavaScript is complex

Seems to me that both issues can be solved with the use of a full-features JavaScript library like jQuery, which allows you to vastly simplify on-page script, and to easily make form submits via Ajax.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Avoiding html forms in a struts application