use of org.primefaces.component.api.InputHolder in project primefaces by primefaces.
the class KeyFilterRenderer method encodeEnd.
@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
KeyFilter keyFilter = (KeyFilter) component;
UIComponent target;
if (isValueBlank(keyFilter.getFor())) {
target = component.getParent();
} else {
target = SearchExpressionFacade.resolveComponent(context, keyFilter, keyFilter.getFor());
}
String targetClientId = target instanceof InputHolder ? ((InputHolder) target).getInputClientId() : target.getClientId();
WidgetBuilder wb = getWidgetBuilder(context);
wb.init(KeyFilter.class.getSimpleName(), keyFilter);
wb.attr("target", targetClientId);
if (keyFilter.getRegEx() != null) {
wb.nativeAttr("regEx", keyFilter.getRegEx());
} else if (keyFilter.getInputRegEx() != null) {
wb.nativeAttr("inputRegEx", keyFilter.getInputRegEx());
} else if (keyFilter.getMask() != null) {
wb.attr("mask", keyFilter.getMask());
} else if (keyFilter.getTestFunction() != null) {
wb.callback("testFunction", "function(c)", keyFilter.getTestFunction() + ";");
}
if (keyFilter.isPreventPaste()) {
wb.attr("preventPaste", keyFilter.isPreventPaste());
}
wb.finish();
}
use of org.primefaces.component.api.InputHolder in project primefaces by primefaces.
the class SliderRenderer method encodeScript.
protected void encodeScript(FacesContext context, Slider slider) throws IOException {
String range = slider.getRange();
UIComponent output = getTarget(context, slider, slider.getDisplay());
WidgetBuilder wb = getWidgetBuilder(context);
wb.init("Slider", slider);
if ("true".equals(range)) {
String[] inputIds = slider.getFor().split(",");
UIComponent inputMin = getTarget(context, slider, inputIds[0]);
UIComponent inputMax = getTarget(context, slider, inputIds[1]);
String inputMinValue = ComponentUtils.getValueToRender(context, inputMin);
if (inputMinValue == null) {
inputMinValue = Constants.EMPTY_STRING;
}
String inputMaxValue = ComponentUtils.getValueToRender(context, inputMax);
if (inputMaxValue == null) {
inputMaxValue = Constants.EMPTY_STRING;
}
wb.attr("input", inputMin.getClientId(context) + "," + inputMax.getClientId(context)).append(",values:[").append(inputMinValue).append(",").append(inputMaxValue).append("]");
} else {
UIComponent input = getTarget(context, slider, slider.getFor());
String inputClientId = input instanceof InputHolder ? ((InputHolder) input).getInputClientId() : input.getClientId(context);
wb.attr("value", ComponentUtils.getValueToRender(context, input)).attr("input", inputClientId);
}
wb.attr("min", slider.getMinValue()).attr("max", slider.getMaxValue()).attr("animate", slider.isAnimate()).attr("step", slider.getStep()).attr("orientation", slider.getType()).attr("disabled", slider.isDisabled(), false).attr("displayTemplate", slider.getDisplayTemplate(), null).attr("touchable", ComponentUtils.isTouchable(context, slider), true).callback("onSlideStart", "function(event,ui)", slider.getOnSlideStart()).callback("onSlide", "function(event,ui)", slider.getOnSlide()).callback("onSlideEnd", "function(event,ui)", slider.getOnSlideEnd());
switch(range) {
case "true":
case "false":
wb.attr("range", Boolean.valueOf(range));
break;
default:
wb.attr("range", range);
break;
}
if (output != null) {
wb.attr("display", output.getClientId(context));
}
encodeClientBehaviors(context, slider);
wb.finish();
}
use of org.primefaces.component.api.InputHolder in project primefaces by primefaces.
the class OutputLabelRenderer method encodeEnd.
@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
final ResponseWriter writer = context.getResponseWriter();
final OutputLabel label = (OutputLabel) component;
final String clientId = label.getClientId(context);
final String value = ComponentUtils.getValueToRender(context, label);
final StringBuilder styleClass = SharedStringBuilder.get(context, SB_STYLE_CLASS);
styleClass.append(OutputLabel.STYLE_CLASS);
if (label.getStyleClass() != null) {
styleClass.append(" ");
styleClass.append(label.getStyleClass());
}
final EditableValueHolderState state = new EditableValueHolderState();
final String indicateRequired = label.getIndicateRequired();
boolean isAuto = "auto".equals(indicateRequired) || "autoSkipDisabled".equals(indicateRequired);
String _for = label.getFor();
if (!isValueBlank(_for)) {
ContextCallback callback = new ContextCallback() {
@Override
public void invokeContextCallback(FacesContext context, UIComponent target) {
if (target instanceof InputHolder) {
InputHolder inputHolder = ((InputHolder) target);
state.setClientId(inputHolder.getInputClientId());
inputHolder.setLabelledBy(clientId);
} else {
state.setClientId(target.getClientId(context));
}
if (target instanceof UIInput) {
UIInput input = (UIInput) target;
if (value != null && (input.getAttributes().get("label") == null || input.getValueExpression("label") == null)) {
ValueExpression ve = label.getValueExpression("value");
if (ve != null) {
input.setValueExpression("label", ve);
} else {
String labelString = value;
int colonPos = labelString.lastIndexOf(':');
if (colonPos != -1) {
labelString = labelString.substring(0, colonPos);
}
input.getAttributes().put("label", labelString);
}
}
if (!input.isValid()) {
styleClass.append(" ui-state-error");
}
if (isAuto) {
boolean disabled = false;
if ("autoSkipDisabled".equals(indicateRequired)) {
disabled = Boolean.parseBoolean(String.valueOf(input.getAttributes().get("disabled"))) || Boolean.parseBoolean(String.valueOf(input.getAttributes().get("readonly")));
}
if (disabled) {
state.setRequired(false);
} else {
state.setRequired(input.isRequired());
// fallback if required=false
if (!state.isRequired()) {
PrimeApplicationContext applicationContext = PrimeApplicationContext.getCurrentInstance(context);
if (applicationContext.getConfig().isBeanValidationEnabled() && isBeanValidationDefined(input, context)) {
state.setRequired(true);
}
}
}
}
}
}
};
UIComponent forComponent = SearchExpressionFacade.resolveComponent(context, label, _for);
if (CompositeUtils.isComposite(forComponent)) {
CompositeUtils.invokeOnDeepestEditableValueHolder(context, forComponent, callback);
} else {
callback.invokeContextCallback(context, forComponent);
}
}
writer.startElement("label", label);
writer.writeAttribute("id", clientId, "id");
writer.writeAttribute("class", styleClass.toString(), "id");
renderPassThruAttributes(context, label, HTML.LABEL_ATTRS);
renderDomEvents(context, label, HTML.LABEL_EVENTS);
if (!isValueBlank(_for)) {
writer.writeAttribute("for", state.getClientId(), "for");
}
if (value != null) {
if (label.isEscape()) {
writer.writeText(value, "value");
} else {
writer.write(value);
}
}
renderChildren(context, label);
if ("true".equals(indicateRequired) || (isAuto && !isValueBlank(_for) && state.isRequired())) {
encodeRequiredIndicator(writer, label);
}
writer.endElement("label");
}
use of org.primefaces.component.api.InputHolder in project primefaces by primefaces.
the class ClientValidator method getScript.
@Override
public String getScript(ClientBehaviorContext behaviorContext) {
if (isDisabled()) {
return null;
}
if (!behaviorContext.getFacesContext().isProjectStage(ProjectStage.Production)) {
if (!PrimeApplicationContext.getCurrentInstance(behaviorContext.getFacesContext()).getConfig().isClientSideValidationEnabled()) {
LOGGER.log(Level.WARNING, Constants.ContextParams.CSV + " must be enabled for p:clientValidator!");
}
}
UIComponent component = behaviorContext.getComponent();
String target = (component instanceof InputHolder) ? "'" + ((InputHolder) component).getValidatableInputClientId() + "'" : "this";
return "return PrimeFaces.vi(" + target + ", true, true)";
}
use of org.primefaces.component.api.InputHolder in project primefaces by primefaces.
the class InputRenderer method renderAccessibilityAttributes.
protected void renderAccessibilityAttributes(FacesContext context, UIInput component, boolean disabled, boolean readonly) throws IOException {
ResponseWriter writer = context.getResponseWriter();
renderARIARequired(context, component);
renderARIAInvalid(context, component);
if (component instanceof InputHolder) {
InputHolder inputHolder = ((InputHolder) component);
String labelledBy = inputHolder.getLabelledBy();
if (LangUtils.isNotBlank(labelledBy)) {
writer.writeAttribute(HTML.ARIA_LABELLEDBY, labelledBy, null);
}
}
if (disabled) {
writer.writeAttribute("disabled", "disabled", null);
}
if (readonly) {
writer.writeAttribute("readonly", "readonly", null);
}
}
Aggregations