use of javax.faces.component.html.HtmlOutcomeTargetButton in project liferay-faces-alloy by liferay.
the class AbstractButtonRenderer method encodeBegin.
@Override
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
if (hasMenu(uiComponent)) {
UIComponent nodeMenuNav = NodeMenuNavFactory.getNodeMenuNav(uiComponent);
RenderKit renderKit = facesContext.getRenderKit();
Renderer nodeMenuNavRenderer = renderKit.getRenderer(nodeMenuNav.getFamily(), nodeMenuNav.getRendererType());
nodeMenuNavRenderer.encodeBegin(facesContext, nodeMenuNav);
} else {
ResponseWriter responseWriter = facesContext.getResponseWriter();
// It is not possible for the ButtonResponseWriter to intercept writing of the input element that is
// rendered by the JSF runtime, because endElement("input") may be called in either encodeBegin() or
// encodeEnd(). Button requires that endElement() be called in encodeEnd(), so that children can be added to
// the button if neccessary.
responseWriter.startElement(BUTTON, uiComponent);
Map<String, Object> attributes = uiComponent.getAttributes();
Boolean autofocus = (Boolean) attributes.get(AUTOFOCUS);
if (autofocus != null) {
responseWriter.writeAttribute(AUTOFOCUS, autofocus, AUTOFOCUS);
}
// Do not delegate the writing of the class or style attributes because we need to apply certain default
// classes.
StringBuilder classNames = new StringBuilder();
classNames.append(DEFAULT_BUTTON_CSS_CLASSES);
boolean disabled = (Boolean) attributes.get(DISABLED);
if (disabled) {
classNames.append(" ");
classNames.append(DISABLED_BUTTON_CSS_CLASSES);
}
RendererUtil.encodeStyleable(responseWriter, (Styleable) uiComponent, classNames.toString());
// Do not delegate the writing of the disabled attribute because the JSF runtime may disable the button
// programmatically based on navigation case matching.
responseWriter.writeAttribute("disabled", disabled, "disabled");
// Do not delegate the writing of the type attribute because the JSF runtime hard codes the type for button.
String type = (String) attributes.get("type");
responseWriter.writeAttribute("type", type, "type");
// Determine if we should delegate the rendering of onclick or render it ourselves.
Boolean delegateOnclick = Boolean.TRUE;
if (uiComponent instanceof HtmlOutcomeTargetButton) {
HtmlOutcomeTargetButton htmlOutcomeTargetButton = (HtmlOutcomeTargetButton) uiComponent;
if (htmlOutcomeTargetButton.getOutcome() == null) {
delegateOnclick = Boolean.FALSE;
String onclick = htmlOutcomeTargetButton.getOnclick();
if (onclick != null) {
// Do not delegate the writing of the onclick attribute because the JSF runtime assumes that it
// should include navigation, and we do not need to navigate in this case.
responseWriter.writeAttribute("onclick", onclick, "onclick");
}
}
}
// Do not delegate the writing of the onfocus attribute because we need to supply a script to modify the css
// class.
String onfocus = (String) attributes.get(ONFOCUS);
if (onfocus == null) {
onfocus = RETURN_FALSE;
}
StringBuilder onfocusBuilder = new StringBuilder();
onfocusBuilder.append(DEFAULT_ONFOCUS);
onfocusBuilder.append(onfocus);
responseWriter.writeAttribute(ONFOCUS, onfocusBuilder.toString(), ONFOCUS);
// Do not delegate the writing of the onblur attribute because we need to supply a script to modify the css
// class.
String onblur = (String) attributes.get(ONBLUR);
if (onblur == null) {
onblur = RETURN_FALSE;
}
StringBuilder onblurBuilder = new StringBuilder();
onblurBuilder.append(DEFAULT_ONBLUR);
onblurBuilder.append(onblur);
responseWriter.writeAttribute(ONBLUR, onblurBuilder.toString(), ONBLUR);
// Do not delegate the writing of the value attribute because the JSF runtime may not render value
Object value = (Object) attributes.get("value");
if (value != null) {
responseWriter.writeAttribute("value", value.toString(), "value");
}
// Delegate to the JSF implementation's renderer while using our own ButtonResponseWriter to control the
// output.
ButtonResponseWriter buttonResponseWriter = new ButtonResponseWriter(responseWriter, delegateOnclick);
super.encodeBegin(facesContext, uiComponent, buttonResponseWriter);
facesContext.getAttributes().put(FACES_RUNTIME_SRC, buttonResponseWriter.getSrc());
}
}
Aggregations