Java源码示例:javax.faces.component.UIInput

示例1
/**
 * Reset the values of all UIInput children. This might be necessary after a
 * validation error to successfully process an AJAX request. See [Bug 5449]
 * and http://wiki.apache.org/myfaces/ClearInputComponents
 * 
 * @param uiComponent
 *            the root component to be processed.
 */
public static void resetUIInputChildren(UIComponent uiComponent) {
    if (uiComponent != null) {
        List<UIComponent> children = uiComponent.getChildren();
        for (UIComponent child : children) {
            if (child instanceof UIInput) {
                UIInput uiInput = (UIInput) child;
                uiInput.setSubmittedValue(null);
                uiInput.setValue(null);
                uiInput.setLocalValueSet(false);
            } else {
                resetUIInputChildren(child);
            }
        }
    }
}
 
示例2
@Test
public void testValidateSubscriptionId() throws Exception {

    // given
    SubscriptionServiceInternal ssi = mock(SubscriptionServiceInternal.class);
    doReturn(true).when(ssi).validateSubscriptionIdForOrganization(
            anyString());
    doReturn(ssi).when(bean).getSubscriptionServiceInternal();

    UIComponent uiInputMock = mock(UIInput.class);
    FacesContext contextMock = mock(FacesContext.class);

    // when
    bean.validateSubscriptionId(contextMock, uiInputMock, "value");

    // then
    verify(ui, times(1)).handleError(anyString(),
            eq(SUBSCRIPTION_NAME_ALREADY_EXISTS), anyObject());
}
 
示例3
/**
 * decode method
 * @param context
 * @param component
 */
public void decode(FacesContext context, UIComponent component)
{
  // we haven't added these attributes--yet--defensive programming...
  if(RendererUtil.isDisabledOrReadonly(component))
  {
    return;
  }

  String clientId = component.getClientId(context);
  Map requestParameterMap = context.getExternalContext()
                            .getRequestParameterMap();
  String newValue = (String) requestParameterMap.get(clientId );
  UIInput comp = (UIInput) component;
  comp.setSubmittedValue(newValue);
}
 
示例4
@Override
protected void writeFormRowHelp(FacesContext context, ResponseWriter w, FormLayout c, UIFormLayoutRow row, UIInput edit) throws IOException {
    String helpId = row.getHelpId();
    String helpStyle = (String)getProperty(PROP_HELPROWSTYLE);
    if(StringUtil.isNotEmpty(helpStyle)) {
        w.writeAttribute("style", helpStyle, null); // $NON-NLS-1$
    }
    if(StringUtil.isNotEmpty(helpId)) {
        String forClientId = null;
        UIComponent forComponent = FacesUtil.getComponentFor(c, helpId);
        if(forComponent == null) {
            UIComponent p = (UIComponent)FacesUtil.getNamingContainer(c);
            if(p!=null) {
               forClientId = p.getClientId(context)+":"+helpId;
            }
        } else {
            forClientId = forComponent.getClientId(context);
        }
        writeFormRowDataHelp(context, w, c, row, edit, forClientId);
    } else {
        UIComponent facet = row.getFacet(UIFormLayoutRow.FACET_HELP);
        if(facet!=null) {
            writeFormRowDataHelpFacet(context, w, c, row, edit, facet);
        }
    }
}
 
