use of org.apache.myfaces.tobago.internal.renderkit.Command in project myfaces-tobago by apache.
the class TreeSelectRenderer method encodeBeginInternal.
@Override
public void encodeBeginInternal(final FacesContext facesContext, final T component) throws IOException {
final AbstractUITree tree = ComponentUtils.findAncestor(component, AbstractUITree.class);
final AbstractUITreeNodeBase node = ComponentUtils.findAncestor(component, AbstractUITreeNodeBase.class);
final AbstractUIData data = ComponentUtils.findAncestor(node, AbstractUIData.class);
final TobagoResponseWriter writer = getResponseWriter(facesContext);
if (data instanceof AbstractUITreeListbox) {
writer.write(StringUtils.defaultString(component.getLabel()));
return;
}
final String id = component.getClientId(facesContext);
final String currentValue = getCurrentValue(facesContext, component);
final boolean checked;
if (component.isValueStoredInState()) {
checked = data.getSelectedState().isSelected(node.getPath());
} else {
checked = "true".equals(currentValue);
}
final boolean folder = data.isFolder();
final Selectable selectable = data.getSelectable();
final boolean showFormCheck = component.isShowCheckbox() && selectable != Selectable.none && (!selectable.isLeafOnly() || !folder);
writer.startElement(HtmlElements.TOBAGO_TREE_SELECT);
writer.writeClassAttribute(component.getCustomClass(), showFormCheck ? BootstrapClass.FORM_CHECK_INLINE : null, showFormCheck && selectable.isMulti() ? BootstrapClass.FORM_CHECK : null, showFormCheck && selectable.isSingle() ? BootstrapClass.FORM_CHECK : null);
HtmlRendererUtils.writeDataAttributes(facesContext, writer, component);
if (showFormCheck) {
writer.startElement(HtmlElements.INPUT);
writer.writeClassAttribute(BootstrapClass.FORM_CHECK_INPUT);
if (selectable.isSingle()) {
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.RADIO);
writer.writeNameAttribute(getClientIdWithoutRowIndex(data, id));
} else {
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.CHECKBOX);
writer.writeNameAttribute(id);
}
writer.writeAttribute(HtmlAttributes.VALUE, id, false);
// TODO: ID must be at the outer tag
writer.writeIdAttribute(id);
writer.writeAttribute(HtmlAttributes.CHECKED, checked);
writer.endElement(HtmlElements.INPUT);
}
final String label = component.getLabel();
writer.startElement(HtmlElements.LABEL);
writer.writeClassAttribute(showFormCheck ? BootstrapClass.FORM_CHECK_LABEL : null);
final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, component);
if (title != null) {
writer.writeAttribute(HtmlAttributes.TITLE, title, true);
}
writer.writeAttribute(HtmlAttributes.FOR, id, false);
writer.writeText(label);
writer.endElement(HtmlElements.LABEL);
if (showFormCheck) {
final CommandMap behaviorCommands = getBehaviorCommands(facesContext, component);
if (behaviorCommands != null) {
Map<ClientBehaviors, Command> other = behaviorCommands.getOther();
if (other != null) {
Command change = other.get(ClientBehaviors.change);
change.setExecute(change.getExecute() + " " + tree.getBaseClientId(facesContext));
change.setRender(change.getRender() + " " + tree.getBaseClientId(facesContext));
}
}
encodeBehavior(writer, behaviorCommands);
}
writer.endElement(HtmlElements.TOBAGO_TREE_SELECT);
}
use of org.apache.myfaces.tobago.internal.renderkit.Command in project myfaces-tobago by apache.
the class RendererBase method encodeBehavior.
/**
* Renders the tobago-behavior tag.
*
* @since 5.0
*/
protected void encodeBehavior(final TobagoResponseWriter writer, final CommandMap behaviorCommands) throws IOException {
if (behaviorCommands != null) {
final Command click = behaviorCommands.getClick();
if (click != null) {
encodeBehavior(writer, ClientBehaviors.click, click);
}
final Map<ClientBehaviors, Command> other = behaviorCommands.getOther();
if (other != null) {
for (Map.Entry<ClientBehaviors, Command> entry : other.entrySet()) {
encodeBehavior(writer, entry.getKey(), entry.getValue());
}
}
}
}
use of org.apache.myfaces.tobago.internal.renderkit.Command in project myfaces-tobago by apache.
the class JsonUtilsUnitTest method testCommandMap.
@Test
public void testCommandMap() {
CommandMap map = new CommandMap();
map.addCommand(ClientBehaviors.blur, new Command("doit", null, false, "field", "execute", "render", "Do \"you\" want?", 100, new Collapse(Collapse.Operation.hide, "box"), false));
final String expected = ("{'blur':" + "{'clientId':'doit'," + "'transition':false," + "'target':'field'," + "'execute':'execute'," + "'render':'render'," + "'collapse':{'transition':'hide','forId':'box'}," + "'confirmation':'Do \\'you\\' want?'," + "'delay':100}}").replaceAll("'", "\"");
Assertions.assertEquals(expected, JsonUtils.encode(map), "command map");
}
use of org.apache.myfaces.tobago.internal.renderkit.Command in project myfaces-tobago by apache.
the class RendererBase method getBehaviorCommands.
protected CommandMap getBehaviorCommands(final FacesContext facesContext, final ClientBehaviorHolder clientBehaviorHolder) {
CommandMap commandMap = null;
for (final Map.Entry<String, List<ClientBehavior>> entry : clientBehaviorHolder.getClientBehaviors().entrySet()) {
final String eventName = entry.getKey();
final ClientBehaviorContext clientBehaviorContext = getClientBehaviorContext(facesContext, clientBehaviorHolder, eventName);
for (final ClientBehavior clientBehavior : entry.getValue()) {
if (clientBehavior instanceof EventBehavior) {
final EventBehavior eventBehavior = (EventBehavior) clientBehavior;
final AbstractUIEvent abstractUIEvent = RenderUtils.getAbstractUIEvent((UIComponent) clientBehaviorHolder, eventBehavior);
if (abstractUIEvent != null && abstractUIEvent.isRendered() && !abstractUIEvent.isDisabled()) {
for (List<ClientBehavior> children : abstractUIEvent.getClientBehaviors().values()) {
for (ClientBehavior child : children) {
final CommandMap childMap = getCommandMap(facesContext, clientBehaviorContext, child);
commandMap = CommandMap.merge(commandMap, childMap);
}
}
}
}
final CommandMap map = getCommandMap(facesContext, clientBehaviorContext, clientBehavior);
commandMap = CommandMap.merge(commandMap, map);
}
}
// if there is no explicit behavior (with f:ajax or tc:event), use the command properties as default.
if ((commandMap == null || commandMap.isEmpty()) && clientBehaviorHolder instanceof AbstractUICommand) {
if (commandMap == null) {
commandMap = new CommandMap();
}
final AbstractUICommand holder = (AbstractUICommand) clientBehaviorHolder;
commandMap.addCommand(ClientBehaviors.click, new Command(holder.getClientId(facesContext), holder.getFieldId(facesContext), holder.isTransition(), holder.getTarget(), null, null, ComponentUtils.getConfirmation(holder), null, TobagoClientBehaviorRenderer.createCollapsible(facesContext, holder), holder.isOmit()));
}
return commandMap;
}
use of org.apache.myfaces.tobago.internal.renderkit.Command in project myfaces-tobago by apache.
the class RenderUtils method getBehaviorCommands.
/**
* @deprecated since 5.0.0
*/
@Deprecated
public static CommandMap getBehaviorCommands(final FacesContext facesContext, final ClientBehaviorHolder clientBehaviorHolder) {
CommandMap commandMap = null;
for (final Map.Entry<String, List<ClientBehavior>> entry : clientBehaviorHolder.getClientBehaviors().entrySet()) {
final String eventName = entry.getKey();
final ClientBehaviorContext clientBehaviorContext = getClientBehaviorContext(facesContext, clientBehaviorHolder, eventName);
for (final ClientBehavior clientBehavior : entry.getValue()) {
if (clientBehavior instanceof EventBehavior) {
final EventBehavior eventBehavior = (EventBehavior) clientBehavior;
final AbstractUIEvent abstractUIEvent = getAbstractUIEvent((UIComponent) clientBehaviorHolder, eventBehavior);
if (abstractUIEvent != null && abstractUIEvent.isRendered() && !abstractUIEvent.isDisabled()) {
for (List<ClientBehavior> children : abstractUIEvent.getClientBehaviors().values()) {
for (ClientBehavior child : children) {
final CommandMap childMap = getCommandMap(facesContext, clientBehaviorContext, child);
commandMap = CommandMap.merge(commandMap, childMap);
}
}
}
}
final CommandMap map = getCommandMap(facesContext, clientBehaviorContext, clientBehavior);
commandMap = CommandMap.merge(commandMap, map);
}
}
// if there is no explicit behavior (with f:ajax or tc:event), use the command properties as default.
if ((commandMap == null || commandMap.isEmpty()) && clientBehaviorHolder instanceof AbstractUICommand) {
if (commandMap == null) {
commandMap = new CommandMap();
}
final AbstractUICommand holder = (AbstractUICommand) clientBehaviorHolder;
commandMap.addCommand(ClientBehaviors.click, new Command(holder.getClientId(facesContext), holder.getFieldId(facesContext), holder.isTransition(), holder.getTarget(), null, null, ComponentUtils.getConfirmation(holder), null, TobagoClientBehaviorRenderer.createCollapsible(facesContext, holder), holder.isOmit()));
}
return commandMap;
}
Aggregations