private Object getSubmittedValue(UIInput input) { return input.getSubmittedValue() == null && input.isLocalValueSet() ? input.getValue() : input.getSubmittedValue(); } }
Set<ConstraintDescriptor<?>> constraints = BeanValidationMetadataExtractor.extractDefaultConstraintDescriptors(context, applicationContext, ValueExpressionAnalyzer.getExpression(context.getELContext(), input.getValueExpression("value"))); + input.getClientId(context) + "\" because the ValueExpression of the \"value\" attribute" + " isn't resolvable completely (e.g. a sub-expression returns null)";
if (valueTo < valueFrom) { setValid(false); inputFrom.setValid(false); inputTo.setValid(false); inputFrom.setValid(false); inputTo.setValid(false); if (submittedValueDouble < getMinValue() || submittedValueDouble > getMaxValue()) { setValid(false); input.setValid(false); FacesMessage msg = null; if (validatorMessage != null) { msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, validatorMessage, validatorMessage); context.addMessage(getClientId(context), msg);
UIInput startDateComponent = (UIInput) component.getAttributes().get("startDateComponent"); if (!startDateComponent.isValid()) { return; // Already invalidated. Don't care about it then. Date startDate = (Date) startDateComponent.getValue(); startDateComponent.setValid(false); throw new ValidatorException(new FacesMessage( FacesMessage.SEVERITY_ERROR, "Start date may not be after end date.", null));
@Override public void transformInput(FacesContext context, PrimeApplicationContext applicationContext, UIInput input) throws IOException { EditableValueHolder editableValueHolder = (EditableValueHolder) input; if (editableValueHolder.isRequired() && isMaxlenghtSet(input)) { return; } try { Set<ConstraintDescriptor<?>> constraints = BeanValidationMetadataExtractor.extractDefaultConstraintDescriptors( context, applicationContext, input.getValueExpression("value")); if (constraints != null && !constraints.isEmpty()) { for (ConstraintDescriptor<?> constraintDescriptor : constraints) { applyConstraint(constraintDescriptor, input, editableValueHolder); } } } catch (PropertyNotFoundException e) { String message = "Skip transform metadata for component \"" + input.getClientId(context) + "\" because" + " the ValueExpression of the \"value\" attribute" + " isn't resolvable completely (e.g. a sub-expression returns null)"; LOGGER.log(Level.FINE, message); } }
protected void doDecode(FacesContext context, UIComponent component) { String clientId = component.getClientId(context); Map<String, String> requestParameterMap = context.getExternalContext().getRequestParameterMap(); String newValue = (String) requestParameterMap.get(clientId); if (null != newValue) { UIInput input = (UIInput) component; input.setSubmittedValue(newValue); } }
public void validateMetadataFormat(FacesContext context, UIComponent toValidate, Object rawValue) { String value = (String) rawValue; UIInput input = (UIInput) toValidate; input.setValid(true); // Optimistic approach // metadataFormats are selected from a pulldown that's populated with // the values returned by the remote OAI server. // the only validation we want is to make sure the select one from the // menu. if (context.getExternalContext().getRequestParameterMap().get("DO_VALIDATION") != null && StringUtils.isEmpty(value)) { input.setValid(false); context.addMessage(toValidate.getClientId(), new FacesMessage(FacesMessage.SEVERITY_ERROR, "", BundleUtil.getStringFromBundle("harvestclients.newClientDialog.oaiMetadataFormat.required"))); } }
private void checkIsNumber(FacesContext context, UIInput component, String errorMsg) { FacesMessage message = null; String bundleName = context.getApplication().getMessageBundle(); Locale locale = context.getViewRoot().getLocale(); String duree = (String) component.getSubmittedValue(); try { Integer.parseInt(duree); } catch (NumberFormatException e) { String msg = I18NUtils.getMessageString(bundleName, errorMsg, null, locale); message = new FacesMessage(msg); message.setSeverity(FacesMessage.SEVERITY_ERROR); throw new ValidatorException(message); } }
public void validateObject(FacesContext context, UIComponent component, Object value) { String msg; FacesMessage message; String bundleName = context.getApplication().getMessageBundle(); Locale locale = context.getViewRoot().getLocale(); if ( (null != objectDocumentUidInput) && StringUtils.isNotBlank((String) objectDocumentUidInput.getLocalValue()) ) { return; } msg = I18NUtils.getMessageString(bundleName, "acaren.dafpic.title.create.relation.training.error.required.object.document", null, locale); message = new FacesMessage(msg); message.setSeverity(FacesMessage.SEVERITY_ERROR); throw new ValidatorException(message); }
public boolean guestbookResponseValidator( UIInput toValidate, String value) { if (value != null && value.length() > 255) { (toValidate).setValid(false); FacesContext.getCurrentInstance().addMessage((toValidate).getClientId(), new FacesMessage( FacesMessage.SEVERITY_ERROR, BundleUtil.getStringFromBundle("dataset.guestbookResponse.guestbook.responseTooLong"), null)); return false; } return true; }
public void validateObject(FacesContext context, UIComponent component, Object value) { Map<String, Object> attributes = component.getAttributes(); final String objectTypeInputId = (String) attributes.get("objectTypeInputId"); final String objectLiteralValueInputId = (String) attributes.get("objectLiteralValueInputId"); String objectType = (String) objectTypeInput.getLocalValue(); String objectValue = null; String bundleName = context.getApplication().getMessageBundle(); Locale locale = context.getViewRoot().getLocale(); String msg; message = new FacesMessage(msg); } else if (objectType.equals("literal")) { objectValue = StringUtils.trim((String) objectLiteralValueInput.getLocalValue()); msg = I18NUtils.getMessageString(bundleName, "error.relation.required.object.text", null, locale); message = new FacesMessage(msg); } else if (objectType.equals("uri")) { objectValue = StringUtils.trim((String) objectUriInput.getLocalValue()); msg = I18NUtils.getMessageString(bundleName, "error.relation.required.object.uri", null, locale); message = new FacesMessage(msg); } else if (objectType.equals("document")) { objectValue = StringUtils.trim((String) objectDocumentUidInput.getLocalValue()); msg = I18NUtils.getMessageString(bundleName, "error.relation.required.object.document", null, locale); message = new FacesMessage(msg);
String clientId = inputComponent.getClientId(context); String msg = inputComponent.getValidatorMessage(); Locale locale = context.getViewRoot().getLocale(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); msg = HDIVUtil.getMessage(request, Constants.HDIV_EDITABLE_ERROR_KEY, label, locale); FacesMessage facesMessage = new FacesMessage(msg); facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR); return facesMessage;
public void validateUserName(FacesContext context, UIComponent toValidate, Object value) { String userName = (String) value; logger.log(Level.FINE, "Validating username: {0}", userName); boolean userNameFound = authenticationSvc.identifierExists(userName); if (userNameFound) { ((UIInput) toValidate).setValid(false); FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, BundleUtil.getStringFromBundle("user.username.taken"), null); context.addMessage(toValidate.getClientId(context), message); } }
if (!isValid()) if (!isLocalValueSet()) ValueExpression expression = getValueExpression("value"); if (expression == null) expression.setValue(context.getELContext(), getLocalValue()); setValue(null); setLocalValueSet(false); context.getViewRoot().getLocale(), FacesMessage.SEVERITY_ERROR, UPDATE_MESSAGE_ID, new Object[] { _MessageUtils.getLabel(context, this) }); context.getApplication().publishEvent(context, ExceptionQueuedEvent.class, exceptionQueuedContext); setValid(false);
public void updateCell() { FacesContext context = FacesContext.getCurrentInstance(); Map<String, String> parameters = context.getExternalContext() .getRequestParameterMap(); int ordinal = Integer.parseInt(parameters.get("cell")); String id = "input-" + ordinal; UIInput input = (UIInput) component.findComponent(id); Double value = (Double) input.getValue(); Cell cell = model.getCellSet().getCell(ordinal); try { cell.setValue(value, AllocationPolicy.EQUAL_ALLOCATION); } catch (OlapException e) { throw new FacesException(e); } model.refresh(); }
@Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { UIInput taglineInput = (UIInput) component.getAttributes().get("taglineInput"); UIInput linkUrlInput = (UIInput) component.getAttributes().get("linkUrlInput"); String taglineStr = (String) taglineInput.getSubmittedValue(); String urlStr = (String) linkUrlInput.getSubmittedValue(); FacesMessage msg = null; if (taglineStr.isEmpty() && !urlStr.isEmpty()) { msg = new FacesMessage(BundleUtil.getStringFromBundle("link.tagline.validate")); msg.setSeverity(FacesMessage.SEVERITY_ERROR); FacesContext.getCurrentInstance().addMessage(taglineInput.getClientId(), msg); } if (msg != null) { throw new ValidatorException(msg); } }
Map alteredComponents) { FacesContext facesContext = FacesContext.getCurrentInstance(); .getApplication().createValueBinding("#{false}"); Iterator kidsAndFacets = parent.getFacetsAndChildren(); while (kidsAndFacets.hasNext()) { UIComponent next = (UIComponent) kidsAndFacets.next(); UIInput input = (UIInput) next; ValueBinding valueBinding = input.getValueBinding(REQUIRED); if (null != valueBinding) { ValueBinding replacementBinding = null; replacementBinding = FALSE_BINDING; input.setValueBinding(REQUIRED, replacementBinding); alteredComponents.put(input, valueBinding); } else { if (input.isRequired() && input != componentToAvoid && input.isValid()) { input.setRequired(false); alteredComponents.put(input, null);
@Override public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException { // Obtain the client ID of the first password field from f:attribute. String passwordId = (String) uic.getAttributes().get("passwordId"); // Find the actual JSF component for the client ID. UIInput passwordInput = (UIInput) fc.getViewRoot().findComponent(passwordId); // Get its value, the entered password of the first field. String password = (String) passwordInput.getValue(); // Cast the value of the entered password of the second field back to String. String confirm = (String) o; // Compare the first password with the second password. if (!password.equals(confirm)) { throw new ValidatorException(new FacesMessage("Passwords are not equal.")); } // You can even validate the minimum password length here and throw accordingly. // Or, if you're smart, calculate the password strength and throw accordingly ;) } }
setCachedFacesContext(context); pushComponentToEL(context, this); if (!isRendered()) setCachedFacesContext(null); popComponentFromEL(context); int facetCount = getFacetCount(); if (facetCount > 0) for (UIComponent facet : getFacets().values()) for (int i = 0, childCount = getChildCount(); i < childCount; i++) UIComponent child = getChildren().get(i); child.processValidators(context); setCachedFacesContext(context); pushComponentToEL(context, this); if (!isImmediate()) validate(context); if (!isValid()) setCachedFacesContext(null); popComponentFromEL(context);
@Override public void decode(final FacesContext facesContext, final UIComponent component) { final UIInput input = (UIInput) component; if (ComponentUtils.isOutputOnly(input)) { return; } final String newValue = facesContext.getExternalContext() .getRequestParameterMap().get(input.getClientId(facesContext)); if (LOG.isDebugEnabled()) { LOG.debug("new value = '" + newValue + "'"); } input.setSubmittedValue("true".equals(newValue) ? "true" : "false"); RenderUtils.decodeClientBehaviors(facesContext, input); }