use of javax.faces.component.html.HtmlSelectOneMenu in project gdmatrix by gdmatrix.
the class QueryInstanceBean method addParameterComponent.
private void addParameterComponent(Query.Parameter parameter, String expression, HtmlPanelGroup exprPanelGroup) {
FacesContext context = FacesContext.getCurrentInstance();
String sql = parameter.getSql();
if (StringUtils.isBlank(sql)) {
String format = parameter.getFormat();
ValueBinding valueBinding;
if (Query.Parameter.DATE.equals(format)) {
HtmlCalendar calendar = new HtmlCalendar();
calendar.setId("input_" + id);
String expr = "#{queryInstanceBean." + expression + "['" + parameter.getName() + "']}";
valueBinding = context.getApplication().createValueBinding(expr);
calendar.setValueBinding("value", valueBinding);
calendar.setStyleClass("input_value date");
exprPanelGroup.getChildren().add(calendar);
} else {
HtmlInputText inputText = new HtmlInputText();
inputText.setId("input_" + id);
String expr = "#{queryInstanceBean." + expression + "['" + parameter.getName() + "']}";
valueBinding = context.getApplication().createValueBinding(expr);
inputText.setValueBinding("value", valueBinding);
inputText.setStyleClass("input_value");
String title = parameter.getDescription() == null ? parameter.getName() : parameter.getDescription();
inputText.setTitle(title);
inputText.setAlt(title);
inputText.setSize(parameter.getSize());
if (Query.Parameter.NUMBER.equals(format)) {
Application application = context.getApplication();
MethodBinding method = application.createMethodBinding("#{queryInstanceBean.validateNumber}", new Class[] { FacesContext.class, UIComponent.class, Object.class });
inputText.setValidator(method);
}
exprPanelGroup.getChildren().add(inputText);
}
Object value = valueBinding.getValue(context);
if (value == null) {
String defaultValue = parameter.getDefaultValue();
if (!StringUtils.isBlank(defaultValue)) {
valueBinding.setValue(context, String.valueOf(defaultValue));
}
}
} else // selectOneMenu
{
HtmlSelectOneMenu selectOneMenu = new HtmlSelectOneMenu();
selectOneMenu.setId("input_" + id);
String expr = "#{queryInstanceBean." + expression + "['" + parameter.getName() + "']}";
ValueBinding valueBinding = context.getApplication().createValueBinding(expr);
selectOneMenu.setValueBinding("value", valueBinding);
selectOneMenu.setStyleClass("input_value select");
id++;
UISelectItems uiSelectItems = new UISelectItems();
uiSelectItems.setId("items_" + id);
expr = "#{queryInstanceBean.parameterSelectItemsMap['" + parameter.getName() + "']}";
ValueBinding itemsValue = context.getApplication().createValueBinding(expr);
uiSelectItems.setValueBinding("value", itemsValue);
selectOneMenu.getChildren().add(uiSelectItems);
exprPanelGroup.getChildren().add(selectOneMenu);
}
}
use of javax.faces.component.html.HtmlSelectOneMenu in project gdmatrix by gdmatrix.
the class QueryInstanceBean method addOperatorComponents.
private void addOperatorComponents(Operator operator, HtmlPanelGroup exprPanelGroup) {
FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
ValueBinding valueBinding = context.getApplication().createValueBinding("expression #{queryInstanceBean.expressions['" + operator.getId() + "'].type}");
exprPanelGroup.setValueBinding("styleClass", valueBinding);
if (operator.getType().equals(Operator.ROOT)) {
addLabelComponents(selectedInstance.getQuery().getLabel(), "selectedInstance.globalParameterValuesMap", selectedInstance.getQuery().getGlobalParameters(), exprPanelGroup);
} else // other operators: and, or, nor
{
// add operator select box
id++;
HtmlSelectOneMenu selectMenu = new HtmlSelectOneMenu();
selectMenu.setId(operator.getType() + "_" + id);
selectMenu.setStyleClass("operator");
selectMenu.setOnchange("submit();");
String valueExpr = "#{queryInstanceBean.expressions['" + operator.getId() + "'].type}";
valueBinding = context.getApplication().createValueBinding(valueExpr);
selectMenu.setValueBinding("value", valueBinding);
ArrayList list = new ArrayList();
SelectItem item1 = new SelectItem();
item1.setDescription(Operator.AND);
item1.setValue(Operator.AND);
item1.setLabel(getQueryLabel(Operator.AND));
list.add(item1);
SelectItem item2 = new SelectItem();
item2.setDescription(Operator.OR);
item2.setValue(Operator.OR);
item2.setLabel(getQueryLabel(Operator.OR));
list.add(item2);
SelectItem item3 = new SelectItem();
item3.setDescription(Operator.NOR);
item3.setValue(Operator.NOR);
item3.setLabel(getQueryLabel(Operator.NOR));
list.add(item3);
id++;
UISelectItems selectItems = new UISelectItems();
selectItems.setId("si_" + id);
selectItems.setValue(list);
selectMenu.getChildren().add(selectItems);
exprPanelGroup.getChildren().add(selectMenu);
id++;
HtmlCommandButton button = new HtmlCommandButton();
button.setId("button_" + id);
MethodBinding method = application.createMethodBinding("#{queryInstanceBean.expressionWrappers['" + operator.getId() + "'].removeExpression}", new Class[0]);
button.setAction(method);
button.setImage("/common/misc/images/remove_expr.png");
button.setStyleClass("expr_button remove");
exprPanelGroup.getChildren().add(button);
}
id++;
HtmlPanelGroup subPanelGroup = new HtmlPanelGroup();
subPanelGroup.setId("comp_" + id);
subPanelGroup.setStyleClass("op_children");
exprPanelGroup.getChildren().add(subPanelGroup);
for (Expression expr : operator.getArguments()) {
addExpressionComponents(expr, subPanelGroup);
if (!operator.getType().equals(Operator.ROOT)) {
id++;
HtmlOutputText linkText = new HtmlOutputText();
linkText.setId("link_" + id);
valueBinding = application.createValueBinding("#{queryInstanceBean.expressionWrappers['" + operator.getId() + "'].linkLabel}");
linkText.setValueBinding("value", valueBinding);
linkText.setStyleClass("operator_link");
subPanelGroup.getChildren().add(linkText);
}
}
if (operator.equals(selectedExpression)) {
addExpressionList(context, subPanelGroup);
} else {
id++;
HtmlCommandButton button = new HtmlCommandButton();
button.setId("button_" + id);
MethodBinding method = application.createMethodBinding("#{queryInstanceBean.expressionWrappers['" + operator.getId() + "'].selectExpression}", new Class[0]);
button.setAction(method);
button.setImage("/common/misc/images/add_expr.png");
button.setStyleClass("expr_button add");
ValueBinding value = application.createValueBinding("#{queryInstanceBean.expressionWrappers['" + operator.getId() + "'].addButtonRendered}");
button.setValueBinding("rendered", value);
subPanelGroup.getChildren().add(button);
}
}
Aggregations