formGroup for select element
parent
f4ee9d96b8
commit
de89b2c131
|
|
@ -23,9 +23,12 @@ import org.libreccm.ui.Message;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -118,6 +121,26 @@ public class CategoryDetailsModel {
|
||||||
return categoryOrder;
|
return categoryOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only for testing components
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Map<String, String> getOptions() {
|
||||||
|
final Map<String, String> options = new TreeMap<>();
|
||||||
|
options.put("alpha", "Option Alpha");
|
||||||
|
options.put("bravo", "Option Bravo");
|
||||||
|
options.put("charlie", "Option Charlie");
|
||||||
|
options.put("delta", "Option Delta");
|
||||||
|
options.put("echo", "Option Echo");
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getSelectedOptions() {
|
||||||
|
final Set<String> selectedOptions = new HashSet<>();
|
||||||
|
selectedOptions.add("delta");
|
||||||
|
return selectedOptions;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Message> getMessages() {
|
public List<Message> getMessages() {
|
||||||
return Collections.unmodifiableList(messages);
|
return Collections.unmodifiableList(messages);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:cc="http://xmlns.jcp.org/jsf/composite"
|
||||||
|
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
|
||||||
|
<cc:interface shortDescription="Component for a form group with a number input">
|
||||||
|
<cc:attribute name="help"
|
||||||
|
required="true"
|
||||||
|
shortDescription="A short description of the input field"
|
||||||
|
type="String" />
|
||||||
|
<cc:attribute name="inputId"
|
||||||
|
required="true"
|
||||||
|
shortDescription="The ID of the input field."
|
||||||
|
type="String" />
|
||||||
|
<cc:attribute name="label"
|
||||||
|
required="true"
|
||||||
|
shortDescription="The label of the input field."
|
||||||
|
type="String" />
|
||||||
|
<cc:attribute default="false"
|
||||||
|
name="multiple"
|
||||||
|
required="false"
|
||||||
|
shortDescription="Wether multiple options can be selected."
|
||||||
|
type="boolean" />
|
||||||
|
<cc:attribute name="name"
|
||||||
|
required="true"
|
||||||
|
shortDescription="The name of the input field. This is also the name which is used to send the value of the input to the server."
|
||||||
|
type="String" />
|
||||||
|
<cc:attribute name="options"
|
||||||
|
required="true"
|
||||||
|
shortDescription="The options for the select as Map with Strings as key and value . The keys of the Map is used for the value attribute of the option elements, the values of the map are used as content of the option elements"
|
||||||
|
type="java.util.Map" />
|
||||||
|
<cc:attribute default="false"
|
||||||
|
name="required"
|
||||||
|
shortDescription="Is the field required?"
|
||||||
|
required="false"
|
||||||
|
type="boolean" />
|
||||||
|
<cc:attribute default="#{java.util.Collections.emptySet()}"
|
||||||
|
name="selectedOptions"
|
||||||
|
required="false"
|
||||||
|
shortDescription="A collection of the keys of the selected options. The keys must be strings."
|
||||||
|
type="java.util.Collection" />
|
||||||
|
<cc:attribute default="1"
|
||||||
|
name="size"
|
||||||
|
shortDescription="Size of the select element."
|
||||||
|
required="false"
|
||||||
|
type="int" />
|
||||||
|
</cc:interface>
|
||||||
|
<cc:implementation>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="#{cc.attrs.inputId}">${cc.attrs.label}</label>
|
||||||
|
<select aria-describedby="#{cc.attrs.inputId}-help"
|
||||||
|
class="custom-select"
|
||||||
|
id="#{cc.attrs.inputId}"
|
||||||
|
multiple="#{cc.attrs.multiple ? 'multiple' : null}"
|
||||||
|
name="#{cc.attrs.name}"
|
||||||
|
required="#{cc.attrs.required}"
|
||||||
|
size="#{not empty cc.attrs.size ? cc.attrs.size : null}">
|
||||||
|
<c:forEach items="#{cc.attrs.options.entrySet()}" var="option">
|
||||||
|
<option selected="#{cc.attrs.selectedOptions.contains(option.key) ? 'selected' : null}"
|
||||||
|
value="#{option.key}">#{option.value}</option>
|
||||||
|
</c:forEach>
|
||||||
|
</select>
|
||||||
|
<small class="form-text text-muted"
|
||||||
|
id="#{cc.attrs.inputId}-help">
|
||||||
|
#{cc.attrs.help}
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</cc:implementation>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -94,6 +94,18 @@
|
||||||
inputId="textareatest"
|
inputId="textareatest"
|
||||||
name="textareatest"
|
name="textareatest"
|
||||||
rows="10" />
|
rows="10" />
|
||||||
|
<bootstrap:formGroupSelect help="Select Test 1"
|
||||||
|
label="choose an option"
|
||||||
|
inputId="selecttest1"
|
||||||
|
name="selecttest1"
|
||||||
|
options="#{CategoryDetailsModel.options}" />
|
||||||
|
<bootstrap:formGroupSelect help="Select Test 2"
|
||||||
|
label="choose an option"
|
||||||
|
inputId="selecttest2"
|
||||||
|
name="selecttest2"
|
||||||
|
options="#{CategoryDetailsModel.options}"
|
||||||
|
selectedOptions="#{CategoryDetailsModel.selectedOptions}"
|
||||||
|
size="3" />
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
<p>ToDo</p>
|
<p>ToDo</p>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue