Skip to content

Commit

Permalink
#584 added AJAX for the few events supported by the underlying JS com…
Browse files Browse the repository at this point in the history
…ponent
  • Loading branch information
stephanrauh committed Dec 14, 2016
1 parent 874a0f5 commit 33cf7b2
Show file tree
Hide file tree
Showing 7 changed files with 392 additions and 36 deletions.
20 changes: 15 additions & 5 deletions src/main/java/net/bootsfaces/component/ajax/AJAXRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static void generateBootsFacesAJAXAndJavaScript(FacesContext context, Cli
if (null != jQueryEvents)
if (jQueryEvents.containsKey(keyClientBehavior))
continue;
generatedAJAXCall |= generateAJAXCallForASingleEvent(context, component, rw, specialEvent,
generatedAJAXCall |= generateAJAXCallForASingleEvent(context, component, rw, null, specialEvent,
specialEventHandler, isJQueryCallback, keyClientBehavior, null, null);
}
}
Expand Down Expand Up @@ -292,7 +292,7 @@ private static void generateOnClickHandler(FacesContext context, ResponseWriter
}

public static boolean generateAJAXCallForASingleEvent(FacesContext context, ClientBehaviorHolder component,
ResponseWriter rw, String specialEvent, String specialEventHandler, boolean isJQueryCallback,
ResponseWriter rw, StringBuffer code, String specialEvent, String specialEventHandler, boolean isJQueryCallback,
String keyClientBehavior, StringBuilder generatedJSCode, String optionalParameterList) throws IOException {
boolean generatedAJAXCall = false;
String jsCallback = "";
Expand All @@ -311,8 +311,13 @@ public static boolean generateAJAXCallForASingleEvent(FacesContext context, Clie
jsCallback = jsCallback + ";javascript:" + specialEventHandler;
}
jsCallback = convertAJAXToJavascript(context, jsCallback, component, keyClientBehavior, optionalParameterList);
if (null != code) {
code.append(jsCallback);
}
if ("dragstart".equals(keyClientBehavior)) {
if (null != rw) {
rw.writeAttribute("draggable", "true", "draggable");
}
}
break;
}
Expand Down Expand Up @@ -358,7 +363,12 @@ public static boolean generateAJAXCallForASingleEvent(FacesContext context, Clie
if (component instanceof CommandButton)
if (generatedAJAXCall && "click".equals(keyClientBehavior))
script += ";return false;";
rw.writeAttribute("on" + keyClientBehavior, jsCallback + script, null);
if (null != rw) {
rw.writeAttribute("on" + keyClientBehavior, jsCallback + script, null);
}
if (null != code) {
code.append(jsCallback + script);
}
}
}
if (null != generatedJSCode) {
Expand Down Expand Up @@ -640,7 +650,7 @@ public void generateBootsFacesAJAXAndJavaScriptForJQuery(FacesContext context, U
if (null != ajaxComponent.getJQueryEventParameterListsForAjax().get(event))
parameterList = ajaxComponent.getJQueryEventParameterListsForAjax().get(event);
}
generateAJAXCallForASingleEvent(context, (ClientBehaviorHolder) component, rw, event,
generateAJAXCallForASingleEvent(context, (ClientBehaviorHolder) component, rw, null, event,
additionalEventHandler, true, event, code, parameterList);
if (code.length() > 0) {
rw.startElement("script", component);
Expand All @@ -662,7 +672,7 @@ public String generateBootsFacesAJAXAndJavaScriptForAnMobileEvent(FacesContext c
StringBuilder code = new StringBuilder();
String additionalEventHandler = null;

generateAJAXCallForASingleEvent(context, component, rw, event, additionalEventHandler, true, event, code, null);
generateAJAXCallForASingleEvent(context, component, rw, null, event, additionalEventHandler, true, event, code, null);
return code.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void encodeBegin(FacesContext context, UIComponent component) throws IOEx
StringBuilder jsCode = new StringBuilder();
// Render Ajax Capabilities
AJAXRenderer.generateAJAXCallForASingleEvent(
FacesContext.getCurrentInstance(), gyroscope, rw,
FacesContext.getCurrentInstance(), gyroscope, rw, null,
null, null, false, "rotation", jsCode, null);
String js = jsCode.toString().replace("callAjax(this,", "callAjax(document.getElementById('" + clientId + ".alpha'),");
rw.write("window.addEventListener('deviceorientation', function(event) {\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

package net.bootsfaces.component.selectMultiMenu;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.el.ValueExpression;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
Expand All @@ -35,7 +42,8 @@
@ResourceDependency(library = "bsf", name = "js/dropdown.js", target = "body"), })

@FacesComponent("net.bootsfaces.component.selectMultiMenu.SelectMultiMenu")
public class SelectMultiMenu extends SelectMultiMenuCore implements net.bootsfaces.render.IHasTooltip, IResponsive, IResponsiveLabel {
public class SelectMultiMenu extends SelectMultiMenuCore implements net.bootsfaces.render.IHasTooltip, IResponsive, IResponsiveLabel,
net.bootsfaces.component.ajax.IAJAXComponent{

public static final String COMPONENT_TYPE = "net.bootsfaces.component.selectMultiMenu.SelectMultiMenu";

Expand All @@ -59,4 +67,43 @@ public void setValueExpression(String name, ValueExpression binding) {
public String getFamily() {
return COMPONENT_FAMILY;
}


@Override
public Map<String, String> getJQueryEvents() {
Map<String, String> result = new HashMap<String, String>();
result.put("selectall", "onSelectAll");
result.put("dropdownshow", "onDropdownShow");
result.put("dropdownhidden", "onDropdownHidden");
result.put("selectall", "onSelectAll");
result.put("change", "onChange");
result.put("dropdownhide", "onDropdownHide");
result.put("deselectall", "onDeselectAll");
result.put("dropdownshown", "onDropdownShown");
result.put("unitialized", "onInitialized");
return result;
}

@Override
public Map<String, String> getJQueryEventParameterLists() {
Map<String, String> result = new HashMap<String, String>();
result.put("change", "option, checked, select");
return result;
}

@Override
public Map<String, String> getJQueryEventParameterListsForAjax() {
return null;
}

private static final Collection<String> EVENT_NAMES = Collections.unmodifiableCollection(
new ArrayList<String>());

public Collection<String> getEventNames() {
return EVENT_NAMES;
}

public String getDefaultEventName() {
return "valueChange";
}
}
Loading

0 comments on commit 33cf7b2

Please sign in to comment.