gpt4 book ai didi

JSF URL 重写

转载 作者:行者123 更新时间:2023-12-04 02:23:58 28 4
gpt4 key购买 nike

我尝试在我的 JSF 应用程序中使用“重写”(http://ocpsoft.org/rewrite/)。

一切都很好,我已经创建了规则:

.addRule(Join.path("/profile/{pagename}-{id}/").to("/profile/{pagename}.xhtml?id={id}"))

一切正常,例如,当我转到/profile/viewpoll-101/时,我看到带有 id = 101 的 poll 的正确页面。所以,现在我想在 h:link jsf 元素中获得用户友好的链接。我正在尝试这个:
<h:link outcome="/profile/viewpoll-#{poll.id}/">
#{poll.title}
</h:link>

但是链接无效...

那么,如何在 h:link 中获得用户友好的链接?

谢谢!

最佳答案

使用 rewrite 无法做到这一点,只能使用 Prettyfaces。使用重写,您必须指定 JSF 标识符。

PrettyFaces shipped with a special JSF component that simplified creating links to mapped URLs. However JSF 2.0 introduced h:link, which works fine for creating such links. Rewrite doesn’t include any special JSF component. It is recomended to use the standard JSF component for rendering links.

Using h:link for creating links to Rewrite URLs is very easy. Just use the URL you configured as the to part of the Join for the outcome. If the URL contains parameters, set their value using f:param.


<h:link outcome="/customer-details.jsf">
<f:param name="id" value="123"/>
Show details
</h:link>
JSF 2 ,通过隐式导航,您可以使用它来访问/customer-details.jsp 或/customer-details.xhtml:
<h:link outcome="/customer-details">
<f:param name="id" value="123"/>
Show details
</h:link>
另见:
  • Creating JSF links with rewrite
  • Implicit Navigation in JSF 2
  • 关于JSF URL 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24529929/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com