use of javax.faces.component.UIData in project primefaces by primefaces.
the class RowExpressionResolver method validate.
protected int validate(FacesContext context, UIComponent source, UIComponent last, String expression) {
if (!(last instanceof UIData)) {
throw new FacesException("The last resolved component must be instance of UIData to support @row. Expression: \"" + expression + "\" referenced from \"" + last.getClientId(context) + "\".");
}
try {
Matcher matcher = PATTERN.matcher(expression);
if (matcher.matches()) {
int row = Integer.parseInt(matcher.group(1));
if (row < 0) {
throw new FacesException("Row number must be greater than 0. Expression: \"" + expression + "\"");
}
UIData data = (UIData) last;
if (data.getRowCount() < row + 1) {
throw new FacesException("The row count of the target is lesser than the row number. Expression: \"" + expression + "\"");
}
return row;
} else {
throw new FacesException("Expression does not match following pattern @row(n). Expression: \"" + expression + "\"");
}
} catch (Exception e) {
throw new FacesException("Expression does not match following pattern @row(n). Expression: \"" + expression + "\"", e);
}
}
use of javax.faces.component.UIData in project primefaces by primefaces.
the class UIDataContextCallback method invokeContextCallback.
@Override
public void invokeContextCallback(FacesContext fc, UIComponent component) {
String[] idTokens = dragId.split(String.valueOf(UINamingContainer.getSeparatorChar(fc)));
String dataId = idTokens[idTokens.length - 2];
if (component instanceof UITree) {
UITree uiTree = (UITree) component;
uiTree.setRowKey(dataId);
data = uiTree.getRowNode();
uiTree.setRowKey(null);
} else {
UIData uiData = (UIData) component;
uiData.setRowIndex(Integer.parseInt(dataId));
data = uiData.getRowData();
uiData.setRowIndex(-1);
}
}
use of javax.faces.component.UIData in project primefaces by primefaces.
the class Droppable method queueEvent.
@Override
public void queueEvent(FacesEvent event) {
FacesContext context = getFacesContext();
if (ComponentUtils.isRequestSource(this, context)) {
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
String clientId = getClientId(context);
AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
if ("drop".equals(eventName)) {
String dragId = params.get(clientId + "_dragId");
String dropId = params.get(clientId + "_dropId");
DragDropEvent dndEvent = null;
String datasourceId = getDatasource();
if (datasourceId != null) {
UIData datasource = findDatasource(context, this, datasourceId);
String[] idTokens = dragId.split(String.valueOf(UINamingContainer.getSeparatorChar(context)));
int rowIndex = Integer.parseInt(idTokens[idTokens.length - 2]);
datasource.setRowIndex(rowIndex);
Object data = datasource.getRowData();
datasource.setRowIndex(-1);
dndEvent = new DragDropEvent(this, behaviorEvent.getBehavior(), dragId, dropId, data);
} else {
dndEvent = new DragDropEvent(this, behaviorEvent.getBehavior(), dragId, dropId);
}
super.queueEvent(dndEvent);
}
} else {
super.queueEvent(event);
}
}
use of javax.faces.component.UIData in project empire-db by apache.
the class TagEncodingHelper method findRecordComponent.
public Object findRecordComponent() {
// already present?
if (this.recordTag != null)
return this.recordTag.getRecord();
if (this.uiDataTag != null) {
// check row available
if (this.uiDataTag.isRowAvailable())
return this.uiDataTag.getRowData();
// row not available (possibly deleted)
return null;
}
// walk upwards the parent component tree and return the first record component found (if any)
UIComponent parent = component;
while ((parent = parent.getParent()) != null) {
if (parent instanceof RecordTag) {
this.recordTag = (RecordTag) parent;
return this.recordTag.getRecord();
}
if (parent instanceof UIData) {
this.uiDataTag = (UIData) parent;
this.insideUIData = true;
return (this.uiDataTag.isRowAvailable() ? this.uiDataTag.getRowData() : null);
}
}
return null;
}
use of javax.faces.component.UIData in project empire-db by apache.
the class InputControl method getInputComponent.
protected UIInput getInputComponent(UIComponent parent) {
// default implementation
int count = parent.getChildCount();
if (count < 1)
return null;
// find the UIInput component (only one allowed here)
UIInput inp = null;
for (int i = 0; i < count; i++) {
// check UIInput
UIComponent comp = parent.getChildren().get(i);
if (comp instanceof UIInput) {
if (inp != null)
throw new UnexpectedReturnValueException(comp, "comp.getChildren().get(" + String.valueOf(i) + ")");
inp = (UIInput) comp;
}
}
// No UIInput found
if (inp == null) {
// Check whether inside a DataTable (javax.faces.component.UIData)
for (UIComponent p = parent.getParent(); p != null; p = p.getParent()) {
// Check whether inside UIData
if (p instanceof UIData) {
log.info("Ignore value component for id '{}' inside a DataTable (javax.faces.component.UIData)", parent.getClientId());
return null;
}
}
// Should not happen!
throw new UnexpectedReturnValueException(null, "comp.getChildren().get()");
}
// found one
return inp;
}
Aggregations