Java Code Examples for javax.faces.component.UIInput#isRequired()
The following examples show how to use
javax.faces.component.UIInput#isRequired() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoreRenderer.java From BootsFaces-OSP with Apache License 2.0 | 6 votes |
/** * Yields the value of the required and error level CSS class. * * @param input * must not be null * @param clientId * must not be null * @return can never be null */ public String getErrorAndRequiredClass(UIInput input, String clientId) { String styleClass = ""; if (BsfUtils.isLegacyFeedbackClassesEnabled()) { styleClass = FacesMessages.getErrorSeverityClass(clientId); } if (input.isRequired()) { styleClass += " bf-required"; } else { Annotation[] readAnnotations = ELTools.readAnnotations(input); if (null != readAnnotations && readAnnotations.length > 0) { for (Annotation a : readAnnotations) { if ((a.annotationType().getName().endsWith("NotNull")) || (a.annotationType().getName().endsWith("NotEmpty")) || (a.annotationType().getName().endsWith("NotBlank"))) { styleClass += " bf-required"; break; } } } } return styleClass; }
Example 2
Source File: FormTableRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
protected void writeFormRowLabel(FacesContext context, ResponseWriter w, FormLayout c, ComputedFormData formData, UIFormLayoutRow row, UIInput edit, String label) throws IOException { if(StringUtil.isNotEmpty(label)) { w.startElement("label", c); // $NON-NLS-1$ if(edit!=null && !ReadOnlyAdapterRenderer.isReadOnly(context, edit)) { w.writeAttribute("for", edit.getClientId(context), null); // $NON-NLS-1$ } // Required mark if(edit!=null && !formData.isDisableRequiredMarks() && edit.isRequired()) { writeFormRowRequiredContent(context, w, c, row, edit); } // Label text writeFormRowDataLabel(context, w, c, row, edit, label); w.endElement("label"); // $NON-NLS-1$ } else { UIComponent facet = row.getFacet(UIFormLayoutRow.FACET_LABEL); if(facet!=null) { writeFormRowDataLabelFacet(context, w, c, row, edit, facet); } else { JSUtil.writeTextBlank(w); // } } }
Example 3
Source File: Datepicker.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * 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; }
Example 4
Source File: InputFileUploadRenderer.java From sakai with Educational Community License v2.0 | 4 votes |
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); } } }
Example 5
Source File: InputFileUploadRenderer.java From sakai with Educational Community License v2.0 | 4 votes |
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); } } }
Example 6
Source File: InputFileUploadRenderer.java From sakai with Educational Community License v2.0 | 4 votes |
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); } } }
Example 7
Source File: InputFileUploadRenderer.java From sakai with Educational Community License v2.0 | 4 votes |
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); } } }