aspose file tools*
The moose likes Struts and the fly likes struts 2 design problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts 2 design problem" Watch "struts 2 design problem" New topic
Author

struts 2 design problem

Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
I have this main page main.jsp in wich i want to s:include dataParams.jsp page, and togheter they render as one.
The problem is that dataParams.jsp uses some data from the database and i want to fetch that in the DataParams.class that extends ActionSupport that gets the data from a DAO.

How can i retrieve the data (an int) and passing as a param using something like this? lineCount is the int field of DataParams action class that backs dataParams.jsp but obviously i can't s:include an action, so what are my options?



Should i just call the DAO in the included jsp? Or can it still be done with a mapping?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'd re-architect. You'd doing logic that should be on the Java side in the JSP. Keep your JSPs as "stupid" as possible.
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
The Java side is either struts 2's actions, or servlets, which means going back to struts 1. Theoretically a s:include should process an action since th sLinclude returns only the rendered page (supposedly) - and that would clear all this problem up.

I think for pages that only use a minimum of database interaction i could use JSTL sql, and for heavy parameter pages and logic, a dispatcher servlet with a DAO respectively.

I rather do it struts 2 style if i'm using struts 2 though.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If you want to include an *action* then use the <s:action> tag and render the result.

If you're just trying to do *templating* then use the standard JSP templating, or SiteMesh, or Tiles, or whatever.

IMO you're putting code in the JSP that belongs on the Java side.

