0

I suspect about 2 way of passing value through attribute.

First: f:param

<p:inputText value="#{inputTextView.inputVal}">
    <f:param name="fieldA" value="inputA" />
    <p:ajax process="@form" update="@form"></p:ajax>
</p:inputText>

Second: custom field

<p:inputText value="#{inputTextView.inputVal}"
             fieldB="inputB">
    <p:ajax process="@form" update="@form"></p:ajax>
</p:inputText>

The first way, I can get value of attribute by using

FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("fieldA");

While the second way use

UIComponent.getCurrentComponent(FacesContext.getCurrentInstance()).getAttributes().get("fieldB");

Does anyone know what different between first and second?

What situation which appropriate for use the first approach?

Agie
  • 114
  • 1
  • 1
  • 7

1 Answers1

1

First of all, if you want to set a custom attribute, you cannot just add a random new attribute to a tag because JSF ignores unsupported tag attributes. BalusC gives some options on how to work around this in this answer.

f:param should be used if you want to add values to the query string or request parameters. It should be used with command components (e.g. h:commandButton, h:commandLink or h:outputLink).

f:attribute on the other hand, adds entries to the attribute Map of a component.

Community
  • 1
  • 1
yetti
  • 141
  • 1
  • 4