List of usage examples for javax.el ValueExpression setValue
public abstract void setValue(ELContext context, Object value);
From source file:org.richfaces.component.UICalendar.java
public void updateCurrentDate(FacesContext context, Object currentDate) { if (context == null) { throw new NullPointerException(); }// w w w.j a v a2 s .c o m // RF-1073 try { ValueExpression ve = getValueExpression("currentDate"); if (ve != null) { ELContext elContext = context.getELContext(); if (ve.getType(elContext).equals(String.class)) { DateTimeConverter convert = new DateTimeConverter(); convert.setLocale(getAsLocale(getLocale())); convert.setPattern(getDatePattern()); ve.setValue(context.getELContext(), convert.getAsString(context, this, currentDate)); return; } else if (ve.getType(elContext).equals(Calendar.class)) { Calendar c = Calendar.getInstance(); c.setTime((Date) currentDate); ve.setValue(elContext, c); return; } else { ve.setValue(elContext, currentDate); return; } } else { setCurrentDate(currentDate); } } catch (Exception e) { setValid(false); // XXX nick - kaa - add log.debug(...) if (log.isDebugEnabled()) { log.debug(" updateCurrentDate method throws exception: " + e.toString(), e); } e.printStackTrace(); String messageString = e.toString(); FacesMessage message = new FacesMessage(messageString); message.setSeverity(FacesMessage.SEVERITY_ERROR); context.addMessage(getClientId(context), message); } }
From source file:org.apache.empire.jsf2.utils.TagEncodingHelper.java
public void setDataValue(Object value) { if (getRecord() != null) { // value if (record instanceof Record) { getColumn();// w w w .j a va 2 s . co m /* special case if (value==null && getColumn().isRequired()) { // ((Record)record).isFieldRequired(column)==false log.warn("Unable to set null for required field!"); return; } */ if (isDetectFieldChange()) { // DetectFieldChange by comparing current and most recent value Object currentValue = ((Record) record).getValue(column); if (!ObjectUtils.compareEqual(currentValue, mostRecentValue)) { // Value has been changed by someone else! log.info("Concurrent data change for " + column.getName() + ". Current Value is {}. Ignoring new value {}", currentValue, value); return; } } // check whether to skip validation boolean reenableValidation = false; if (skipValidation && (record instanceof DBRecord)) { // Ignore read only values if (this.isReadOnly()) return; // Column required? if (column.isRequired() && ObjectUtils.isEmpty(value)) return; // Cannot set required value to null // Disable Validation reenableValidation = ((DBRecord) record).isValidateFieldValues(); if (reenableValidation) ((DBRecord) record).setValidateFieldValues(false); // Validation skipped for if (log.isDebugEnabled()) log.debug("Input Validation skipped for {}.", column.getName()); } // Now, set the value try { ((Record) record).setValue(column, value); mostRecentValue = value; } finally { // re-enable validation if (reenableValidation) ((DBRecord) record).setValidateFieldValues(true); } } else if (record instanceof RecordData) { // a record throw new PropertyReadOnlyException("record"); } else { // a normal bean String prop = getColumn().getBeanPropertyName(); setBeanPropertyValue(record, prop, value); } } else { // Get from tag // tag.setValue(value); ValueExpression ve = tag.getValueExpression("value"); if (ve == null) throw new PropertyReadOnlyException("value"); FacesContext ctx = FacesContext.getCurrentInstance(); ve.setValue(ctx.getELContext(), value); } }
From source file:org.openfaces.component.table.AbstractTable.java
@Override public void processUpdates(FacesContext context) { super.processUpdates(context); if (!isRendered()) return;/*from w w w. java 2 s. c om*/ processModelUpdates(context); processModelDependentUpdates(context); ValueExpression sortColumnIdExpression = getValueExpression("sortColumnId"); ELContext elContext = context.getELContext(); if (sortColumnIdExpression != null) sortColumnIdExpression.setValue(elContext, getSortColumnId()); ValueExpression sortAscendingExpression = getValueExpression("sortAscending"); if (sortAscendingExpression != null) sortAscendingExpression.setValue(elContext, isSortAscending()); List<Filter> filters = getFilters(); for (Filter filter : filters) { filter.processUpdates(context); } ColumnResizing columnResizing = getColumnResizing(); if (columnResizing != null) columnResizing.processUpdates(context); Iterable<String> submittedColumnsOrder = (Iterable<String>) getAttributes().get("submittedColumnsOrder"); if (submittedColumnsOrder != null) { getAttributes().remove("submittedColumnsOrder"); setColumnsOrder(submittedColumnsOrder); if (columnsOrder != null && ValueBindings.set(this, "columnsOrder", columnsOrder)) { columnsOrder = null; } } }
From source file:org.nuxeo.ecm.platform.ui.web.component.list.UIEditableList.java
/** * Overridden to handle diff boolean value, see NXP-16515. *///from w w w . ja v a2s .c o m public void updateModel(FacesContext context) { if (context == null) { throw new NullPointerException(); } if (!isValid() || !isLocalValueSet()) { return; } ValueExpression ve = getValueExpression("value"); if (ve != null) { Throwable caught = null; FacesMessage message = null; try { Boolean setDiff = getDiff(); if (setDiff) { // set list diff instead of the whole list // FIXME NXP-16515 // EditableModel model = getEditableModel(); // ve.setValue(context.getELContext(), model.getListDiff()); ve.setValue(context.getELContext(), getLocalValue()); } else { ve.setValue(context.getELContext(), getLocalValue()); } setValue(null); setLocalValueSet(false); } catch (ELException e) { caught = e; String messageStr = e.getMessage(); Throwable result = e.getCause(); while (null != result && result.getClass().isAssignableFrom(ELException.class)) { messageStr = result.getMessage(); result = result.getCause(); } if (null == messageStr) { message = MessageFactory.getMessage(context, UPDATE_MESSAGE_ID, MessageFactory.getLabel(context, this)); } else { message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageStr, messageStr); } setValid(false); } catch (Exception e) { caught = e; message = MessageFactory.getMessage(context, UPDATE_MESSAGE_ID, MessageFactory.getLabel(context, this)); setValid(false); } if (caught != null) { assert message != null; // PENDING(edburns): verify this is in the spec. UpdateModelException toQueue = new UpdateModelException(message, caught); ExceptionQueuedEventContext eventContext = new ExceptionQueuedEventContext(context, toQueue, this, PhaseId.UPDATE_MODEL_VALUES); context.getApplication().publishEvent(context, ExceptionQueuedEvent.class, eventContext); } } }
From source file:com.lassitercg.faces.components.sheet.Sheet.java
private void setComment(FacesContext context, Object rowKey, int col, String value) { comments.put(new RowColIndex(rowKey, col), value); final Column column = getColumns().get(col); ValueExpression valueExpression = column.getValueExpression("comment"); if (valueExpression != null) { valueExpression.setValue(context.getELContext(), value); }//from w w w . j a v a 2s. c o m }
From source file:com.lassitercg.faces.components.sheet.Sheet.java
/** * Override to update model with local values. Note that this is where * things can be fragile in that we can successfully update some values and * fail on others. There is no clean way to roll back the updates, but we * also need to fail processing.//from w ww .j ava 2 s . c om * <p> * TODO consider keeping old values as we update (need for event anyhow) and * if there is a failure attempt to roll back by updating successful model * updates with the old value. This may not all be necessary. */ @Override public void updateModel(FacesContext context) { HashSet<Object> dirtyRows = new HashSet<Object>(); Iterator<Entry<RowColIndex, String>> commentsEntries = comments.entrySet().iterator(); while (commentsEntries.hasNext()) { final Entry<RowColIndex, String> entry = commentsEntries.next(); final String newValue = entry.getValue(); final Object rowKey = entry.getKey().getRowKey(); final int col = entry.getKey().getColIndex(); final Column column = getColumns().get(col); final RowMap map = rowMap.get(rowKey); String oldValue = null; ValueExpression valueExpression = column.getValueExpression("comment"); if (valueExpression != null) { oldValue = (String) valueExpression.getValue(context.getELContext()); } commentsEntries.remove(); if (!StringUtils.equals(oldValue, newValue)) { appendUpdateEvent(map.sortedIndex, col, map.value, oldValue, newValue); dirtyRows.add(rowKey); } } Iterator<Entry<RowColIndex, Object>> entries = localValues.entrySet().iterator(); // Keep track of the dirtied rows for ajax callbacks so we can send // updates on what was touched while (entries.hasNext()) { final Entry<RowColIndex, Object> entry = entries.next(); final Object newValue = entry.getValue(); final Object rowKey = entry.getKey().getRowKey(); final int col = entry.getKey().getColIndex(); final Column column = getColumns().get(col); final RowMap map = rowMap.get(rowKey); this.setRowIndex(context, map.sortedIndex); // System.out.println("Local key=" + rowKey + " and sortedRow is " + map.sortedIndex); ValueExpression ve = column.getValueExpression(PropertyKeys.value.name()); ELContext elContext = context.getELContext(); Object oldValue = ve.getValue(elContext); if (!column.isReadonlyCell()) { ve.setValue(elContext, newValue); } entries.remove(); appendUpdateEvent(map.sortedIndex, col, map.value, oldValue, newValue); dirtyRows.add(rowKey); } setLocalValueSet(false); setRowIndex(context, -1); this.sortAndFilter(); if (context.getPartialViewContext().isPartialRequest()) this.renderRowUpdateScript(context, dirtyRows); }
From source file:org.primefaces.extensions.component.sheet.Sheet.java
/** * Override to update model with local values. Note that this is where things can be fragile in that we can successfully update some values and fail on * others. There is no clean way to roll back the updates, but we also need to fail processing. TODO consider keeping old values as we update (need for * event anyhow) and if there is a failure attempt to roll back by updating successful model updates with the old value. This may not all be necessary. */// w w w . j a v a 2 s . c om @Override public void updateModel(final FacesContext context) { final Iterator<Entry<SheetRowColIndex, Object>> entries = localValues.entrySet().iterator(); // Keep track of the dirtied rows for ajax callbacks so we can send // updates on what was touched final HashSet<String> dirtyRows = new HashSet<String>(); while (entries.hasNext()) { final Entry<SheetRowColIndex, Object> entry = entries.next(); final Object newValue = entry.getValue(); final String rowKey = entry.getKey().getRowKey(); final int col = entry.getKey().getColIndex(); final SheetColumn column = getColumns().get(col); setRowVar(context, rowKey); final Object rowVal = rowMap.get(rowKey); final ValueExpression ve = column.getValueExpression(PropertyKeys.value.name()); final ELContext elContext = context.getELContext(); final Object oldValue = ve.getValue(elContext); ve.setValue(elContext, newValue); entries.remove(); appendUpdateEvent(getRowKeyValue(context), col, rowVal, oldValue, newValue); dirtyRows.add(rowKey); } setLocalValueSet(false); setRowVar(context, null); if (context.getPartialViewContext().isPartialRequest()) { renderRowUpdateScript(context, dirtyRows); } }
From source file:org.ajax4jsf.component.UIDataAdaptor.java
/** * @return current state of this component. *///from w w w . j a v a2 s .co m public DataComponentState getComponentState() { DataComponentState state = null; if (this._currentState == null) { // Check for binding state to user bean. ValueExpression valueBinding = getValueExpression(UIDataAdaptor.COMPONENT_STATE_ATTRIBUTE); FacesContext facesContext = getFacesContext(); ELContext elContext = facesContext.getELContext(); if (null != valueBinding) { state = (DataComponentState) valueBinding.getValue(elContext); if (null == state) { // Create default state state = createComponentState(); if (!valueBinding.isReadOnly(elContext)) { // Store created state in user bean. valueBinding.setValue(elContext, state); } } } else { // Check for stored state in map for parent iterations String baseClientId = getBaseClientId(facesContext); state = (DataComponentState) this._statesMap.get(baseClientId); if (null == state) { // Create default component state state = createComponentState(); this._statesMap.put(baseClientId, state); } this._currentState = state; } } else { state = this._currentState; } return state; }
From source file:org.apache.myfaces.component.html.ext.AbstractHtmlDataTable.java
/** * Specify what column the data should be sorted on. * <p/>//from w ww .j ava 2s .co m * Note that calling this method <i>immediately</i> stores the value * via any value-binding with name "sortColumn". This is done because * this method is called by the HtmlCommandSortHeader component when * the user has clicked on a column's sort header. In this case, the * the model getter method mapped for name "value" needs to read this * value in able to return the data in the desired order - but the * HtmlCommandSortHeader component is usually "immediate" in order to * avoid validating the enclosing form. Yes, this is rather hacky - * but it works. */ public void setSortColumn(String sortColumn) { getStateHelper().put(PropertyKeys.sortColumn, sortColumn); // update model is necessary here, because processUpdates is never called // reason: HtmlCommandSortHeader.isImmediate() == true ValueExpression vb = getValueExpression("sortColumn"); if (vb != null) { vb.setValue(getFacesContext().getELContext(), sortColumn); getStateHelper().put(PropertyKeys.sortColumn, null); } setSortColumnIndex(columnNameToIndex(sortColumn)); }
From source file:org.apache.myfaces.component.html.ext.AbstractHtmlDataTable.java
public void setSortAscending(boolean sortAscending) { getStateHelper().put(PropertyKeys.sortAscending, sortAscending); // update model is necessary here, because processUpdates is never called // reason: HtmlCommandSortHeader.isImmediate() == true ValueExpression vb = getValueExpression("sortAscending"); if (vb != null) { vb.setValue(getFacesContext().getELContext(), sortAscending); getStateHelper().put(PropertyKeys.sortAscending, null); }/* w ww . ja v a2 s .co m*/ }