aspose file tools*
The moose likes Struts and the fly likes another design problem with struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "another design problem with struts 2" Watch "another design problem with struts 2" New topic
Author

another design problem with struts 2

Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
i load up dataParams.jsp from main.jsp:

i map it in struts.xml:

and set up a DataParams-validator.xml.

The problem starts when i submit dataParams.jsp 's form:

because it's supposed to validate while beeing loaded by main.jsp, but it displays alone not included in main.jsp when it displays errors.
The key to this problem is what should i write in <form action="???" to make this work the way i aim?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm not really sure what you're asking. Forms should submit to the action and method name you want to process the submission. You have the "input" result mapped to the dataParams.jsp page--if that's not what you want to display then you should map the input result to something else.
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
If i dataParams action doesn't get called when dataParams submits, the struts 2 xml validation doesn't fire.
dataParams.jsp is supposed to be always included in main.jsp though, showing errors or not,
but if i call main action, the struts 2 xml validation is always bypassed by the input action.
dataParams bypasses validation the first time because it doesn't need to validate when first shown (like in HelloWorld), should i validate from start and live with it?
Maybe action chaining would do it? I don't know...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Action chaining is even worse than using the <s:action> tag :(
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
What's bad about <s:action> tag?

EDIT:1 chaining is not good for me, it only needs to run when validation triggers. I think i'll go back to struts 1
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Struts 1 is even worse than action chaining.

(That one's actually debatable, but S2 is so much better than S1 it's not a very interesting debate.)

Using the action tag basically *is* action chaining, just not on the Java- or config-level. Besides a tricky "gotcha" that IIRC is related to I18N (I don't recall at this point), it ties up dependencies in a way that's arguably even worse than Java- or config-level chaining, because it's essentially invisible unless you happen to see it in the JSP. The possibility of unintended side effects is just too great, particularly since there are other ways to accomplish the same things.
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
ActionSupport ties everything togheter from what i can tell so far, interceptors, validation, resource bundles etc. W/o it there isn't much struts 2.
I'm having a tough time with struts 2's 'so much better'ness because:
1. I don't want to learn freemarker at this point, so, struts 2 default xml validation is pointless to me spouting the message where i don't want it to, where as struts 1 outputs the error message in the position i like; of course i can do jsp validation, but then what is struts 2 validation for if i can't use it in my web app.
2. I don't really need POJO's so far as action classes.
3. I don't see how can i come out of a design tight spot like this ATM (the mailing list question returned with "i can't" which i believe). If Struts 2 is so much better how come i end up using JSP's tags almost every time.
4. I don't see what the exact problem of struts 1 is, but its verbose configs kind of work for me.
5. So far looking at struts 1&2 i think it's often better to do JSP with servlets and Beans/POJOs as code behind for MVC.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

1. I don't want to learn freemarker at this point, so, struts 2 default xml validation is pointless to me spouting the message where i don't want it to, where as struts 1 outputs the error message in the position i like; of course i can do jsp validation, but then what is struts 2 validation for if i can't use it in my web app.

What does FreeMarker have to do with the validation? (Nothing.) So create a theme--the point of having extensible/modifiable themes is to avoid being locked in to the framework's idea of where you should put things. If learning even *than* much FreeMarker is too much, then I agree--Struts 2 is not for you.

2. I don't really need POJO's so far as action classes.

Nobody else does, either, at least for the most part (people exposing services are more likely to use the POJO functionality).

3. I don't see how can i come out of a design tight spot like this ATM (the mailing list question returned with "i can't" which i believe). If Struts 2 is so much better how come i end up using JSP's tags almost every time.

For that question I have no idea--I sure don't have to use S2 tags in that way, but I might be writing much larger applications that require some extensibility/maintainability than you are. For small apps like that I don't use *any* Java framework--Java's too bulky for easy stuff. At the least I'd consider using a different Java-based framework.

4. I don't see what the exact problem of struts 1 is, but its verbose configs kind of work for me.

Verbose configs are hardly the biggest issue with S1. Testability, extensibility, and maintainability, OTOH, are.

5. So far looking at struts 1&2 i think it's often better to do JSP with servlets and Beans/POJOs as code behind for MVC.

So do that then--nobody's making you use either framework.
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Thanks for the guidance but i only care for concrete solutions. Nobody is making you commenting my threads w/o coming up with a solution.
Please stop answering my questions if you're going to say "I sure don't have to use S2 tags in that way" and "...nobody's making you use either framework." This is a struts forum I asked about the problem with where default struts 2 validation puts the error message not the relation between FreeMarker and Struts 2 (which exists anyway). Also people don't learn struts to create something new but also maintain existing work. Also i'm using Java frameworks for once because i hope i would benefit for the much acclaimed maintainability of it that comes from templating (which seems to be the main concept of all these frameworks). I dreamed up a solution now that i realised struts 2 can be intermingled with struts 1 and servlets. Hopefully i can materialise it.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Themes exist *specifically* so that people can extend or modify them to suit their application's needs. There's no possible (or at least practical) way we can guess everybody's layout information--so we made it ridiculously easy to change it. The same way we do on the Java side--by abstracting functionality.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Thanks for the guidance but i only care for concrete solutions.

And what is "concrete solutions"??
Tudor Andrei Raneti wrote:5. So far looking at struts 1&2 i think it's often better to do JSP with servlets and Beans/POJOs as code behind for MVC.

Tudor Andrei Raneti wrote:Nobody is making you commenting my threads w/o coming up with a solution.Please stop answering my questions if you're going to say "I sure don't have to use S2 tags in that way" and "...nobody's making you use either framework." .....i'm using Java frameworks for once because i hope i would benefit for the much acclaimed maintainability of it that comes from templating

Doesn't your statements contradict with each other?? Earlier you were saying that its better to do JSP with servlets, and now you are saying that you want to use the features of a framework. If you make 5 points about how struts is not for you, then what is a person supposed to say?? Creating a theme to use struts is much better than handling all request parameters by hand, forwarding from servlets to JSP using request dispatcher, handling all validation by hand .....


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Don't know how it is where you live, but here bosses don't care if a framework can't do this or that, and they are partly right, if the framework can't do something, patch it up.

By a concrete solution i mean an example or steps to accomplish a solution to a given problem.

You only think they are conflicting when they are not, i wouldn't post questions in struts forum if i was going to use JSP/servlets. The advantage of struts frameworks is that it's suppose to make certain steps easier like internationalisation and write less code overall. As for themes vs markup, i understood the markup to put stuff where it should right away in struts, in fact i'm surprised the devs didn't leave an attribute for it. I don't have the time to learn it, and if i had, i'm still dismalled having to learn yet another paradigm to the already flawed paradigm of web developing of having at least 4 languages to do it.

Anyway themes are enforcing a way, whereas the key to success in something new is also leveraging the old way's advantages. Luckily struts 1, 2 and servlets(i think) can intermingle to supplement eachother. IMO struts 2 should've been to struts 1 and servlets what C++ is to C and assembly. I don't know what you meant by "riculously easy" also, from existing documentation there one could extract the logic do make things work like he wants to, but reading through several articles it still isn't clear where should i put the theme, and i know it would take a couple of days getting use to it.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Tudor Andrei Raneti wrote: Don't know how it is where you live, but here bosses don't care if a framework can't do this or that,

Believe me, bosses are the same here .
By a concrete solution i mean an example or steps to accomplish a solution to a given problem.

I couldn't provide a concrete solution because I couldn't understand your problem, what you exactly want and why you need to use s:action tag to achieve it. I think David understood your problem and he provided you with the correct way of doing it...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: another design problem with struts 2