question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AutoComplete: accept array as a value (in addition to List)

See original GitHub issue

1) Environment

  • PrimeFaces version: 8.0

2) Expected behavior

  • Accept String[] as a valid type for a value of the component

3) Actual behavior

throws java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class [Ljava.lang.String; (java.util.ArrayList and [Ljava.lang.String; are in module java.base of loader 'bootstrap')

Right now the following components accept an array as a valid type:

  • SelectCheckboxMenu
  • SelectManyCheckbox

But AutoComplete accept only List.

It has something about converting List to array in AutoCompleteRenderer:encodeMultipleMarkup, but I don’t know how to use it. Also, the result is stored as an array in decodeMultiple but then converted to List in validate method.

To solve the issue I extended AutoComplete class with the following methods:

private boolean isInputValueArray = false;

@Override
public Object getValue()
{
    Object value = super.getValue();

    if (value != null && value.getClass().isArray())
    {
        isInputValueArray = true;
        Object[] array = (Object[]) value;
        return Arrays.asList(array);
    }

    return value;
}

@Override
public void setValue(Object value)
{
    if (isInputValueArray && value instanceof List)
    {
        value = ((List<String>) value).toArray(new String[0]);
    }

    super.setValue(value);
}

I can create a PR, but I think there is a better way to do that. If you can help me, I will implement it.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:26 (26 by maintainers)

github_iconTop GitHub Comments

1reaction
astappievcommented, May 27, 2020

Hi @melloware , I will try to implement using UISelectMany in the next few days…

0reactions
Rapstercommented, Dec 9, 2020

Till we don’t have a clean way of supporting arrays and list, I’m against supporting more array stuff. It’s not because arrays are “old school” or anything like that, it’s just it results as ugly/messy code

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple array add in autocomplete - jquery - Stack Overflow
I want to add multiple array in autocomplete. I have added aTags but how can I add bTags ? var aTags = ["ask" ......
Read more >
AutoComplete - YUI Library
The AutoComplete widget provides a flexible, configurable, and accessible implementation of the AutoComplete design pattern, which offers suggestions or ...
Read more >
Places Autocomplete Service | Maps JavaScript API
Contains methods related to retrieving Autocomplete predictions. Load using the &libraries=places URL parameter. See Libraries in the Maps JavaScript API.
Read more >
JqueryUI - Autocomplete - Tutorialspoint
The autocomplete (options) method declares that an HTML <input> element must be managed as an input field that will be displayed above a...
Read more >
JQueryUIAutocomplete < System < Foswiki
Autocomplete, when added to an input field, enables users to quickly find and select from a pre-populated list of values as they type,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found