views:

46

answers:

1

I'm trying to make something simple with Stripes. I've read and heard a lot about easiness of using this framework and about steep learning curve (i.e. learning is quite fast and productive).

But till this moment I can't even create the simplest HelloWorld with Stripes.

All examples I've found demonstrate functionality like: "click on the link --> see the result". When we click on the link special handler is called (which returns Resolution) and after that getters also works (because bean is instantiated).

But if I don't want a link but I want simple static information (for example, when I open StackOverflow I don't need to click a link, but I immediately see a list of questions) then it's something non-trivial for Stripes as it seems to me, because bean is not instantiated immediately.

How to fix that? Are there some special annotation or another technique?

Have anyone here tried Stripes and met the same problem? I'm realy frustrated, maybe I've missed something..

UPD: it's probably not clear because I haven't appended any code. So I describe a bit more. In order to reproduce my situation it's enough to get the code from QuickStart and try to retrieve text from ActionBean getters (currently, text is hard-coded in jsp). The text will appear only after you press the button (i.e. after handler does some work). But after you open the page first time you won't see the text.

+4  A: 

Are you familiar with the MVC pattern( see http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller )? One of the key parts of the MVC is you never ever call the JSP directly. You don't go to www.myservername.com/myjsp.jsp. Instead, you go to www.myservername.com/mything.action. Stripes will do some processing, set some stuff, and then send you on to the specific JSP.

From your question, it just sounds like you are trying to go directly to JSPs. Stop doing that, and you will get along much nicer with stripes.

As for what happens when you just go to www.myservername.com, you go to the welcome-file in your web.xml. You do something like this

<welcome-file>index.jsp</welcome-file>

(yes you break the rule about no jsp directly)

Then in index.jsp you make it a 1 line file like so:

<jsp:forward page="myaction.action"/>

And the first time someone goes to your site, they hit index.jsp, which sends them to an action, which populates stuff and forwards them on. In no other cases will the user directly get to a jsp, and the index file is nothing but a forward to a real action.

bwawok
Thanks! I'll try it tomorrow. I didn't think about how MVC could work. My mistake seems obvious now, but I'm confused that nothing related was explaned in the book.
Roman
It works. If someone reads this thread and has the same problem, this thread http://stackoverflow.com/questions/725534/converting-a-stripes-application-to-use-friendly-urls can also help.
Roman
Roman, I'm not sure if it was addressed in the book, but the Stripes Best Practices page touches on it - http://www.stripesframework.org/display/stripes/Best+Practices. On the other hand, if you really did want to just link to something (out to stack overflow, whatever) you can use <stripes:link> for that purpose.
lucas
There is no need to use the <welcome-file> just map you're homepage actionbean with: @UrlBinding("/")
Kdeveloper