示例5
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    
    Map<String, Object> attrs = TypedUtil.getAttributes(component);
    String initializedKey = "_initialized_MobileTypeAheadInputRenderer"; //$NON-NLS-1$
    if( null == attrs.get(initializedKey) ){
        UIInput input = (UIInput) component;
        XspTypeAhead typeAhead = findTypeAheadChild(input);
        if( null != typeAhead && typeAhead.isTypeAheadEnabled(context)){
            initTypeAhead(context, input, typeAhead);
            validateNoSeparator(context, input, typeAhead);
        }
        attrs.put(initializedKey, "true"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    
    super.encodeBegin(context, component);
}
 
示例6
/**
 * @deprecated Use
 *             {@link CoreRenderer#generateErrorAndRequiredClass(javax.faces.component.UIInput, javax.faces.context.ResponseWriter, java.lang.String, java.lang.String, java.lang.String, java.lang.String) }
 *             instead
 * 
 *             Renders the CSS pseudo classes for required fields and for the
 *             error levels.
 *
 * @param input
 * @param rw
 * @param clientId
 * @throws IOException
 */
@Deprecated
public void generateErrorAndRequiredClassForLabels(UIInput input, ResponseWriter rw, String clientId,
		String additionalClass) throws IOException {
	String styleClass = getErrorAndRequiredClass(input, clientId);
	if (null != additionalClass) {
		additionalClass = additionalClass.trim();
		if (additionalClass.trim().length() > 0) {
			styleClass += " " + additionalClass;
		}
	}
	UIForm currentForm = AJAXRenderer.getSurroundingForm((UIComponent) input, true);
	if (currentForm instanceof Form) {
		if (((Form) currentForm).isHorizontal()) {
			styleClass += " control-label";
		}
	}
	if (input instanceof IResponsiveLabel) {
		String responsiveLabelClass = Responsive.getResponsiveLabelClass((IResponsiveLabel) input);
		if (null != responsiveLabelClass) {
			styleClass += " " + responsiveLabelClass;
		}
	}

	rw.writeAttribute("class", styleClass, "class");
}
 
示例7
/**
 * Renders the CSS pseudo classes for required fields and for the error levels.
 *
 * @param input
 * @param rw
 * @param clientId
 * @throws IOException
 */
protected void generateErrorAndRequiredClass(UIInput input, ResponseWriter rw, String clientId,
		String additionalClass1, String additionalClass2, String additionalClass3) throws IOException {
	String styleClass = getErrorAndRequiredClass(input, clientId);
	if (null != additionalClass1) {
		additionalClass1 = additionalClass1.trim();
		if (additionalClass1.trim().length() > 0) {
			styleClass += " " + additionalClass1;
		}
	}
	if (null != additionalClass2) {
		additionalClass2 = additionalClass2.trim();
		if (additionalClass2.trim().length() > 0) {
			styleClass += " " + additionalClass2;
		}
	}
	if (null != additionalClass3) {
		additionalClass3 = additionalClass3.trim();
		if (additionalClass3.trim().length() > 0) {
			styleClass += " " + additionalClass3;
		}
	}
	rw.writeAttribute("class", styleClass, "class");
}
 
示例8
public void validateProperty(FacesContext context, UIComponent comp, Object value) {
	String newkeyAttr = (String) value;
	oxTrustAuditService.audit("Validation");
	for (SimpleProperty keyAttribute : keyAttributes) {
		int i = 0;
		if (newkeyAttr.equalsIgnoreCase(keyAttribute.getValue())) {
			i = i + 1;
			if (i == 2) {
				((UIInput) comp).setValid(false);
				FacesMessage message = new FacesMessage("key attribute already Exist! ");
				context.addMessage(comp.getClientId(context), message);
			}
		}

	}
}
 
示例9
protected void writeFormRow(FacesContext context, ResponseWriter w, FormLayout c, ComputedFormData formData, UIFormLayoutRow row) throws IOException {
    
    ComputedRowData rowData = createRowData(context, c, formData, row);

    UIInput edit = row.getForComponent();
    if(edit!=null) {
        // Write the error messages, if any
        if(!formData.isDisableRowError()) {
            Iterator<FacesMessage> msg = getMessages(context, edit.getClientId(context));
            if(msg.hasNext()) {
                while(msg.hasNext()) {
                    FacesMessage m = msg.next();
                    writeFormRowError(context, w, c, row, edit, m, rowData);
                }
            }
        }
    }
    
    // The write the children
    writeFormRowData(context, w, c, formData, row, edit, rowData);
}
 
示例10
protected void writeFormRowDataHelp(FacesContext context, ResponseWriter w, FormLayout c, UIFormLayoutRow row, UIInput edit, String helpId) throws IOException {
    // TODO: how should the help be implemented?
    w.startElement("a", c);
    w.writeAttribute("href", "javascript:;", null); // $NON-NLS-1$ $NON-NLS-2$
    w.writeAttribute("aria-haspopup", "true", null); // $NON-NLS-1$ $NON-NLS-2$
    w.writeAttribute("aria-owns", helpId, null); // $NON-NLS-1$
    w.startElement("img", c); // $NON-NLS-1$
    String style = (String)getProperty(PROP_HELPIMGSTYLE);
    if(StringUtil.isNotEmpty(style)) {
        w.writeAttribute("style", style, null); // $NON-NLS-1$
    }
    String cls = (String)getProperty(PROP_HELPIMGCLASS);
    if(StringUtil.isNotEmpty(cls)) {
        w.writeAttribute("class", cls, null); // $NON-NLS-1$
    }
    String bgif = (String)getProperty(PROP_HELPIMGSRC);
    if(StringUtil.isNotEmpty(bgif)) {
        w.writeAttribute("src",HtmlRendererUtil.getImageURL(context,bgif),null); // $NON-NLS-1$
    }
    String alt = (String)getProperty(PROP_HELPIMGALT);
    if(StringUtil.isNotEmpty(alt)) {
        w.writeAttribute("alt", alt, null); // $NON-NLS-1$
    }
    w.endElement("img"); // $NON-NLS-1$
    w.endElement("a");
}
 
示例11
/**
 * decode method
 * @param context
 * @param component
 */
public void decode(FacesContext context, UIComponent component)
{
  // we haven't added these attributes--yet--defensive programming...
  if(RendererUtil.isDisabledOrReadonly(context, component))
  {
    return;
  }

  String clientId = component.getClientId(context);
  Map requestParameterMap = context.getExternalContext()
                            .getRequestParameterMap();
  String newValue = (String) requestParameterMap.get(clientId );
  UIInput comp = (UIInput) component;
  comp.setSubmittedValue(newValue);
}
 
示例12
@Override
protected void writeValueAttribute(FacesContext context, UIInput component, ResponseWriter writer, String currentValue) throws IOException {
    UIDojoToggleButton ck = (UIDojoToggleButton)component;
    Object oCheckedValue = ck.getCheckedValue();
    String checkedValue = null;
    if (oCheckedValue != null) {
    	checkedValue = oCheckedValue.toString();
    }
    if(checkedValue==null) {
        checkedValue = UIDojoCheckBox.CHECKED_VALUE_DEFAULT;
    }
    if(StringUtil.equals(checkedValue, currentValue)) {
        // Should it be a dojo attribute instead?
        writer.writeAttribute("value", "on", null); //$NON-NLS-1$ //$NON-NLS-2$
    }
}
 
示例13
/**
 * decode method
 * @param context
 * @param component
 */
public void decode(FacesContext context, UIComponent component)
{
  // we haven't added these attributes--yet--defensive programming...
  if(RendererUtil.isDisabledOrReadonly(component))
  {
    return;
  }

  String clientId = component.getClientId(context);
  Map requestParameterMap = context.getExternalContext()
                            .getRequestParameterMap();
  String newValue = (String) requestParameterMap.get(clientId );
  UIInput comp = (UIInput) component;
  comp.setSubmittedValue(newValue);
}
 
示例14
private boolean isUsingInputPlainText(FacesContext context, UIInput component) {
    
    // most browsers use <input type=datetime, but for iOS defaulting to type=text
    boolean isUseInputPlainTextOnIOS = true;
    String option = ((FacesContextEx)context).getProperty("xsp.theme.mobile.iOS.native.dateTime"); //$NON-NLS-1$
    if( null != option ){
        // explicitly configured whether to use type=datetime on iOS
        boolean isNativeOnIOS = "true".equals(option); //$NON-NLS-1$
        isUseInputPlainTextOnIOS = ! isNativeOnIOS;
    }
    if( isUseInputPlainTextOnIOS ){
        Object deviceBeanObj = ExtLibUtil.resolveVariable(context, "deviceBean"); //$NON-NLS-1$
        if( deviceBeanObj instanceof DeviceBean ){
            DeviceBean deviceBean = (DeviceBean)deviceBeanObj;
            boolean isIOS = deviceBean.isIphone()|| deviceBean.isIpad() || deviceBean.isIpod();
            if( isIOS ){
                // is iOS, so by use type=text
                return true;
            }
            // else other devices use type=datetime, not type=text
        }
    }
    // else always use type=datetime, don't need to whether check browser OS is iOS.
    return false;
}
 
示例15
@Override
protected void writeFormRow(FacesContext context, ResponseWriter w, FormLayout c, ComputedFormData formData, UIFormLayoutRow row) throws IOException {
    ComputedRowData rowData = createRowData(context, c, formData, row);

    UIInput edit = row.getForComponent();
    if(edit!=null) {
        // Write the error messages, if any
        if(!formData.isDisableRowError()) {
            Iterator<FacesMessage> msg = ((DominoFacesContext)context).getMessages(edit.getClientId(context));
            if(msg.hasNext()) {
                while(msg.hasNext()) {
                    FacesMessage m = msg.next();
                    writeFormRowError(context, w, c, row, edit, m, rowData);
                }
            }
        }
    }
    
    // The write the children
    writeFormRowData(context, w, c, formData, row, edit, rowData);
}
 
示例16
private void initTypeAhead(FacesContext context, UIInput input, XspTypeAhead typeAhead) {
    
    // prevent setParent after restoreState from overwriting the rendererType set in the theme file
    String themeConfiguredInputRendererType = input.getRendererType();
    typeAhead.setParentRendererType(themeConfiguredInputRendererType);
    
    // TODO have to do this overriding here instead of in the theme file
    // because XspTypeAhead doesn't implement ThemeControl
    String existingDojoType = typeAhead.getDojoType();
    if( null == existingDojoType ){
        String dojoType= COMBOBOX_MODULE.getName();
        typeAhead.setDojoType(dojoType);
    }
    
    String existingStoreType = typeAhead.getDojoStoreType();
    if( null == existingStoreType ){
        String storeType = "extlib.store.TypeAheadStore"; //$NON-NLS-1$
        typeAhead.setDojoStoreType(storeType);
    }
}
 
示例17
private Converter getConverter(FacesContext context, UIComponent component) {
	Converter converter = ((UIInput) component).getConverter();
	if (converter != null) {
		return converter;
	}
	ValueExpression exp = component.getValueExpression("value");
	if (exp == null) {
		return null;
	}
	Class valueType = exp.getType(context.getELContext());
	if (valueType == null) {
		return null;
	}
	return context.getApplication().createConverter(valueType);
}
 
示例18
public void validateDuplicatedId(final FacesContext context,
        final UIComponent component, final Object value) {

    String billingId = value.toString();
    POBillingAdapter billingAdapter = getBillingAdapter(billingId);

    if (billingAdapter.getBillingIdentifier() != null && billingId.equals(billingAdapter.getBillingIdentifier())) {
        ((UIInput) component).setValid(false);
        addMessage(component.getClientId(context),
                FacesMessage.SEVERITY_ERROR,
                ERROR_BILLING_ID_ALREADY_EXISTS,
                new Object[] { billingId });
    }
}
 
示例19
/**
 * Check if the component is an input component and if the style is the
 * error style.
 * 
 * @param uiComponent
 *            UI component
 * @return true if the component is an input component and if the style is
 *         the error style
 */
private boolean isErrorStyle(UIComponent uiComponent) {
    if (!(uiComponent instanceof UIInput)) {
        return false;
    }
    if (uiComponent instanceof UISelectBoolean) {
        return (STYLE_CHECKBOX_ERROR).equals(uiComponent.getAttributes()
                .get(ATTRIBUTE_STYLE));
    }
    return (STYLE_ERROR).equals(uiComponent.getAttributes().get(
            ATTRIBUTE_STYLE));
}
 
示例20
@Test
public void validateDuplicatedIds() throws SaaSApplicationException {
    FacesContext fc = mock(FacesContext.class);
    UIComponent component = mock(UIInput.class);
    doReturn(createBillingAdapter()).when(bean)
            .getBillingAdapter(any(String.class));

    bean.validateDuplicatedId(fc, component, "BILLING_ADAPTER1");
}
 
示例21
@Test
public void billingTypeChanged_bug10285() {
    // given
    UIInput input = mock(UIInput.class);
    ValueChangeEvent e = new ValueChangeEvent(input, null, null);

    // when
    ctrl.billingTypeChanged(e);

    // then
    assertEquals(null, model.getSelectedBillingDataType());
}
 
示例22
@Override
public void validate(FacesContext context, UIComponent toValidate, Object value) throws ValidatorException {
    String str = (String) value;
    if (str.trim().length() < 1) {
        ((UIInput) toValidate).setValid(false);

        FacesMessage message = new FacesMessage();
        String messageText = JsfUtil.getLocalizedMessage("sectionTitle.validator.stringWithSpaceOnly");
        message.setDetail(messageText);
        message.setSummary(messageText);
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(message);
    }
}
 
示例23
public void validatePartialCredit(FacesContext context,  UIComponent toValidate,Object value){
	Integer pCredit = null;
	boolean isValid = true;
	if ("0.0".equals(value.toString())) {
		pCredit = 0;
	}
	else {
		try {
			pCredit = Integer.parseInt(value.toString());
		}
		catch (NumberFormatException e) {
			isValid = false;
		}
	}
	
	if(isValid && (pCredit==null || pCredit<0 || pCredit>99 )){
		isValid = false;
	}
	
	if (!isValid) {
		((UIInput)toValidate).setValid(false);
		FacesMessage message=new FacesMessage();
		message.setSeverity(FacesMessage.SEVERITY_ERROR);
		String summary=ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.AuthorMessages","partial_credit_limit_summary");
		String detail =ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.AuthorMessages","partial_credit_limit_detail"); 
		message.setSummary(summary) ;
		message.setDetail(detail);   
		context.addMessage(toValidate.getClientId(context), message);
	}
}
 
示例24
public void validatePartialCredit(FacesContext context,  UIComponent toValidate,Object value){
	Integer pCredit = null;
	boolean isValid = true;
	if ("0.0".equals(value.toString())) {
		pCredit = 0;
	}
	else {
		try {
			pCredit = Integer.parseInt(value.toString());
		}
		catch (NumberFormatException e) {
			isValid = false;
		}
	}
	
	if(isValid && (pCredit==null || pCredit<0 || pCredit>99 )){
		isValid = false;
	}
	
	if (!isValid) {
		((UIInput)toValidate).setValid(false);
		FacesMessage message=new FacesMessage();
		message.setSeverity(FacesMessage.SEVERITY_ERROR);
		String summary=ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.AuthorMessages","partial_credit_limit_summary");
		String detail =ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.AuthorMessages","partial_credit_limit_detail"); 
		message.setSummary(summary) ;
		message.setDetail(detail);   
		context.addMessage(toValidate.getClientId(context), message);
	}
}
 
示例25
/**
 * Throw exception if there is only space(s) character as input.
 */
public void validate(FacesContext context, UIComponent toValidate, Object value) throws ValidatorException {
	String str = (String) value;
	if (str.trim().length() < 1) {
		((UIInput) toValidate).setValid(false);

		FacesMessage message = new FacesMessage();
		message.setDetail(Utilities.rb.getString("signup.validator.stringWithSpaceOnly"));
		message.setSummary(Utilities.rb.getString("signup.validator.stringWithSpaceOnly"));
		message.setSeverity(FacesMessage.SEVERITY_ERROR);
		throw new ValidatorException(message);
	}
}
 
示例26
private String computeValueAsISOString(FacesContext context, UIInput input) {
    DateTimeConverter converter = (DateTimeConverter) input.getConverter();
    
    // the submitted value takes precedence
    // As it is a string, no conversion should happen 
    Object submittedValue = input.getSubmittedValue();
    if (submittedValue != null) {
        return (String)submittedValue;
    }
    Object value = input.getValue();
    if( null == value ){
        return "";
    }
    return getAsString(context, input, converter, value);
}
 
示例27
/**
 * Yields the value of the required and error level CSS class.
 *
 * @param input
 * @param clientId
 * @return
 */
public String getErrorAndRequiredClass(UIInput input, String clientId) {
	String[] levels = { "bf-no-message", "bf-info", "bf-warning", "bf-error", "bf-fatal" };
	int level = 0;
	Iterator<FacesMessage> messages = FacesContext.getCurrentInstance().getMessages(clientId);
	if (null != messages) {
		while (messages.hasNext()) {
			FacesMessage message = messages.next();
			if (message.getSeverity().equals(FacesMessage.SEVERITY_INFO))
				if (level < 1)
					level = 1;
			if (message.getSeverity().equals(FacesMessage.SEVERITY_WARN))
				if (level < 2)
					level = 2;
			if (message.getSeverity().equals(FacesMessage.SEVERITY_ERROR))
				if (level < 3)
					level = 3;
			if (message.getSeverity().equals(FacesMessage.SEVERITY_FATAL))
				if (level < 4)
					level = 4;
		}
	}
	String styleClass = levels[level];
	if (input.isRequired()) {
		styleClass += " bf-required";
	}
	return styleClass;
}
 
示例28
protected void writeFormRowHelp(FacesContext context, ResponseWriter w, FormLayout c, UIFormLayoutRow row, UIInput edit) throws IOException {
    String helpId = row.getHelpId();
    String helpStyle = (String)getProperty(PROP_HELPROWSTYLE);
    if(StringUtil.isNotEmpty(helpStyle)) {
        w.writeAttribute("style", helpStyle, null); // $NON-NLS-1$
    }
    String helpClass = (String)getProperty(PROP_HELPROWCLASS);
    if(StringUtil.isNotEmpty(helpClass)) {
        w.writeAttribute("class", helpClass, null); // $NON-NLS-1$
    }
    if(StringUtil.isNotEmpty(helpId)) {
        String forClientId = null;
        UIComponent forComponent = FacesUtil.getComponentFor(c, helpId);
        if(forComponent == null) {
            UIComponent p = (UIComponent)FacesUtil.getNamingContainer(c);
            if(p!=null) {
               forClientId = p.getClientId(context)+":"+helpId;
            }
        } else {
            forClientId = forComponent.getClientId(context);
        }
        writeFormRowDataHelp(context, w, c, row, edit, forClientId);
    } else {
        UIComponent facet = row.getFacet(UIFormLayoutRow.FACET_HELP);
        if(facet!=null) {
            writeFormRowDataHelpFacet(context, w, c, row, edit, facet);
        } else {
            JSUtil.writeTextBlank(w); // &nbsp;
        }
    }
}
 
示例29
protected void writeFormRowRequiredContent(FacesContext context, ResponseWriter w, FormLayout c, UIFormLayoutRow row, UIInput edit) throws IOException {
	String reqClass = (String)getProperty(PROP_FIELDLABELREQUIREDCLASS);
	String reqText = (String)getProperty(PROP_FIELDLABELREQUIREDTEXT);
	if(StringUtil.isNotEmpty(reqClass) || StringUtil.isNotEmpty(reqText)) {
		w.startElement("span", c); // $NON-NLS-1$
		if(StringUtil.isNotEmpty(reqClass)) {
			w.writeAttribute("class", reqClass, null); // $NON-NLS-1$
		}
		if(StringUtil.isNotEmpty(reqText)) {
			w.writeText(reqText, null);
		}
		w.endElement("span"); // $NON-NLS-1$
	}
}
 
示例30
protected void startTag(FacesContext context, ResponseWriter writer, UIInput component) throws IOException {
    String tagName = getTagName();
    writer.startElement(tagName, component); //$NON-NLS-1$
    String type = getInputType();
    if(StringUtil.isNotEmpty(type)) {
        writer.writeAttribute("type", type, null); //$NON-NLS-1$ //$NON-NLS-2$
    }
}