[Enhancement] Autocomplete: Add FacesEvent to onComplete

UI Components for JSF
Post Reply
bayer-dba
Posts: 45
Joined: 19 Dec 2011, 18:07
Location: Hesse, Germany

10 Apr 2012, 11:37

Hi folks,
we are currently migrating to PrimeFaces and we encountered an issue at the moment with the autocomplete component. The problem is, that only the query string is passed to the oncomplete-method as seen in the following source code snippet of PrimeFaces.

AutoComplete.java

Code: Select all

public void broadcast(javax.faces.event.FacesEvent event) throws javax.faces.event.AbortProcessingException {
		super.broadcast(event);
		
		FacesContext facesContext = FacesContext.getCurrentInstance();
		MethodExpression me = getCompleteMethod();
		
		if(me != null && event instanceof org.primefaces.event.AutoCompleteEvent) {
			suggestions = (List) me.invoke(facesContext.getELContext(), new Object[] {((org.primefaces.event.AutoCompleteEvent) event).getQuery()});
...
The point is, that we need to pass some external values into the oncomplete method which are needed to return the correct suggestions.
Consider the following: There are several autocomplete components on the mask. Each one stands for a different data group, but the backend logic is always the same (same oncomplete method). In the markup it's possible to tell the component which is the relevant group key; a group key can be understood as "Barca, Real, Munich". So by switching on the group key value in the oncomplete method you'd be able to deliver the players for the desired club.

Using IceFaces this was possible by adding some f:attributes to their autocomplete component and later on fetch these values from the FacesEvent. I figured out that the AutoCompleteEvent contains my attributes but I'm not able to read them since the event is "thrown away" during the reflection.

So, could it be possible to add an option (addEvent, e.g.) to enable something like this: myBean.oncomplete(org.primefaces.event.AutoCompleteEvent event)? I'd still am able to fetch the query and in addition access my attributes:

enhancement AutoComplete.java

Code: Select all

		
		if(me != null && event instanceof org.primefaces.event.AutoCompleteEvent) {
			suggestions = (getAddEvent()) ? (List) me.invoke(facesContext.getELContext(), new Object[] {(org.primefaces.event.AutoCompleteEvent) event) : (List) me.invoke(facesContext.getELContext(), new Object[] {((org.primefaces.event.AutoCompleteEvent) event).getQuery()});
...
Thanks in advance for any replies, workarounds, thoughts or whatever. :)

Regards Dennis
JBoss 6.2.2; Mojarra 2.1.7; PrimeFaces 3.5 | JBoss 6.2.2; Mojarra 2.2.8; PrimeFaces 5.1.2

bayer-dba
Posts: 45
Joined: 19 Dec 2011, 18:07
Location: Hesse, Germany

11 Apr 2012, 10:46

Hi there,
I figured out a workaround:

handleComplete(String s)

Code: Select all

AutoComplete autoComplete = (AutoComplete) UIComponent.getCurrentComponent(FacesContext.getCurrentInstance());
Map<String, Object> attributes = autoComplete.getAttributes();
It's possible to read the f:attributes which were attached to the autocomplete component. However, it would be a cleaner approach to provide the event, wouldn't it? In addition you'd save the execution time of getCurrentCompoent().
JBoss 6.2.2; Mojarra 2.1.7; PrimeFaces 3.5 | JBoss 6.2.2; Mojarra 2.2.8; PrimeFaces 5.1.2

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 24 guests