f:param or f:attribute support ?

UI Components for JSF
Post Reply
moonblade.wolf
Posts: 48
Joined: 07 Dec 2010, 02:46

28 Jun 2011, 12:46

Hello !

I've read that the core JSF components support the f:param and f:attribute tag, in order to pass some values to the serverside for the enclosing UI Components.

There's a need for me to be able to do this for primefaces' autocomplete component,
so that the autocomplete method will be able to make use of the parameter supplied by the f:param or f:attribute.
I tried finding out ways to accomplish this, and found out that the complete method parameter is fixed and cannot take more arguments,
hence im thinking of using f:param or f:attribute.

Im use the 2.2.x version, and based on my experiment, i cant seem to get the f:param or the f:attribute working

Code: Select all

<p:autocomplete ...>
   <f:param name="myParam" value="xxxx" />
</p:autocomplete>
Is primefaces going to support this feature on the autocomplete component ?
Is there anyway i can find out which tags that support the parameters and those who dont ?


Thank you !

Alex_San
Posts: 4
Joined: 20 Jul 2011, 21:25

22 Jul 2011, 22:30

I have found that this works:

Code: Select all

<p:autoComplete id="autocomplete" completeMethod="#{pprBean.complete}" selectListener="#{pprBean.handleSelection}" onSelectUpdate="messages">
            <f:attribute name="inputHidden" value="hiddenValue"/>
</p:autoComplete>
and in my bean:

Code: Select all

public void handleSelection(SelectEvent event) {
        String hiddenValue = (String)event.getComponent().getAttributes().get("inputHidden");
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected:" + event.getObject().toString() + "hidden is: " + hiddenValue, null);

        FacesContext.getCurrentInstance().addMessage(null, message);
    }
Let us know if it works for you.

Alex
Primefaces 3.2, jBoss6

moonblade.wolf
Posts: 48
Joined: 07 Dec 2010, 02:46

23 Jul 2011, 19:02

Hi Alex !

Thanks for providing a working example.

But what i wanted was to be access this attribute from the autocomplete method which only accepts 1 parameter, which is the string value that is typed by the user.
Is it possible to access the attribute value of that component in the autocomplete method ?
I desperately tried something like FacesContext.getInstance().getAttributes().get("myAttributeKey") in vain. :lol:

moonblade.wolf
Posts: 48
Joined: 07 Dec 2010, 02:46

11 Aug 2011, 09:51

Finally i got it to work !

Code: Select all

	<p:autoComplete id="#{cc.attrs.id}" label="#{cc.attrs.label}"
		....
		completeMethod="#{filterableRaceAutocompleteBean.filterRace}">

		<f:attribute name="filter" value="#{cc.attrs.filter}" />

	</p:autoComplete>

Code: Select all

	public List<Dto> filterRace(String filterString) {
		String filterValue = (String) UIComponent.getCurrentComponent(FacesContext.getCurrentInstance()).getAttributes().get("filter");
		log.debug("filter string : " + filterString + ", with query filter of : " + filterValue);

		....

		return result;
	}

Alex_San
Posts: 4
Joined: 20 Jul 2011, 21:25

11 Aug 2011, 15:38

Thank you for posting this, it will come in handy for sure in the future!
Primefaces 3.2, jBoss6

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 32 guests