If you known rails, you must love its developer-friendly features such as params attribute in controller, the log of each request and so on.
Now, this project is trying to bring these features to
... [More]
JavaEE as possible as it can.
And there is one and only one rule: non-aggressive. Any apps can benefit from this project, regardless whether using any frameworks or not.
Now there are two filters, bring two rails-like features:
RailsLikeParamsFilter - create params in the request which contains the request params DebugFilter - log infos of each request to stdout
You just need to config these filters in web.xml, nothing else.Let's go...
RailsLikeParamsFilterif the request param is something like this:foo[]=xxx&foo[]=yyy&...we automatically convert it to List, and put it in HttpServletRequest, with name "foo"。 So you can take it back:
List list = request.getAttribute("foo")if the request param is something like this:foo[aaa]=xxx&foo[bbb]=yyy&...we automatically convert it to Map, and put it in HttpServletRequest, with name "foo"。 So you can take it back:
Map map = request.getAttribute("foo")Why is , because we can convert the value if possible
Value StringJava Class Integer numbers like 123Integer Float numbers like 123.45Double true/falseBoolean yyyy-MM-dd or yyyy/MM/dd or yyyy.MM.dd (like 1984-01-25) Date start by "l_",devided by ',' like l_1,2,3,4,5 List (recursion, numbers are also converted) start by "m_",entris devided by ',' and key-value devided by ':' like m_age:1,male:true Map (recursion, numbers are also converted)
After convertion, all these converted values are put in a Map, the key is remain the name of the orignal request name, and then put the map in the HttpServletRequest, with the name "params"
For example, given URL:
foo/bar.action?person[age]=25&person[male]=true&person[birthday]=1984-01-25&person[emails]=l_a@b.com,c@d.comIn your controller:
Map params = request.getAttribute("params");
Map person = params.get("person");
System.out.println(person);Then you get
{birthday=Wed Jan 25 00:00:00 CST 1984, emails=[a@b.com, c@d.com], age=25, male=true} Add the Flash ScopeLike RAILS' flash[:foo], now you can do similar thing in J2EE:
In your controller:
((Map)request.getSession().getAttribute("FLASH_SCOPE")).put("foo",value); In your view(normally this is a redirect page):
${FLASH_SCOPE.foo} Done! The rest is handled by the filter
Other bouns{queryString} => String of current request params, in request scope {root} => context path, in request scope {paramName} => String of each request params, in request scope if there is more than one param use the same name(like foo[] above), then they are splited in new params names like foo_0, foo_1, each for one value, and the orignal param's value is modified to "value0,value1,value2,..." .
Configration is just like normal filters
RailsLikeParamsFilter
jacky.lanlan.song.web.RailsLikeParamsFilter
add-flash-scope
false
RailsLikeParamsFilter
/*
DebugFilterThis is for debug purpose, just config it, and it can log lots of useful infomation to your stdout.
Configration
debug
jacky.lanlan.song.web.DebugFilter
showHeaders
false
showServletContextParams
false
debug
/*
There is one more init-param, exclude-url-pattern, take a regex String as value, it controlls which URLs the filter should not focus on, the default value is ".+(\.css|\.js|\.png|\.jpg|\.gif)$"
That's all for version 0.1, other features will be added ASAP. [Less]