Skip to content

Commit ce6f982

Browse files
committed
fixed #259 (b:commandButton actions were called twice, and if you
provide both action and actionListener, even b:navCommandLink actions were called twice)
1 parent c80707f commit ce6f982

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

src/main/java/net/bootsfaces/component/ajax/AJAXRenderer.java

+35-30
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,23 @@ public void decode(FacesContext context, UIComponent component, String component
117117
}
118118
}
119119

120+
boolean addEventToQueue=false;
120121
if (component instanceof ActionSource) {
121122
ActionSource b = (ActionSource) component;
122123
ActionListener[] actionListeners = b.getActionListeners();
123124
if (null != actionListeners && actionListeners.length > 0) {
124-
component.queueEvent(new ActionEvent(component));
125+
addEventToQueue=true;
125126
}
126127
}
127128
if (component instanceof ActionSource2) {
128129
MethodExpression actionExpression = ((ActionSource2) component).getActionExpression();
129130
if (null != actionExpression) {
130-
component.queueEvent(new ActionEvent(component));
131+
addEventToQueue=true;
131132
}
132133
}
134+
if (addEventToQueue) {
135+
component.queueEvent(new ActionEvent(component));
136+
}
133137
}
134138
}
135139

@@ -176,38 +180,39 @@ public static void generateBootsFacesAJAXAndJavaScript(FacesContext context, Cli
176180
script += ";return false;";
177181
rw.writeAttribute("on" + defaultEvent, script, null);
178182
}
179-
// else {
180-
// boolean generateNonAJAXCommand = false;
181-
// if (component instanceof ActionSource) {
182-
// ActionSource b = (ActionSource) component;
183-
// ActionListener[] actionListeners = b.getActionListeners();
184-
// if (null != actionListeners && actionListeners.length > 0) {
185-
// generateNonAJAXCommand = true;
186-
// }
187-
// }
188-
// if (component instanceof ActionSource2) {
189-
// MethodExpression actionExpression = ((ActionSource2) component).getActionExpression();
190-
// if (null != actionExpression) {
191-
// generateNonAJAXCommand = true;
192-
// }
193-
// }
194-
// if (generateNonAJAXCommand && component instanceof IAJAXComponent) {
195-
// // rw.writeAttribute("id", getClientId() + "_a", null);
196-
// generateOnClickHandler(context, rw, (IAJAXComponent) component);
197-
// }
198-
// }
183+
else if (!(component instanceof CommandButton)) {
184+
// b:navCommandLink doesn't submit the form, so we need to use AJAX
185+
boolean generateNonAJAXCommand = false;
186+
if (component instanceof ActionSource) {
187+
ActionSource b = (ActionSource) component;
188+
ActionListener[] actionListeners = b.getActionListeners();
189+
if (null != actionListeners && actionListeners.length > 0) {
190+
generateNonAJAXCommand = true;
191+
}
192+
}
193+
if (component instanceof ActionSource2) {
194+
MethodExpression actionExpression = ((ActionSource2) component).getActionExpression();
195+
if (null != actionExpression) {
196+
generateNonAJAXCommand = true;
197+
}
198+
}
199+
if (generateNonAJAXCommand && component instanceof IAJAXComponent) {
200+
// rw.writeAttribute("id", getClientId() + "_a", null);
201+
generateOnClickHandler(context, rw, (IAJAXComponent) component);
202+
}
203+
}
199204

200205
}
201206
}
202207

203-
// private static void generateOnClickHandler(FacesContext context, ResponseWriter rw, IAJAXComponent component)
204-
// throws IOException {
205-
// StringBuilder cJS = new StringBuilder(150); // optimize int
206-
//
207-
// cJS.append(encodeClick(component)).append("return BsF.ajax.cb(this, event);");
208-
//
209-
// rw.writeAttribute("onclick", cJS.toString(), null);
210-
// }
208+
private static void generateOnClickHandler(FacesContext context, ResponseWriter rw, IAJAXComponent component)
209+
throws IOException {
210+
StringBuilder cJS = new StringBuilder(150); // optimize int
211+
212+
cJS.append(encodeClick(component)).append("return BsF.ajax.cb(this, event);");
213+
214+
rw.writeAttribute("onclick", cJS.toString(), null);
215+
}
211216

212217
private static boolean generateAJAXCallForASingleEvent(FacesContext context, ClientBehaviorHolder component,
213218
ResponseWriter rw, String specialEvent, String specialEventHandler, boolean isJQueryCallback,

0 commit comments

Comments
 (0)