本文整理汇总了Java中javax.faces.component.UIInput.setValid方法的典型用法代码示例。如果您正苦于以下问题:Java UIInput.setValid方法的具体用法?Java UIInput.setValid怎么用?Java UIInput.setValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.faces.component.UIInput
的用法示例。
在下文中一共展示了UIInput.setValid方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateGroupIdentifier
import javax.faces.component.UIInput; //导入方法依赖的package包/类
public void validateGroupIdentifier(FacesContext context, UIComponent toValidate, Object rawValue) {
String value = (String) rawValue;
UIInput input = (UIInput) toValidate;
input.setValid(true); // Optimistic approach
if ( context.getExternalContext().getRequestParameterMap().get("DO_GROUP_VALIDATION") != null
&& !StringUtils.isEmpty(value) ) {
// cheap test - regex
if (! Pattern.matches("^[a-zA-Z0-9\\_\\-]+$", value) ) {
input.setValid(false);
context.addMessage(toValidate.getClientId(),
new FacesMessage(FacesMessage.SEVERITY_ERROR, "", JH.localize("dataverse.permissions.explicitGroupEditDialog.groupIdentifier.invalid")));
} else if ( explicitGroupSvc.findInOwner(getDvObject().getId(), value) != null ) {
// Ok, see that the alias is not taken
input.setValid(false);
context.addMessage(toValidate.getClientId(),
new FacesMessage(FacesMessage.SEVERITY_ERROR, "", JH.localize("dataverse.permissions.explicitGroupEditDialog.groupIdentifier.taken")));
}
}
}
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:23,代码来源:ManagePermissionsPage.java
示例2: resetInputComponents
import javax.faces.component.UIInput; //导入方法依赖的package包/类
private static void resetInputComponents(UIComponent rootUIComponent) {
if ((rootUIComponent == null) || (rootUIComponent.getChildCount() == 0)) {
return;
}
for (UIComponent comp : rootUIComponent.getChildren()) {
if (comp instanceof UIInput) {
UIInput uiInput = (UIInput) comp;
uiInput.setSubmittedValue(null);
uiInput.setValid(true);
uiInput.setLocalValueSet(false);
uiInput.resetValue();
}
resetInputComponents(comp);
}
}
示例3: validate
import javax.faces.component.UIInput; //导入方法依赖的package包/类
public void validate(FacesContext context, UIComponent component, Object value)
throws ValidatorException
{
// Cast the value of the entered password to String.
String password = (String) value;
// Obtain the component and submitted value of the confirm password component.
UIInput confirmComponent = (UIInput) component.getAttributes().get("confirm");
String confirm = (String) confirmComponent.getSubmittedValue();
// Check if they both are filled in.
if (password == null || password.isEmpty() || confirm == null || confirm.isEmpty())
{
return; // Let required="true" do its job.
}
// Compare the password with the confirm password.
if (!password.equals(confirm))
{
confirmComponent.setValid(false); // So that it's marked invalid.
String text = bundleManager.getMessage( "validator.confpwd" );
throw new ValidatorException( new FacesMessage( text ) );
}
// You can even validate the minimum password length here and throw accordingly.
// Or, if you're smart, calculate the password strength and throw accordingly ;)
}
示例4: validatePopUp
import javax.faces.component.UIInput; //导入方法依赖的package包/类
/**
* M�todo de valida��o. Beta testando
* @param context
* @param toValidate
* @param value
*/
public void validatePopUp(FacesContext context, UIComponent toValidate, Object value) {
UIInput uiInput = (UIInput) toValidate;
FacesMessage message = new FacesMessage("Invalid Email");
context.addMessage(toValidate.getClientId(context), message);
uiInput.setValid(false);
}
示例5: validatePopUp
import javax.faces.component.UIInput; //导入方法依赖的package包/类
/**
* Método de validação. Beta testando
* @param context
* @param toValidate
* @param value
*/
public void validatePopUp(FacesContext context, UIComponent toValidate, Object value) {
UIInput uiInput = (UIInput) toValidate;
FacesMessage message = new FacesMessage("Invalid Email");
context.addMessage(toValidate.getClientId(context), message);
uiInput.setValid(false);
}
示例6: validate
import javax.faces.component.UIInput; //导入方法依赖的package包/类
/**
* Validate if password and confirm password field is equals
*/
@Override
public void validate(FacesContext context, UIComponent component,
Object value) {
String password = value.toString();
UIInput uiInputConfirmPassword = (UIInput) component.getAttributes()
.get("confirmPassword");
String confirmPassword = uiInputConfirmPassword.getSubmittedValue()
.toString();
// Password and confirmPassword are required
if (password == null || password.isEmpty() || confirmPassword == null
|| confirmPassword.isEmpty()) {
return;
}
// If password and confirmPassword aren´t equal
if (!password.equals(confirmPassword)) {
uiInputConfirmPassword.setValid(false);
FacesMessage msg = guiUtils.getFacesMessage(context, FacesMessage.SEVERITY_ERROR,
"edit.user.passwordNotEqual");
throw new ValidatorException(msg);
}
}
示例7: processValidators
import javax.faces.component.UIInput; //导入方法依赖的package包/类
/**
* Validates the phone number field
* @param context - context
*/
@Override
public void processValidators(FacesContext context) {
Object value = getAttributes().get("required");
boolean required = false;
if(value != null && (Boolean)value) {
required = (Boolean)value;
}
UIInput areaCode = (UIInput)findComponent(AREA_CODE);
UIInput prefix = (UIInput)findComponent(PREFIX);
UIInput lineNumber = (UIInput)findComponent(LINE_NUMBER);
int provided = 0;
String areaCodeStr = (String)areaCode.getSubmittedValue();
if(areaCodeStr.length() < 3 && required) {
areaCode.setValid(false);
} else if (areaCodeStr.length() == 3) {
provided = provided | 0x1;
}
String prefixStr = (String)prefix.getSubmittedValue();
if(prefixStr.length() < 3 && required) {
prefix.setValid(false);
} else if(prefixStr.length() == 3) {
provided = provided | 0x2;
}
String lineNumberStr = (String)lineNumber.getSubmittedValue();
if(lineNumberStr.length() < 4 && required) {
lineNumber.setValid(false);
} else if (lineNumberStr.length() == 4) {
provided = provided | 0x4;
}
if(required && provided != 7) {
String requiredMessage = (String)getAttributes().get("requiredMessage");
context.addMessage(lineNumber.getClientId(),new FacesMessage(
FacesMessage.SEVERITY_ERROR,requiredMessage,requiredMessage));
}
if(provided != 0 && provided != 7) {
FacesContext facesContext = FacesContext.getCurrentInstance();
Locale locale = null;
if(facesContext != null && facesContext.getViewRoot() != null) {
locale = facesContext.getViewRoot().getLocale();
if(locale == null)
locale = Locale.getDefault();
}
ResourceBundle bundle = ResourceBundle.getBundle(COMPONENT_BUNDLE,locale);
context.addMessage(lineNumber.getClientId(),new FacesMessage(
FacesMessage.SEVERITY_ERROR,bundle.getString("invalid_phone"),bundle.getString("invalid_phone")));
}
if(!required && provided > 0) {
if((provided & 0x1) != 1) {
areaCode.setValid(false);
}
if((provided & 0x2) != 2) {
prefix.setValid(false);
}
if((provided & 0x4) != 4) {
lineNumber.setValid(false);
}
}
super.processValidators(context);
}
示例8: decode
import javax.faces.component.UIInput; //导入方法依赖的package包/类
public void decode(FacesContext context, UIComponent comp)
{
UIInput component = (UIInput) comp;
if (!component.isRendered()) return;
ExternalContext external = context.getExternalContext();
HttpServletRequest request = (HttpServletRequest) external.getRequest();
String clientId = component.getClientId(context);
String directory = (String) RendererUtil.getAttribute(context, component, "directory");
// mark that this component has had decode() called during request
// processing
request.setAttribute(clientId + ATTR_REQUEST_DECODED, "true");
// check for user errors and developer errors
boolean atDecodeTime = true;
String errorMessage = checkForErrors(context, component, clientId, atDecodeTime);
if (errorMessage != null)
{
addFacesMessage(context, clientId, errorMessage);
return;
}
// get the file item
FileItem item = getFileItem(context, component);
if (item.getName() == null || item.getName().length() == 0)
{
if (component.isRequired())
{
addFacesMessage(context, clientId, "Please specify a file.");
component.setValid(false);
}
return;
}
if (directory == null || directory.length() == 0)
{
// just passing on the FileItem as the value of the component, without persisting it.
component.setSubmittedValue(item);
}
else
{
// persisting to a permenent file in a directory.
// pass on the server-side filename as the value of the component.
File dir = new File(directory);
String filename = item.getName();
filename = filename.replace('\\','/'); // replaces Windows path seperator character "\" with "/"
filename = filename.substring(filename.lastIndexOf("/")+1);
File persistentFile = new File(dir, filename);
try
{
item.write(persistentFile);
component.setSubmittedValue(persistentFile.getPath());
}
catch (Exception ex)
{
throw new FacesException(ex);
}
}
}
示例9: clearAllInputs
import javax.faces.component.UIInput; //导入方法依赖的package包/类
/**
* JSF 1.1 provides no way to cleanly discard input fields from a table when
* we know we won't use them. Ideally in such circumstances we'd specify an
* "immediate" action handler (to skip unnecessary validation checks and
* model updates), and then overwrite any existing values. However,
* JSF absolutely insists on keeping any existing input components as
* they are if validation and updating hasn't been done. When the table
* is re-rendered, all of the readonly portions of the columns will be
* refreshed from the backing bean, but the input fields will
* keep their now-incorrect values.
*
* <p>
* The easiest practical way to deal with this limitation is to avoid
* "immediate" actions when a table contains input fields, avoid side-effects
* from the bogus model updates, and stick the user with the inconvenience
* of unnecessary validation errors.
*
* <p>
* The only other solution we've found is to have the backing bean bind to
* the data table component (which just means storing a transient
* pointer to the UIData or HtmlDataTable when it's passed to the
* bean's "setTheDataTable" method), and then to have the action handler call
* this method to walk the table, look for UIInputs on each row, and
* perform the necessary magic on each to force reloading from the data model.
*
* <p>
* Usage:
* <pre>
* private transient HtmlDataTable dataTable;
* public HtmlDataTable getDataTable() {
* return dataTable;
* }
* public void setDataTable(HtmlDataTable dataTable) {
* this.dataTable = dataTable;
* }
* public void processImmediateIdSwitch(ActionEvent event) {
* // ... modify the current ID ...
* FacesUtil.clearAllInputs(dataTable);
* }
* </pre>
*/
public static void clearAllInputs(UIComponent component) {
if (log.isDebugEnabled()) log.debug("clearAllInputs " + component);
if (component instanceof UIInput) {
if (log.isDebugEnabled()) log.debug(" setValid, setValue, setLocalValueSet, setSubmittedValue");
UIInput uiInput = (UIInput)component;
uiInput.setValid(true);
uiInput.setValue(null);
uiInput.setLocalValueSet(false);
uiInput.setSubmittedValue(null);
} else if (component instanceof UIData) {
UIData dataTable = (UIData)component;
int first = dataTable.getFirst();
int rows = dataTable.getRows();
int last;
if (rows == 0) {
last = dataTable.getRowCount();
} else {
last = first + rows;
}
for (int rowIndex = first; rowIndex < last; rowIndex++) {
dataTable.setRowIndex(rowIndex);
if (dataTable.isRowAvailable()) {
for (Iterator iter = dataTable.getChildren().iterator(); iter.hasNext(); ) {
clearAllInputs((UIComponent)iter.next());
}
}
}
} else {
for (Iterator iter = component.getChildren().iterator(); iter.hasNext(); ) {
clearAllInputs((UIComponent)iter.next());
}
}
}