我有一个包含以下参数的页面:
<f:metadata>
<f:event type="preRenderView" listener="#{busquedaBean.init}" />
<f:viewParam name="k" value="#{busquedaBean.keyword}" />
<f:viewParam name="categoryId" value="#{busquedaBean.categoryId}" />
<f:viewParam name="minprice" value="#{busquedaBean.minPrice}" />
<f:viewParam name="maxprice" value="#{busquedaBean.maxPrice}" />
</f:metadata>
所有这些都是可选的。我需要做两件事,到目前为止我无法做到:
1)添加新的参数(保留以前的参数)。这是我尝试添加价格参数的原因:
<h:outputText value="Precio diario" />
<o:form includeRequestParams="true">
<h:outputText value="min: " />
<p:inputText id="min" value="#{busquedaBean.minPrice}" />
<h:outputText value="max: " />
<p:inputText id="max" value="#{busquedaBean.maxPrice}" />
<p:commandButton icon="ui-icon-search" ajax="false">
<f:param name="minprice" value="#{busquedaBean.minPrice}" />
<f:param name="maxprice" value="#{busquedaBean.maxPrice}" />
</p:commandButton>
</o:form>
这基本上有效,但问题是URL没有更新。如果URL中的参数是?minprice = 10&amp; maxprice = 200并且我更新了这些值,则网址保持不变。如果这些参数不包含在网址中,则不会添加它们,过滤器将无法使用。
2)更新param的值: 当categoryId不为空时,我想显示一个清除此参数的按钮。这就是我试过的:
<p:button outcome="/busqueda" includeViewParams="true" >
<f:param name="categoryId=" value="" />
</p:button>
但是这个按钮对这个URL进行了GET:/ busqueda /?categoryId =%3D&amp; categoryId = 1 categoryId参数出现两次。我怎样才能更新现有的参数?
我正在使用MyFaces 2.1.14,Tomcat 7,Primefaces 4.0,Omnifaces
谢谢!
答案 0 :(得分:0)
我是以错误的方式看着这个。 includeViewParams = true将使请求包含f:metadata中声明的所有参数与当前值。如果此值为null,则不包括该参数。
所以..添加价格参数:
<h:form >
<h:outputText value="$ " />
<p:inputText id="min" value="#{busquedaBean.minPrice}"/>
<h:outputText value=" a $ " />
<p:inputText id="max" value="#{busquedaBean.maxPrice}"/>
<p:commandButton icon="ui-icon-search" ajax="false" action="/busqueda?faces-redirect=true&includeViewParams=true" />
</h:form>
删除一个参数:
<p:commandButton action="#{busquedaBean.removeCategory}" ajax="false" icon="ui-icon-close" />
在支持bean中:
public String removeCategory() {
categoryId = null;
return "/busqueda?faces-redirect=true&includeViewParams=true";
}