如何在dataList项目链接中使用PrettyFaces?
<p:dataList value="#{mybean.cities}" var="city">
<h:link outcome="pretty:goCity">
TEXT
<f:param name="city" value="#{city.city}" />
<f:param name="cityId" value="#{city.id}" />
</h:link>
</p:dataList>
这是我的漂亮配置:
<url-mapping id="goCity">
<pattern value="/#{cityId:city.id}/#{city:city.city}" />
<view-id value="/page.xhtml" />
</url-mapping>
我收到了这个错误:
com.ocpsoft.pretty.PrettyException: PrettyFaces: Exception occurred while processing <goCity:#{city.id}> for URL </144/London>
com.ocpsoft.pretty.faces.beans.ParameterInjector.injectPathParams(ParameterInjector.java:96)
com.ocpsoft.pretty.faces.beans.ParameterInjector.injectParameters(ParameterInjector.java:54)
com.ocpsoft.pretty.faces.event.PrettyPhaseListener.afterPhase(PrettyPhaseListener.java:98)
com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:189)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:107)
com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)
com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:110)
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'city' resolved to null
org.apache.el.parser.AstValue.getTarget(AstValue.java:98)
org.apache.el.parser.AstValue.getType(AstValue.java:82)
org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:176)
com.ocpsoft.pretty.faces.util.FacesElUtils.getExpectedType(FacesElUtils.java:50)
com.ocpsoft.pretty.faces.beans.ParameterInjector.injectPathParams(ParameterInjector.java:79)
com.ocpsoft.pretty.faces.beans.ParameterInjector.injectParameters(ParameterInjector.java:54)
com.ocpsoft.pretty.faces.event.PrettyPhaseListener.afterPhase(PrettyPhaseListener.java:98)
com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:189)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:107)
com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)
com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:110)
答案 0 :(得分:1)
您的设置看起来绝对正确。似乎<p:dataList>
与<h:dataTable>
或<ui:repeat>
完全不同。
您可以尝试使用以下内容替换组件:
<ul>
<ui:repeat var="city" value="#{mybean.cities}">
<li>
<h:link outcome="pretty:goCity">
TEXT
<f:param name="city" value="#{city.city}" />
<f:param name="cityId" value="#{city.id}" />
</h:link>
</li>
</ui:repeat>
</ul>
或使用<pretty:link>
代替<h:link>
:
<ul>
<ui:repeat var="city" value="#{mybean.cities}">
<li>
<pretty:link mappingId="goCity">
TEXT
<f:param name="city" value="#{city.city}" />
<f:param name="cityId" value="#{city.id}" />
</pretty:link>
</li>
</ui:repeat>
</ul>