The original JSP, btw, was syntactically invalid (you tried to nest tags), not necessarily functionally broken.
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
This doesn't work:
main.jsp (http://localhost:8080/loto/main?dataParams=show)


struts.xml


What am i doing wrong this time? (no error shown, displays blank)

test.jsp (if it matters)
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You're not really giving much to go on. Is the action executing? Is there anything in the logs? Do you have logging at DEBUG level? What does the config-browser say?

SQL tags?!?!?!
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Found the problem, it seems that the problem is that i don't know to acces parameters with s:if, help? :


and this condition doesn't work (main.jsp):

, i tried alone and it this works:

,also tried with JSTL c:if and it works:
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Solved with (thanks for the s:action tip):

i have to say struts 2 documentation sucks big time.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Tudor Andrei Raneti wrote:i have to say struts 2 documentation sucks big time.

Any reason for this?? I think the struts 2 documentation is quite good...


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

Joined: Nov 29, 2009
Posts: 145
I am not the first to say it, in fact someone quite experimented in Java said it.
Besides that i read a lot on a lot of frameworks (for my level of experience).
In comparison to others, Struts 2 documentation is weak.
For instance i got the solution for this off someone's post or maillist, not from the documentation itself.
I even saw people complain about support from devs, although i don't ask for myself, i recognise that that will attract more developers to one or another framework.

Nothing personal though, i will still use it, i think it's an improvement over Struts 1. Unless i come upon a major downside... i hope not.

For example's sake, MSDN is the most comprehensive documentation there is (MS capital show off), too bad it's targeted mainly at the MS platforms.
Javadoc is good, although i pulled of examples from other sites more than i did with .NET
What i think Struts 2 should do is be more exhaustive on the subject and treat everything nuts and bolts style.
For example i would've espected to see the action tag's result sub-tag somewhere under configuration, not in result types. The definition - demonstration (example) pattern seems to always work, so it should always be used, exhaustively and right on the point, to not leave room to any ambiguities.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

For example i would've espected to see the action tag's result sub-tag somewhere under configuration, not in result types.

I beg to differ here, all the configuration elements are covered at together. That page has all the struts configuration elements.

I generally need struts tag reference to look up tag attributes. If you look at how many tutorials and references they have here, then I think its pretty good. And MS has their billions of dollars, still what apache is doing with collaborative efforts from individuals is pretty good. People pay for MS products, they have to have good documentation. Still MS doesn't have a good API reference like javadocs...
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Maybe i've been spoiled

I have the habit of glancing over the data searching for patterns i'm already used to, so i might miss a hyperlink if it's not the first thing it hits me when i'm glancing the documentation. Practically i espect to see only something like this in a config doc (with relevant design):
element list (short description) >
element (full pseudo/meta arrangement like the full description of a SQL command) >
full description (attr list (short description > full description with example)
generic example
also see: related functionality, guides, primers, cookbooks, etc
pretty much javadoc or MSDN

For me the experience has been less than usual, so i missed the result types the first time, got boggled reading about and got my answer in a chat room where i was pointed out. Also got boggled trying to use the old way to access the params, doc makers had bigger problems perhaps and forgot to add a direct example for us newbs (glancing about i couldn't make the relations - that's why direct examples of usual problems help a lot). I'm using pretty much everything you pointed at now, just that it's not always as easy as i espected to find one or two things, otherwise is good.

I fail at struts 2 documentation
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There *is* a simple example:

If you're on the Struts 2 page, follow the Getting Started link. Or skip a step and jump from the S2 home page directly to the Tutorials, where the first links are to a bootstrap example and a full S2/Spring2/JPA/AJAX example. It doesn't get a *whole* lot simpler than that.

The Guides page has what you'd expect: links to information about what every major component is, how it works, default configurations, and so on.

Considering how much you're paying for it I'd say you're getting a pretty good deal. Feel free to file a CLA and contribute more to the documentation--make the improvements you want. That's the beauty of open source. And its curse: it depends on the generosity, hard work, and time of "other" people, who do the work because they want to or use it themselves.
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Found the example i was speaking of in: http://struts.apache.org/2.1.8.1/docs/why-doesnt-the-if-tag-evaluate-params-properly.html
I never remember reading the FAQ on a framework i used, probably just for win32API because it was all organized as a large cookbook and named FAQ.

Again i would've espected that as an example directly in the OGNL guide or in the HelloWorld example for people to stumble upon. I'm not complaining about the whole documentation, just the issues i had with it and described. Also i don't search the link to give feedback because there's a high chance the effort would be wasted, only thing that ussually matters to programmers is getting their work and only theirs in there (ussually not generally). Criticism is not welcome. Although best kind of feedback is the forums, gives a good ideea what people are dealing with and provides answers as well.

Couldn't struts 2 devs evaluate the parameter name itself key versus values behind the scenes if it's a map? How would i know what index is a certain value in the same parameter map? In the end the user would have to do it with getParameterValues().

If i get a job using struts 2 i'll have the resources at hand to contribute (time and money), otherwise i don't deal/negociate with capitalism if i can.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Well, you're welcome for working on it even though I have a job that doesn't use it, then--money isn't a prime motivator for me, either. If it was, I wouldn't spend so much time on here answering people's questions, and listening to their criticism, for free.

It wouldn't make any sense to put that example in OGNL, since it's not an issue with OGNL. I don't believe the Hello, World example uses an include (and the point of Hello, World is to be simple: not to introduce edge cases. Even if it *does* use an include, that wouldn't be the appropriate place to add this information).

If you don't bother reporting documentation errors, then you shouldn't be surprised that the errors aren't found. I don't know how you expect to get the changes you seem to want if you're completely unwilling to provide even the modest input of providing feedback. Seems like you just want to take, without giving anything back, but perhaps I've just misunderstood you.
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
I see you are editing struts 2 documentation, where do people report issues?
for example on http://struts.apache.org/2.0.14/docs/ognl.html
http://www.ognl.org/ returns: Directory of /
Also i think it could do with a link to: http://www.opensymphony.com/ognl/html/LanguageGuide/apa.html
or: http://www.opensymphony.com/ognl/pdf/LanguageGuide.pdf
as i haven't found direct reference to OGNL logic operators in struts 2 OGNL docs.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Post comments on the page in question, or file a JIRA ticket against the documentation.

OGNL has its own documentation (which, before it changed, was linked to in the first sentence of the OGNL doc page, see [1]) and reproducing it in the S2 documentation would obviously be a Bad Idea.

[1] OGNL is now at http://www.opensymphony.com/ognl/. Can't log in to change it at the moment.
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Found how to post a comment, dunno about JIRA yet.
I said reference the OGNL documentation not reproduce
Also i would find it useful if i could post changes myself, i wrote documentation at my old workplace.
I find referencing the source useful for a number of reasons:
- people find it usefull to get info at the exact place they espect it to;
- referencing a link increases page rank as far as i know;
- through observation on the problems of people in forum, further examples can be added in the struts 2 documentation bundle, that complement OGNL (as long as it has an OGNL section).

I can find it motivating for two reasons:
- i would see the change get done (and not feel like doing something idle);
- i could mention i'm a struts 2 documentation contributor at a job interview (and increase the buzzness of my CV ).

Lastly i could upload the documentation i did as a sample, so how do i sign up as a contributor, please?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

You can find all the details in this FAQ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts 2 design problem