Jsf 2 来自表单提交的PrettyFaces url路由

Jsf 2 来自表单提交的PrettyFaces url路由,jsf-2,prettyfaces,Jsf 2,Prettyfaces,为了能够重用一些xhtml文件,我正在使用漂亮的面孔来进行URL重写。我希望像“/honda/index.xhtml”和“/toyota/index.xhtml”这样的URL都指向同一个/make/index.xhtml文件,make作为参数输入。此路由在以下配置下似乎可以正常工作: <url-mapping id="carMake"> <pattern value="/#{make}/index.xhtml"></pattern> <v

为了能够重用一些xhtml文件,我正在使用漂亮的面孔来进行URL重写。我希望像“/honda/index.xhtml”和“/toyota/index.xhtml”这样的URL都指向同一个/make/index.xhtml文件,make作为参数输入。此路由在以下配置下似乎可以正常工作:

<url-mapping id="carMake">
    <pattern value="/#{make}/index.xhtml"></pattern>
    <view-id value="/make/index.xhtml"/>
</url-mapping>
我尝试过不使用faces重定向参数,但得到了相同的结果


当我直接将/honda/search/index.xhtml放入浏览器时,为什么/honda/search/index.xhtml会起作用,而不是作为操作的结果?

您不能用漂亮的URL作为操作属性的值。您必须使用标准JSF结果,并将
make
作为查询参数

试试这个:

<h:commandButton value="search" 
           action="/honda/search/index.xhtml?faces-redirect=true&make=honda"/>


如果要将URL与视图ID分开,并且不想在应用程序中引用视图ID,则需要使用漂亮的导航字符串:

但这真的让事情变得比需要的更复杂了。我建议按照@chkal的建议去做,除非他的例子有点错误。应该是:


这应该包含在文档中:)检查该部分(以及下面的部分),看看是否有帮助

这是一个很好的答案,尽管不是我希望的答案,因为它违背了我希望从PrettyFaces中获得的目的。如果你想使用URL与视图ID分开,并且你不想在应用程序中引用视图ID,那么你需要使用漂亮的导航字符串:
,但这真的让事情变得比需要的更复杂了。我建议按照@chkal的建议去做,除非他的例子有点错误。应该是:
<h:form>
    <h:messages />
    <h:inputText id="searchTerm"/>
    <h:commandButton value="search" action="/honda/search/index.xhtml?faces-redirect=true"/>
</h:form>
09-23 11:39:55 DEBUG PrettyNavigationHandler:57 - Navigation requested: fromAction [/honda/search/index.xhtml?faces-redirect=true], outcome [/honda/search/index.xhtml?faces-redirect=true]
09-23 11:39:55 DEBUG PrettyNavigationHandler:60 - Not a PrettyFaces navigation string - passing control to default nav-handler
<h:commandButton value="search" 
           action="/honda/search/index.xhtml?faces-redirect=true&make=honda"/>