我的大部分页面导航都使用get请求,现在我有一个窗体,其中参数应该作为查询字符串参数使用f:param
在h:commandButton
之内或检查includeViewParams
的属性以使用UIViewParameter
。JSF - 从f:param和includeViewParams创建url查询字符串的内置方法
我不想使用includeViewParams
,因为这将包括所有视图定义的参数,我只想使用作为命令组件的子项提供的参数。
<h:form>
<p:inputText value="#{bean.value1}"/>
<p:selectOneMenu value="#{bean.value2}"/>
<p:commandButton action="#{utilBean.performActionParams(outcome)}">
<f:param name="key1" value="#{bean.value1}"/>
<o:param name="key1" value="#{bean.value2}" converter="#{bean.converter}/>
</p:commandButton>
</h:form>
public String performActionParams(final String outcome)
{
final UriBuilder uriBuilder = UriBuilder.fromPath(outcome);
final FacesContext context = FacesContext.getCurrentInstance();
final UIComponent component = UIComponent.getCurrentComponent(context);
for (final UIComponent child : component.getChildren())
if (child instanceof UIParameter)
{
final UIParameter param = (UIParameter) child;
if (!param.isDisable() && !StringUtils.isBlank(param.getName()))
{
final Object value = param.getValue();
if (value != null)
uriBuilder.queryParam(param.getName(), value);
}
}
return uriBuilder.build().toString();
}
这种逻辑是不是真的很复杂,但我觉得自己多余的,因为它似乎是同样的逻辑h:link
和h:button
。
那么有人知道这个逻辑在哪里实现?
真的不明白你的问题。这个检查在'RESTORE_VIEW'阶段完成,调用'ViewDeclarationLanguage.getViewMetadata()',在你的情况下将返回一个'ViewMetadata' **的实例,因为**你正在使用GET导航*和*你的目的地页面有' '。你的问题是什么?你想重写元数据处理? –
kolossus
jsf中的某处必须有从'h:link'内读取'f:param'的代码并创建一个目标uri。我编辑回答并发布了我的代码,它基本上是一种解决方法,并且与'h:link'一样,只是用于使用commandbutton。我只是觉得我的代码是多余的,因为jsf中的某个地方已经被编码了。 – djmj