Java Code Examples for javax.faces.component.UIForm#getClientId()

The following examples show how to use javax.faces.component.UIForm#getClientId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AJAXRenderer.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
private static void encodeFormSubmit(UIComponent component, ResponseWriter rw, boolean evenWithoutParameters)
		throws IOException {
	String parameterList = "";
	List<UIComponent> children = component.getChildren();
	for (UIComponent parameter : children) {
		if (parameter instanceof UIParameter) {
			String value = String.valueOf(((UIParameter) parameter).getValue());
			String name = ((UIParameter) parameter).getName();
			if (null != value) {
				parameterList += ",'" + name + "':'" + value + "'";
			}
		}
	}
	if (evenWithoutParameters || parameterList.length() > 0) {
		UIForm currentForm = getSurroundingForm((UIComponent) component, false);
		parameterList = "'" + currentForm.getClientId() + "',{'" + component.getClientId() + "':'"
				+ component.getClientId() + "'" + parameterList + "}";
		rw.writeAttribute("onclick",
				encodeClick((UIComponent) component) + "BsF.submitForm(" + parameterList + ");return false;", null);
	}
}
 
Example 2
Source File: JsfRenderUtils.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void addEventHandlingHiddenFieldsIfNotExists(FacesContext context, UIComponent component) throws IOException {

        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        UIForm parentForm = findForm(component);
        String parentFormClientId = parentForm.getClientId(context);
        String eventSenderHiddenFieldFinalId = getEventSenderHiddenFieldId(parentFormClientId);
        String eventSenderHiddenFieldRenderedAttribute = getEventSenderHiddenFieldRenderedAttributeName(parentFormClientId);
        String eventArgumentHiddenFieldFinalId = getEventArgumentHiddenFieldId(parentFormClientId);
        String eventArgumentHiddenFieldRenderedAttribute = getEventArgumentHiddenFieldRenderedAttributeName(parentFormClientId);
        ResponseWriter writer = context.getResponseWriter();

        if (request.getAttribute(eventSenderHiddenFieldRenderedAttribute) == null) {
            renderEmptyHiddenField(eventSenderHiddenFieldFinalId, writer);
            request.setAttribute(eventSenderHiddenFieldRenderedAttribute, true);
        }

        if (request.getAttribute(eventArgumentHiddenFieldRenderedAttribute) == null) {
            renderEmptyHiddenField(eventArgumentHiddenFieldFinalId, writer);
            request.setAttribute(eventArgumentHiddenFieldRenderedAttribute, true);
        }
    }
 
Example 3
Source File: JsfRenderUtils.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static String getSubmitJavaScriptWithArgument(FacesContext context, UIComponent component, String eventArgument) {
    UIForm parentForm = findForm(component);
    String parentFormClientId = parentForm.getClientId(context);
    String componentClientId = component.getClientId(context);
    String eventSenderHiddenFieldId = getEventSenderHiddenFieldId(parentFormClientId);
    String eventArgumentHiddenFieldId = getEventArgumentHiddenFieldId(parentFormClientId);

    StringBuilder onClickEvent = new StringBuilder();
    onClickEvent.append("document.forms['").append(parentFormClientId).append("'].elements['");
    onClickEvent.append(eventSenderHiddenFieldId).append("'].value='").append(componentClientId).append("';");

    onClickEvent.append("document.forms['").append(parentFormClientId).append("'].elements['");
    onClickEvent.append(eventArgumentHiddenFieldId).append("'].value='").append(eventArgument).append("';");

    onClickEvent.append("document.forms['").append(parentFormClientId).append("'].submit();");

    return onClickEvent.toString();
}
 
Example 4
Source File: JsfRenderUtils.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 
 * @param context
 * @param component
 * @param uiParameterList
 * @return
 */
public static String getSubmitJavaScriptWithParameters(FacesContext context, UIComponent component,
        List<UIParameter> uiParameterList) {
    UIForm parentForm = findForm(component);
    String parentFormClientId = parentForm.getClientId(context);
    String componentClientId = component.getClientId(context);
    String eventSenderHiddenFieldId = getEventSenderHiddenFieldId(parentFormClientId);

    StringBuilder setParametersJavaScript = new StringBuilder();

    for (int i = 0; i < uiParameterList.size(); i++) {
        UIParameter parameter = uiParameterList.get(i);
        setParametersJavaScript.append("document.forms['").append(parentFormClientId).append("'].elements['")
                .append(parameter.getName()).append("'].value='").append(parameter.getValue()).append("';");

    }

    StringBuilder onClickEvent = new StringBuilder();
    onClickEvent.append("document.forms['").append(parentFormClientId).append("'].elements['");
    onClickEvent.append(eventSenderHiddenFieldId).append("'].value='").append(componentClientId).append("';");
    onClickEvent.append(setParametersJavaScript.toString());
    onClickEvent.append("document.forms['").append(parentFormClientId).append("'].submit();");

    return onClickEvent.toString();
}
 
