AutoComplete: accept array as a value (in addition to List)
See original GitHub issue1) 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:
- Created 3 years ago
- Comments:26 (26 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @melloware , I will try to implement using
UISelectMany
in the next few days…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