开发者

JSF2 URL GET parameter

It's easily possible with JSF2 to process GET requests with this annotations:

<f:metadata>
  <f:viewParam name="id" value="#{bean.id}"/>
  <f:viewParam name="name" value="#{bean.name}"/>
  <f:event type="preRenderView" listener="#{bean.init}" />
</f:metadata>

and the init method in my bean:

public void init(Compo开发者_StackOverflow社区nentSystemEvent e) throws AbortProcessingException {...}

This can be accessed with something like test.jsf?id=8012&name=name. Is it possible to use it like the @PathParam in REST and write the URL like test/8012/name?

PS: I know there is a term for this, but I cannot remember ....


The easiest way to accomplish this is by using PrettyFaces. You'll make a pretty-config.xml file that will look like this:

<url-mapping id="test">
  <pattern value="/test/#{id}/#{name}"/>
  <view-id value="/faces/test.jsf"/>
</url-mapping>

Really, it's dead simple. PF will inject path parameters into your managed beans and will even call an action afterwards if you like. I love it. :) The official documentation is probably everything you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