Example 5
Source File: UICommandButton.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void decode(FacesContext context) {
    Map paramMap = context.getExternalContext().getRequestParameterMap();

    UIForm parentForm = JsfRenderUtils.findForm(this);
    String parentFormClientId = parentForm.getClientId(context);
    String eventSenderHiddenFieldId = JsfRenderUtils.getEventSenderHiddenFieldId(parentFormClientId);

    String eventSenderId = (String) paramMap.get(eventSenderHiddenFieldId);
    boolean isReset = false;

    if (this.getType() != null && this.getType().equalsIgnoreCase(INPUT_RESET_TYPE)) {
        isReset = true;
    }

    if (!isReset && (eventSenderId != null) && eventSenderId.equals(this.getClientId(context))) {
        this.queueEvent(new ActionEvent(this));
    }

}
 
Example 6
Source File: DefaultCommand.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
@Override
public void encodeEnd(FacesContext context) throws IOException {
	if (!isRendered()) {
		return;
	}
	Map<String, Object> attrs = getAttributes();

	final UIForm form = BsfUtils.getClosestForm(this);
	if (form == null) {
		throw new FacesException("The default command component must be inside a form", null);
	} else {
		String target = (String)attrs.get("target");
		if(BsfUtils.isStringValued(target)) {
			ResponseWriter rw = context.getResponseWriter();
			String formId = form.getClientId();
			String actionCommandId = ExpressionResolver.getComponentIDs(context, this, target);

			rw.startElement("script", this);

			rw.writeText("" + "$(function() { " + "    $('form#"
					+ BsfUtils.escapeJQuerySpecialCharsInSelector(formId) + " input').keypress(function (e) { "
					+ "    if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) { "
					+ "        document.getElementsByName('" + actionCommandId + "')[0].click();return false; "
					+ "    } else { return true; "
					+ "    } " + "    }); " + "});", null);
			
			rw.writeText("" + "$(function() { " + "    $('form#"
					+ BsfUtils.escapeJQuerySpecialCharsInSelector(formId) + " textarea').keypress(function (e) { "
					+ "    if ((e.ctrlKey && e.which && e.which === 13) || (e.ctrlKey && e.keyCode && e.keyCode === 13)) { "
					+ "        document.getElementsByName('" + actionCommandId + "')[0].click();return false; "
					+ "    } else { return true; "
					+ "    } " + "    }); " + "});", null);
			
			rw.endElement("script");
		} else {
			throw new FacesException("The default command component needs a defined target ID", null);
		}
	}
}
 
Example 7
Source File: UICommandLink.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void decode(FacesContext context) {
    Map paramMap = context.getExternalContext().getRequestParameterMap();

    UIForm parentForm = JsfRenderUtils.findForm(this);
    String parentFormClientId = parentForm.getClientId(context);
    String eventSenderHiddenFieldId = JsfRenderUtils.getEventSenderHiddenFieldId(parentFormClientId);

    String eventSenderId = (String) paramMap.get(eventSenderHiddenFieldId);

    if (eventSenderId != null && eventSenderId.equals(this.getClientId(context))) {
        this.queueEvent(new ActionEvent(this));
    }
}
 
Example 8
Source File: JsfRenderUtils.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String getSubmitJavaScript(FacesContext context, UIComponent component) {
    UIForm parentForm = findForm(component);
    String parentFormClientId = parentForm.getClientId(context);
    String componentClientId = component.getClientId(context);
    String eventSenderHiddenFieldId = getEventSenderHiddenFieldId(parentFormClientId);

    StringBuilder onClickEvent = new StringBuilder();
    onClickEvent.append("document.forms['").append(parentFormClientId).append("'].elements['");
    onClickEvent.append(eventSenderHiddenFieldId).append("'].value='").append(componentClientId);

    onClickEvent.append("';document.forms['").append(parentFormClientId).append("'].submit();");

    return onClickEvent.toString();
}
 
Example 9
Source File: JsfRenderUtils.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void addHiddenFieldsForParametersIfNotExists(FacesContext context, UIComponent parentComponent,
        List<UIParameter> uiParameters) throws IOException {

    UIForm parentForm = findForm(parentComponent);
    String parentFormClientId = parentForm.getClientId(context);
    ResponseWriter writer = context.getResponseWriter();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

    for (int i = 0; i < uiParameters.size(); i++) {
        UIParameter parameter = uiParameters.get(i);
        addHiddenFieldForParameterIfNotExists(parentFormClientId, request, writer, parameter.getName());
    }
}
 
Example 10
Source File: JsfRenderUtils.java    From fenixedu-academic with GNU Lesser General Public License v3.0 3 votes vote down vote up
public static String getClearEventSenderFieldJavaScript(FacesContext context, UIComponent component) {
    UIForm parentForm = findForm(component);
    String parentFormClientId = parentForm.getClientId(context);
    String eventSenderHiddenFieldId = getEventSenderHiddenFieldId(parentFormClientId);

    StringBuilder clearEventSenderFieldJavaScript = new StringBuilder();

    clearEventSenderFieldJavaScript.append("document.forms['").append(parentFormClientId).append("'].elements['")
            .append(eventSenderHiddenFieldId).append("'].value='';");

    return clearEventSenderFieldJavaScript.toString();

}