javax.faces.component.EditableValueHolder Java Examples
The following examples show how to use
javax.faces.component.EditableValueHolder.
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: ResetInputAjaxActionListener.java From ctsms with GNU Lesser General Public License v2.1 | 6 votes |
@Override public VisitResult visit(VisitContext context, UIComponent target) { FacesContext facesContext = context.getFacesContext(); Collection<String> executeIds = facesContext.getPartialViewContext().getExecuteIds(); if (executeIds.contains(target.getClientId(facesContext))) { return VisitResult.REJECT; } if (target instanceof EditableValueHolder) { ((EditableValueHolder) target).resetValue(); } else if (context.getIdsToVisit() != VisitContext.ALL_IDS) { // Render ID didn't specifically point an EditableValueHolder. Visit all children as well. if (!SKIP_COMPONENTS.contains(target.getClass())) { try { target.visitTree(createVisitContext(facesContext, null, context.getHints()), VISIT_CALLBACK); } catch (Exception e) { } } } return VisitResult.ACCEPT; }
Example #2
Source File: TabRepeat.java From BootsFaces-OSP with Apache License 2.0 | 6 votes |
private void saveChildState(FacesContext faces, UIComponent c) { if (c instanceof EditableValueHolder && !c.isTransient()) { String clientId = c.getClientId(faces); SavedState ss = this.getChildState().get(clientId); if (ss == null) { ss = new SavedState(); this.getChildState().put(clientId, ss); } ss.populate((EditableValueHolder) c); } // continue hack Iterator itr = c.getFacetsAndChildren(); while (itr.hasNext()) { saveChildState(faces, (UIComponent) itr.next()); } }
Example #3
Source File: PagerRenderer.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Save the new paging state back to the given component (adjusting firstItem and lastItem first if necessary) */ private static void adjustState(FacesContext context, UIComponent component, int firstItem, int lastItem, int pageSize, int totalItems, int newFirstItem, int newLastItem, int newPageSize) { // recalculate last item int theNewLastItem = Math.min(newFirstItem + newPageSize, totalItems); int theNewFirstItem = newFirstItem; if (newPageSize <= 0) { // if displaying all items theNewFirstItem = 0; theNewLastItem = totalItems; } // we don't count lastItem changing as a full state change (value of this component doesn't change) if (theNewLastItem != lastItem) RendererUtil.setAttribute(context, component, "lastItem", new Integer(theNewLastItem)); // send the newly changed values where they need to go if (newPageSize != pageSize) RendererUtil.setAttribute(context, component, "pageSize", new Integer(newPageSize)); if (theNewFirstItem != firstItem) RendererUtil.setAttribute(context, component, "firstItem", new Integer(theNewFirstItem)); // Set value, which causes registered valueChangeListener to be called EditableValueHolder evh = (EditableValueHolder) component; String newValue = formatValue(theNewFirstItem, newPageSize); Object oldValue = (String)evh.getValue(); if (!newValue.equals(oldValue)) { if (oldValue != null) { evh.setSubmittedValue(newValue); evh.setValid(true); } else { // Need to initialize value string based on initial parameters. if (log.isDebugEnabled()) log.debug("initializing value to " + newValue); evh.setValue(newValue); } } }
Example #4
Source File: PagerRenderer.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Save the new paging state back to the given component (adjusting firstItem and lastItem first if necessary) */ private static void adjustState(FacesContext context, UIComponent component, int firstItem, int lastItem, int pageSize, int totalItems, int newFirstItem, int newLastItem, int newPageSize) { // recalculate last item newLastItem = Math.min(newFirstItem + newPageSize, totalItems); if (newPageSize <= 0) { // if displaying all items newFirstItem = 0; newLastItem = totalItems; } // we don't count lastItem changing as a full state change (value of this component doesn't change) if (newLastItem != lastItem) RendererUtil.setAttribute(context, component, "lastItem", new Integer(newLastItem)); // send the newly changed values where they need to go if (newPageSize != pageSize) RendererUtil.setAttribute(context, component, "pageSize", new Integer(newPageSize)); if (newFirstItem != firstItem) RendererUtil.setAttribute(context, component, "firstItem", new Integer(newFirstItem)); // Set value, which causes registered valueChangeListener to be called EditableValueHolder evh = (EditableValueHolder) component; String newValue = formatValue(newFirstItem, newPageSize); Object oldValue = (String)evh.getValue(); if (!newValue.equals(oldValue)) { if (oldValue != null) { evh.setSubmittedValue(newValue); evh.setValid(true); } else { // Need to initialize value string based on initial parameters. if (log.isDebugEnabled()) log.debug("initializing value to " + newValue); evh.setValue(newValue); } } }
Example #5
Source File: TabRepeat.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
private void restoreChildState(FacesContext faces, UIComponent c) { // reset id String id = c.getId(); c.setId(id); // hack if (c instanceof EditableValueHolder) { EditableValueHolder evh = (EditableValueHolder) c; String clientId = c.getClientId(faces); SavedState ss = this.getChildState().get(clientId); if (ss != null) { ss.apply(evh); } else { String childId = clientId.substring(initialClientId.length() + 1); childId = childId.substring(childId.indexOf(getSeparatorChar(faces)) + 1); childId = initialClientId + getSeparatorChar(faces) + childId; if (initialChildState.containsKey(childId)) { SavedState initialState = initialChildState.get(childId); initialState.apply(evh); } else { NullState.apply(evh); } } } // continue hack Iterator itr = c.getFacetsAndChildren(); while (itr.hasNext()) { restoreChildState(faces, (UIComponent) itr.next()); } }
Example #6
Source File: TabRepeat.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Recursively create the initial state for the given component. * * @param facesContext * the Faces context. * @param component * the UI component to save the state for. * @see #saveInitialChildState(javax.faces.context.FacesContext) */ private void saveInitialChildState(FacesContext facesContext, UIComponent component) { if (component instanceof EditableValueHolder && !component.isTransient()) { String clientId = component.getClientId(facesContext); SavedState state = new SavedState(); initialChildState.put(clientId, state); state.populate((EditableValueHolder) component); } Iterator<UIComponent> iterator = component.getFacetsAndChildren(); while (iterator.hasNext()) { saveChildState(facesContext, iterator.next()); } }
Example #7
Source File: ReadOnlyRadioGroupRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
@Override public void decode(FacesContext context, UIComponent component) { // SPR # LHEY9QHH58 // Ensure that when a parent panel control is read-only // that we do not save "" (empty string) as the current field value. // super.decode(context, component); // We should reset the submitted value as it might be validated otherwise if(component instanceof EditableValueHolder) { ((EditableValueHolder)component).setSubmittedValue(null); } }
Example #8
Source File: ReadOnlyCheckboxGroupRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
@Override public void decode(FacesContext context, UIComponent component) { // SPR # LHEY9QHH58 // Ensure that when a parent panel control is read-only // that we do not save (new String[0]), empty string array, as the current field value. // super.decode(context, component); // We should reset the submitted value as it might be validated otherwise if(component instanceof EditableValueHolder) { ((EditableValueHolder)component).setSubmittedValue(null); } }
Example #9
Source File: PagerRenderer.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Save the new paging state back to the given component (adjusting firstItem and lastItem first if necessary) */ private static void adjustState(FacesContext context, UIComponent component, int firstItem, int lastItem, int pageSize, int totalItems, int newFirstItem, int newLastItem, int newPageSize) { // recalculate last item int theNewLastItem = Math.min(newFirstItem + newPageSize, totalItems); int theNewFirstItem = newFirstItem; if (newPageSize <= 0) { // if displaying all items theNewFirstItem = 0; theNewLastItem = totalItems; } // we don't count lastItem changing as a full state change (value of this component doesn't change) if (theNewLastItem != lastItem) RendererUtil.setAttribute(context, component, "lastItem", new Integer(theNewLastItem)); // send the newly changed values where they need to go if (newPageSize != pageSize) RendererUtil.setAttribute(context, component, "pageSize", new Integer(newPageSize)); if (theNewFirstItem != firstItem) RendererUtil.setAttribute(context, component, "firstItem", new Integer(theNewFirstItem)); // Set value, which causes registered valueChangeListener to be called EditableValueHolder evh = (EditableValueHolder) component; String newValue = formatValue(theNewFirstItem, newPageSize); Object oldValue = (String)evh.getValue(); if (!newValue.equals(oldValue)) { if (oldValue != null) { evh.setSubmittedValue(newValue); evh.setValid(true); } else { // Need to initialize value string based on initial parameters. if (log.isDebugEnabled()) log.debug("initializing value to " + newValue); evh.setValue(newValue); } } }
Example #10
Source File: PagerRenderer.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Save the new paging state back to the given component (adjusting firstItem and lastItem first if necessary) */ private static void adjustState(FacesContext context, UIComponent component, int firstItem, int lastItem, int pageSize, int totalItems, int newFirstItem, int newLastItem, int newPageSize) { // recalculate last item newLastItem = Math.min(newFirstItem + newPageSize, totalItems); if (newPageSize <= 0) { // if displaying all items newFirstItem = 0; newLastItem = totalItems; } // we don't count lastItem changing as a full state change (value of this component doesn't change) if (newLastItem != lastItem) RendererUtil.setAttribute(context, component, "lastItem", new Integer(newLastItem)); // send the newly changed values where they need to go if (newPageSize != pageSize) RendererUtil.setAttribute(context, component, "pageSize", new Integer(newPageSize)); if (newFirstItem != firstItem) RendererUtil.setAttribute(context, component, "firstItem", new Integer(newFirstItem)); // Set value, which causes registered valueChangeListener to be called EditableValueHolder evh = (EditableValueHolder) component; String newValue = formatValue(newFirstItem, newPageSize); Object oldValue = (String)evh.getValue(); if (!newValue.equals(oldValue)) { if (oldValue != null) { evh.setSubmittedValue(newValue); evh.setValid(true); } else { // Need to initialize value string based on initial parameters. if (log.isDebugEnabled()) log.debug("initializing value to " + newValue); evh.setValue(newValue); } } }
Example #11
Source File: SkipRequiredValidator.java From ctsms with GNU Lesser General Public License v2.1 | 4 votes |
private static boolean isRequired(UIComponent component) { if (component instanceof EditableValueHolder) { return ((EditableValueHolder) component).isRequired(); } return false; }
Example #12
Source File: UploadRenderer.java From sakai with Educational Community License v2.0 | 4 votes |
public void decode(FacesContext context, UIComponent component){ log.debug("**** decode ="); ExternalContext external = context.getExternalContext(); HttpServletRequest request = (HttpServletRequest) external.getRequest(); String clientId = component.getClientId(context); WrappedUpload item = wrapUpload(request, clientId + UPLOAD); log.debug("clientId = {}", clientId); log.debug("wrappedUpload = {}", item); ServerConfigurationService serverConfigurationService = ComponentManager.get(ServerConfigurationService.class); Long maxSize = Long.valueOf(serverConfigurationService.getString("samigo.sizeMax", "40960")); // Check if file > maxSize allowed if (item != null && item.getSize()/1000 > maxSize.intValue()){ ((ServletContext)external.getContext()).setAttribute("TEMP_FILEUPLOAD_SIZE", Long.valueOf(item.getSize()/1000)); ((EditableValueHolder) component).setSubmittedValue("SizeTooBig:" + item.getName()); return; } Object target; ValueBinding binding = component.getValueBinding("target"); if (binding != null) target = binding.getValue(context); else target = component.getAttributes().get("target"); String repositoryPath = serverConfigurationService.getString("samigo.answerUploadRepositoryPath", "${sakai.home}/samigo/answerUploadRepositoryPath/"); log.debug("****{}", repositoryPath); if (target != null){ File dir = new File(repositoryPath+target.toString()); //directory where file would be saved if (!dir.exists()) dir.mkdirs(); if (item != null && !("").equals(item.getName())){ String fullname = item.getName(); fullname = fullname.replace('\\','/'); // replace c:\fullname to c:/fullname fullname = fullname.substring(fullname.lastIndexOf("/")+1); int dot_index = fullname.lastIndexOf("."); String filename = ""; if (dot_index < 0) { filename = fullname + "_" + (new Date()).getTime(); } else { filename = fullname.substring(0, dot_index) + "_" + (new Date()).getTime() + fullname.substring(dot_index); } String filePath = dir.getPath()+"/"+filename; log.debug("**1. filename= {}", filePath); try { //if (mediaIsValid) item.write(file); item.write(filePath); // change value so we can evoke the listener ((EditableValueHolder) component).setSubmittedValue(filePath); } catch (Exception ex){ throw new FacesException(ex); } } } }
Example #13
Source File: CoreRenderer.java From BootsFaces-OSP with Apache License 2.0 | 4 votes |
/** * Algorithm works as follows; - If it's an input component, submitted value is * checked first since it'd be the value to be used in case validation errors * terminates jsf lifecycle - Finally the value of the component is retrieved * from backing bean and if there's a converter, converted value is returned * * @param fc * FacesContext instance * @param c * UIComponent instance whose value will be returned * @return End text */ public String getValue2Render(FacesContext fc, UIComponent c) { if (c instanceof ValueHolder) { if (c instanceof EditableValueHolder) { Object sv = ((EditableValueHolder) c).getSubmittedValue(); if (sv != null) { return sv.toString(); } } ValueHolder vh = (ValueHolder) c; Object val = vh.getValue(); // format the value as string if (val != null) { /* * OLD Converter converter = getConverter(fc, vh); */ /* NEW */ Converter converter = vh.getConverter(); if (converter == null) { Class<?> valueType = val.getClass(); if (valueType == String.class && (null == fc.getApplication().createConverter(String.class))) { return (String) val; } converter = fc.getApplication().createConverter(valueType); } /* END NEW */ if (converter != null) return converter.getAsString(fc, c, val); else return val.toString(); // Use toString as a fallback if // there is no explicit or implicit // converter } else { // component is a value holder but has no value return null; } } // component it not a value holder return null; }
Example #14
Source File: TabRepeat.java From BootsFaces-OSP with Apache License 2.0 | 4 votes |
public void populate(EditableValueHolder evh) { this.value = evh.getLocalValue(); this.valid = evh.isValid(); this.submittedValue = evh.getSubmittedValue(); this.localValueSet = evh.isLocalValueSet(); }
Example #15
Source File: TabRepeat.java From BootsFaces-OSP with Apache License 2.0 | 4 votes |
public void apply(EditableValueHolder evh) { evh.setValue(this.value); evh.setValid(this.valid); evh.setSubmittedValue(this.submittedValue); evh.setLocalValueSet(this.localValueSet); }
Example #16
Source File: UploadRenderer.java From sakai with Educational Community License v2.0 | 4 votes |
public void decode(FacesContext context, UIComponent component){ log.debug("**** decode ="); ExternalContext external = context.getExternalContext(); HttpServletRequest request = (HttpServletRequest) external.getRequest(); String clientId = component.getClientId(context); WrappedUpload item = wrapUpload(request, clientId + UPLOAD); log.debug("clientId = {}", clientId); log.debug("wrappedUpload = {}", item); ServerConfigurationService serverConfigurationService = ComponentManager.get(ServerConfigurationService.class); Long maxSize = Long.valueOf(serverConfigurationService.getString("samigo.sizeMax", "40960")); // Check if file > maxSize allowed if (item != null && item.getSize()/1000 > maxSize.intValue()){ ((ServletContext)external.getContext()).setAttribute("TEMP_FILEUPLOAD_SIZE", Long.valueOf(item.getSize()/1000)); ((EditableValueHolder) component).setSubmittedValue("SizeTooBig:" + item.getName()); return; } Object target; ValueBinding binding = component.getValueBinding("target"); if (binding != null) target = binding.getValue(context); else target = component.getAttributes().get("target"); String repositoryPath = serverConfigurationService.getString("samigo.answerUploadRepositoryPath", "${sakai.home}/samigo/answerUploadRepositoryPath/"); log.debug("****{}", repositoryPath); if (target != null){ File dir = new File(repositoryPath+target.toString()); //directory where file would be saved if (!dir.exists()) dir.mkdirs(); if (item != null && !("").equals(item.getName())){ String fullname = item.getName(); fullname = fullname.replace('\\','/'); // replace c:\fullname to c:/fullname fullname = fullname.substring(fullname.lastIndexOf("/")+1); int dot_index = fullname.lastIndexOf("."); String filename = ""; if (dot_index < 0) { filename = fullname + "_" + (new Date()).getTime(); } else { filename = fullname.substring(0, dot_index) + "_" + (new Date()).getTime() + fullname.substring(dot_index); } String filePath = dir.getPath()+"/"+filename; log.debug("**1. filename= {}", filePath); try { //if (mediaIsValid) item.write(file); item.write(filePath); // change value so we can evoke the listener ((EditableValueHolder) component).setSubmittedValue(filePath); } catch (Exception ex){ throw new FacesException(ex); } } } }