Most of my page navigation uses get requests and now I have a form where the parameters should be included as query-string parameters using f:param
inside h:commandButton
or checking attributes for includeViewParams
to use UIViewParameter
.
I do not want to use includeViewParams
since this would include all view defined parameters, I just want to use the ones provided as child's of the command component.
<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();
}
This logic is not really complicated but it seems so redundant since it seems to be the same logic as in h:link
and h:button
.
So does someone knows where this logic is implemented?