*/
public class ColumnResizingRenderer extends RendererBase {
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
super.encodeBegin(context, component);
ColumnResizing columnResizing = (ColumnResizing) component;
if (!columnResizing.isEnabled())
return;
UIComponent parent = component.getParent();
if (!(parent instanceof AbstractTable))
throw new IllegalStateException("<o:columnResizing> can only be placed as a child component inside of <o:dataTable> or <o:treeTable> components. Though the following parent component has been encountered: " + parent.getClass().getName());
AbstractTable table = (AbstractTable) component.getParent();
JSONObject columnParams = new JSONObject();
List<BaseColumn> columns = table.getRenderedColumns();
for (int i = 0; i < columns.size(); i++) {
BaseColumn column = columns.get(i);
boolean resizable = column.isResizable();
String minResizingWidth = column.getMinResizingWidth();
if (!resizable || minResizingWidth != null) {
JSONObject thisColumnParams = new JSONObject();
try {
if (!resizable)
thisColumnParams.put("resizable", resizable);
if (minResizingWidth != null)
thisColumnParams.put("minWidth", minResizingWidth);
columnParams.put(String.valueOf(i), thisColumnParams);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
}
boolean autoSaveState = columnResizing.getAutoSaveState();
if (autoSaveState) {
ValueExpression ve = columnResizing.getValueExpression("resizingState");
ELContext elContext = context.getELContext();
if (ve == null || ve.isReadOnly(elContext))
autoSaveState = false;
}
ScriptBuilder buf = new ScriptBuilder().initScript(context, table, "O$.Table._initColumnResizing",
columnResizing.getRetainTableWidth(),
columnResizing.getMinColWidth(),
columnResizing.getResizeHandleWidth(),
columnParams,
autoSaveState);
Rendering.renderInitScript(context, buf);
}