You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by eugenebalt <eu...@yahoo.com> on 2013/03/21 15:25:04 UTC
Adding to the existing AjaxBehavior of a component
We have a large panel containing components with multiple Ajax behaviors.
In one context where this panel is used, we need to augment (add) the
existing AjaxBehavior of a certain component by adding extra functionality
to it. It seems that if we add it the usual way (add (new
AjaxComponentUpdating Behavior {..})), it breaks the existing Ajax behavior
defined previously in the panel.
Is there a way to "plug into" an existing Ajax behavior of a component
without replacing it, but adding to it?
Thanks
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Adding-to-the-existing-AjaxBehavior-of-a-component-tp4657400.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Adding to the existing AjaxBehavior of a component
Posted by Entropy <bl...@gmail.com>.
Yeah, that is what I do with my panels I write. In this case though, I'd
/RATHER/ just add the extra behavior because it means I don't have to alter
any of that orgPanel's code.
The panel build is done within a factory method and the inheritance and
design of it doesn't really make exposing that event through an abstract
method hook as easy at it should be. This was a panel written by a
developer who is no longer here and who was learning Wicket for the first
time. It's desperately in need of a general rewrite, but that isn't in the
schedule.
Is it time to cash in that hope? Is supporting two ajax behaviors on the
same event just not going to happen?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Adding-to-the-existing-AjaxBehavior-of-a-component-tp4657400p4657494.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Adding to the existing AjaxBehavior of a component
Posted by Sven Meier <sv...@meiers.net>.
>final DropDownChoice struct = (DropDownChoice) orgPanel.get("StructureL");
This way you're breaking the encapsulation of orgPanel :(.
Why doesn't orgPanel offer the #onOfficeChange() hook in the first place?
Sven
On 03/25/2013 04:18 PM, Entropy wrote:
> I am Eugene's co-worker. The entire code block would be unreasonable as it
> contains alot of business rules that have nothing to do with the technical
> issue. The basic code summary is this:
>
> Inside a re-usable panel orgPanel:
> final DropDownChoice<StructureL> structureDropDown = new
> DropDownChoice<StructureL>("StructureL", StructureLList, structureRenderer);
> structureDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
> protected void onUpdate(AjaxRequestTarget target) {
> //WHOLE lotta code...I'll cut down to the parts that affect the target.
> //Note that alot of this is conditional, and different combinations
> happen on different conditions
> choiceAppl.setChoices(optionsApps);
> target.addComponent(choiceAppl);
> target.appendJavascript("resetWidth();");
> target.appendJavascript("setWidth();");
>
> [...]
>
> target.addComponent(wmc1.setVisible(isVisibleAll));
> target.addComponent(wmc2.setVisible(isVisible));
> target.addComponent(wmc3.setVisible(isVisibleAll));
> target.addComponent(wmc4.setVisible(isVisible));
> target.addComponent(structureDropDown);
> target.appendJavascript("resetWidth();");
> target.appendJavascript("setWidth();");
> }
> }
>
> Inside a different re-usable panel that is seeking to use the panel but need
> to do something extra onchange:
>
> final DropDownChoice struct = (DropDownChoice) orgPanel.get("StructureL");
> struct.add(new AjaxFormComponentUpdatingBehavior("onchange") {
> private static final long serialVersionUID = 1L;
> @Override
> protected void onUpdate(AjaxRequestTarget target) {
> onOfficeChange(target, struct, org1, org2, org3, org4);
> }
> });
>
> [...]
>
> private void onOfficeChange(AjaxRequestTarget target, DropDownChoice struct,
> DropDownChoice org1, DropDownChoice org2, DropDownChoice org3,
> DropDownChoice org4) {
> List<String> users = loadUsersByOfficeInfo(target, struct.getInput(),
> org1.getInput(), org2.getInput(), org3.getInput(), org4.getInput());
> if(users != null) {
> listUsers.setChoices(users);
> target.addComponent(listUsers);
> listUsersFromOffice.setChoices(users);
> target.addComponent(listUsersFromOffice);
> }
> }
>
> Note that the list* controls are both ListMultipleChoice and the structure
> control are others within orgPanel are DropDownChoices.
>
> The behavior is that the panel within the panel in my page works fine if i
> don't add a second AjaxFormComponentUpdatingBehavior to the same event.
> When I add my second event, the second works perfectly. But the original is
> never called (confirmed by both breakpoint and print statement), breaking
> the behavior of that component.
>
>
>
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Adding-to-the-existing-AjaxBehavior-of-a-component-tp4657400p4657489.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Adding to the existing AjaxBehavior of a component
Posted by Entropy <bl...@gmail.com>.
I am Eugene's co-worker. The entire code block would be unreasonable as it
contains alot of business rules that have nothing to do with the technical
issue. The basic code summary is this:
Inside a re-usable panel orgPanel:
final DropDownChoice<StructureL> structureDropDown = new
DropDownChoice<StructureL>("StructureL", StructureLList, structureRenderer);
structureDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
protected void onUpdate(AjaxRequestTarget target) {
//WHOLE lotta code...I'll cut down to the parts that affect the target.
//Note that alot of this is conditional, and different combinations
happen on different conditions
choiceAppl.setChoices(optionsApps);
target.addComponent(choiceAppl);
target.appendJavascript("resetWidth();");
target.appendJavascript("setWidth();");
[...]
target.addComponent(wmc1.setVisible(isVisibleAll));
target.addComponent(wmc2.setVisible(isVisible));
target.addComponent(wmc3.setVisible(isVisibleAll));
target.addComponent(wmc4.setVisible(isVisible));
target.addComponent(structureDropDown);
target.appendJavascript("resetWidth();");
target.appendJavascript("setWidth();");
}
}
Inside a different re-usable panel that is seeking to use the panel but need
to do something extra onchange:
final DropDownChoice struct = (DropDownChoice) orgPanel.get("StructureL");
struct.add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
onOfficeChange(target, struct, org1, org2, org3, org4);
}
});
[...]
private void onOfficeChange(AjaxRequestTarget target, DropDownChoice struct,
DropDownChoice org1, DropDownChoice org2, DropDownChoice org3,
DropDownChoice org4) {
List<String> users = loadUsersByOfficeInfo(target, struct.getInput(),
org1.getInput(), org2.getInput(), org3.getInput(), org4.getInput());
if(users != null) {
listUsers.setChoices(users);
target.addComponent(listUsers);
listUsersFromOffice.setChoices(users);
target.addComponent(listUsersFromOffice);
}
}
Note that the list* controls are both ListMultipleChoice and the structure
control are others within orgPanel are DropDownChoices.
The behavior is that the panel within the panel in my page works fine if i
don't add a second AjaxFormComponentUpdatingBehavior to the same event.
When I add my second event, the second works perfectly. But the original is
never called (confirmed by both breakpoint and print statement), breaking
the behavior of that component.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Adding-to-the-existing-AjaxBehavior-of-a-component-tp4657400p4657489.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Adding to the existing AjaxBehavior of a component
Posted by Andrea Del Bene <an...@gmail.com>.
Can you show some code or (better) can you replicate your problem in a
quickstart application? In your opinion which are the behaviors in conflict?
> For example, the Panel was showing/hiding some components inside itself,
> based on the selection in those components; that was working correctly.
>
> Right now, we're using the Panel on a separate page and have an external
> component that needs to respond to the events in one of the Panel's
> dropdowns. We don't want to change the Panel itself because it's a complex
> reusable piece and we want to leave it alone. After adding an Ajax behavior
> to that dropdown, it seems to run but overrides the previous behavior
> defined for it.
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Adding-to-the-existing-AjaxBehavior-of-a-component-tp4657400p4657412.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Adding to the existing AjaxBehavior of a component
Posted by eugenebalt <eu...@yahoo.com>.
For example, the Panel was showing/hiding some components inside itself,
based on the selection in those components; that was working correctly.
Right now, we're using the Panel on a separate page and have an external
component that needs to respond to the events in one of the Panel's
dropdowns. We don't want to change the Panel itself because it's a complex
reusable piece and we want to leave it alone. After adding an Ajax behavior
to that dropdown, it seems to run but overrides the previous behavior
defined for it.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Adding-to-the-existing-AjaxBehavior-of-a-component-tp4657400p4657412.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Adding to the existing AjaxBehavior of a component
Posted by Andrea Del Bene <an...@gmail.com>.
Hi,
how does the additional behavior break the existing one?
> We have a large panel containing components with multiple Ajax behaviors.
>
> In one context where this panel is used, we need to augment (add) the
> existing AjaxBehavior of a certain component by adding extra functionality
> to it. It seems that if we add it the usual way (add (new
> AjaxComponentUpdating Behavior {..})), it breaks the existing Ajax behavior
> defined previously in the panel.
>
> Is there a way to "plug into" an existing Ajax behavior of a component
> without replacing it, but adding to it?
>
> Thanks
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Adding-to-the-existing-AjaxBehavior-of-a-component-tp4657400.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org