开发者

JSF2 URL GET parameter

开发者 https://www.devze.com 2023-04-01 23:02 出处:网络
It\'s easily possible with JSF2 to process GET requests with this annotations: <f:metadata> <f:viewParam name=\"id\" value=\"#{bean.id}\"/>

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

精彩评论

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