Skip to content

Commit

Permalink
#371 now @process behaves exactly like its PrimeFaces counterpart
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanrauh committed May 21, 2016
1 parent 190c23c commit 1c623d9
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions src/main/java/net/bootsfaces/component/ajax/AJAXRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

public class AJAXRenderer extends CoreRenderer {
private static final Logger LOGGER = Logger.getLogger("net.bootsfaces.component.ajax.AJAXRenderer");

// local constants
public static final String BSF_EVENT_PREFIX = "BsFEvent=";
public static final String AJAX_EVENT_PREFIX = "ajax:";
Expand Down Expand Up @@ -115,7 +115,8 @@ public void decode(FacesContext context, UIComponent component, String component
List<ClientBehavior> value = entry.getValue();
for (ClientBehavior bh : value) {
if (bh instanceof AjaxBehavior) {
// String delay = ((AjaxBehavior) bh).getDelay();
// String delay = ((AjaxBehavior)
// bh).getDelay();
bh.decode(context, component);
}
}
Expand Down Expand Up @@ -152,14 +153,14 @@ public void decode(FacesContext context, UIComponent component, String component
* @param rw
* @throws IOException
*/
public static void generateBootsFacesAJAXAndJavaScript(FacesContext context, ClientBehaviorHolder component, ResponseWriter rw)
throws IOException {
public static void generateBootsFacesAJAXAndJavaScript(FacesContext context, ClientBehaviorHolder component,
ResponseWriter rw) throws IOException {
generateBootsFacesAJAXAndJavaScript(context, component, rw, null, null, false);
}

public static void generateBootsFacesAJAXAndJavaScript(FacesContext context, ClientBehaviorHolder component,
ResponseWriter rw, String specialEvent, String specialEventHandler, boolean isJQueryCallback)
throws IOException {
throws IOException {
boolean generatedAJAXCall = false;
Collection<String> eventNames = component.getEventNames();
for (String keyClientBehavior : eventNames) {
Expand Down Expand Up @@ -211,7 +212,7 @@ public static void generateBootsFacesAJAXAndJavaScript(FacesContext context, Cli
}

private static void generateOnClickHandler(FacesContext context, ResponseWriter rw, IAJAXComponent component)
throws IOException {
throws IOException {
StringBuilder cJS = new StringBuilder(150); // optimize int
cJS.append(encodeClick(component)).append("return BsF.ajax.cb(this, event);");

Expand All @@ -220,8 +221,7 @@ private static void generateOnClickHandler(FacesContext context, ResponseWriter

private static boolean generateAJAXCallForASingleEvent(FacesContext context, ClientBehaviorHolder component,
ResponseWriter rw, String specialEvent, String specialEventHandler, boolean isJQueryCallback,
String keyClientBehavior, StringBuilder generatedJSCode)
throws IOException {
String keyClientBehavior, StringBuilder generatedJSCode) throws IOException {
boolean generatedAJAXCall = false;
String jsCallback = "";
String nameOfGetter = "getOn" + keyClientBehavior;
Expand Down Expand Up @@ -358,7 +358,7 @@ private static String convertAJAXToJavascript(FacesContext context, String jsCal
public static StringBuilder generateAJAXCall(FacesContext context, IAJAXComponent component, String event) {
String complete = component.getOncomplete();
String onError = null;
String onSuccess=null;
String onSuccess = null;
if (component instanceof IAJAXComponent2) {
onError = ((IAJAXComponent2) component).getOnerror();
onSuccess = ((IAJAXComponent2) component).getOnsuccess();
Expand All @@ -371,16 +371,15 @@ public static StringBuilder generateAJAXCall(FacesContext context, IAJAXComponen
update = ExpressionResolver.getComponentIDs(context, (UIComponent) component, update);
String process = component.getProcess();
if (null == process) {
if (component.getClass().getName().contains("Command")) {
// CommandButton and CommandLink default to @form - see
// http://stackoverflow.com/questions/25339056/understanding-process-and-update-attributes-of-primefaces
process = "@form";
} else {
process = "@this";
}
// see https://github.com/TheCoder4eu/BootsFaces-OSP/issues/371
process = "@all";
}

process = ExpressionResolver.getComponentIDs(context, (UIComponent) component, process);
if ("@all".equals(process) || "@none".equals(process)) {
// these expressions are evaluated on the client side
} else {
process = ExpressionResolver.getComponentIDs(context, (UIComponent) component, process);
}
cJS.append("BsF.ajax.callAjax(this, event").append(",'" + update + "'").append(",'").append(process)
.append("'");
if (complete != null) {
Expand Down Expand Up @@ -411,7 +410,7 @@ private static StringBuilder generateAJAXCallForClientBehavior(FacesContext cont
String process = component.getProcess();
String onevent = "";
String onError = null;
String onSuccess=null;
String onSuccess = null;
if (component instanceof IAJAXComponent2) {
onError = ((IAJAXComponent2) component).getOnerror();
onSuccess = ((IAJAXComponent2) component).getOnsuccess();
Expand All @@ -421,7 +420,8 @@ private static StringBuilder generateAJAXCallForClientBehavior(FacesContext cont
if (ajaxBehavior instanceof AjaxBehavior) {
boolean disabled = ((AjaxBehavior) ajaxBehavior).isDisabled();
if (!disabled) {
// String onerror = ((AjaxBehavior) ajaxBehavior).getOnerror(); // todo
// String onerror = ((AjaxBehavior)
// ajaxBehavior).getOnerror(); // todo
onevent = ((AjaxBehavior) ajaxBehavior).getOnevent();
if (onevent == null)
onevent = "";
Expand All @@ -433,6 +433,8 @@ private static StringBuilder generateAJAXCallForClientBehavior(FacesContext cont
else
process += " " + u;
}
} else {
process = "@this";
}

Collection<String> render = ((AjaxBehavior) ajaxBehavior).getRender();
Expand All @@ -447,7 +449,11 @@ private static StringBuilder generateAJAXCallForClientBehavior(FacesContext cont
}
}

process = ExpressionResolver.getComponentIDs(context, (UIComponent) component, process);
if ("@all".equals(process) || "@none".equals(process) ) {
// these expressions are evaluated on the client side
} else {
process = ExpressionResolver.getComponentIDs(context, (UIComponent) component, process);
}
update = ExpressionResolver.getComponentIDs(context, (UIComponent) component, update);
cJS.append(encodeClick(component)).append("BsF.ajax.callAjax(this, event")
.append(update == null ? ",''" : (",'" + update + "'"))
Expand Down Expand Up @@ -496,8 +502,7 @@ private static String encodeClick(IAJAXComponent component) {
* @throws IOException
*/
public void generateBootsFacesAJAXAndJavaScriptForJQuery(FacesContext context, UIComponent component,
ResponseWriter rw, String clientId, Map<String, String> additionalEventHandlers)
throws IOException {
ResponseWriter rw, String clientId, Map<String, String> additionalEventHandlers) throws IOException {
IAJAXComponent ajaxComponent = (IAJAXComponent) component;
Set<String> events = ajaxComponent.getJQueryEvents().keySet();
for (String event : events) {
Expand All @@ -518,14 +523,12 @@ public void generateBootsFacesAJAXAndJavaScriptForJQuery(FacesContext context, U
}
}

public String generateBootsFacesAJAXAndJavaScriptForAnMobileEvent(FacesContext context, ClientBehaviorHolder component,
ResponseWriter rw, String clientId, String event)
throws IOException {
public String generateBootsFacesAJAXAndJavaScriptForAnMobileEvent(FacesContext context,
ClientBehaviorHolder component, ResponseWriter rw, String clientId, String event) throws IOException {
StringBuilder code = new StringBuilder();
String additionalEventHandler = null;

generateAJAXCallForASingleEvent(context, component, rw, event, additionalEventHandler,
true, event, code);
generateAJAXCallForASingleEvent(context, component, rw, event, additionalEventHandler, true, event, code);
return code.toString();
}
}

0 comments on commit 1c623d9

Please sign in to comment.