Re: yui context menu after ajax request

2010-01-22 Thread Dave Kallstrom
So it turns out there were a couple of issues preventing the yui context
menu from working correctly after an ajax request.

Even though there was a call to clearContent on the context menu during the
on show event yui seemed to ignore this. This resulted in a doubling up of
some menu items especially sub menu items. I fixed this by calling
clearContent during the menu hide event.

The even worse problem was yui totally ignoring the menu updates if the menu
was not first destroyed. I fixed this by calling destroy on the menu before
calling all the javascript to create the menu. This really seems like
overkill to me but was the only way I could get it to work. I'm not sure why
calling clearContent after a destroy was necessary but this fixes all my
problems.

Also I did not see any reason to make the add method protected in
org.wicketstuff.yui.markup.html.menu2.contextMenu.Menu.
So I opened that up and made it public. This allows the caller to add menu
items and then refresh the panel via ajax and it all seems to work fine.

I have tested these changes in a simple app with one page and one panel. I
have also tested in a much more complicated app that contains a panel with
popup and over a dozen context menus each with two sub menus and so far I
have not found any problems.

I have attached a patch. Please let me know what you think. If you have any
suggestions please let me know.
I am happy to help out where I can...


On Mon, Jan 18, 2010 at 6:16 PM, Dave Kallstrom wrote:

> Interesting... I'll give that a try.. Thanks...
>
>
> On Mon, Jan 18, 2010 at 6:06 PM, Alexander Elsholz <
> alexander.elsh...@widas.de> wrote:
>
>> for my problem with dojo this works:
>>
>> public void refreshMenu(AjaxRequestTarget pTarget) {
>>
>>   String js =  "dojo.addOnLoad(function(){\n + menu.generateJS()
>> + "\n});" ;
>>pTarget.appendJavascript(sss);
>> }
>>
>>
>> and i know the same stuff works for jquery and yui. the problem is that
>> the
>> header javascript brokes after rerendering the component (i think its a
>> problem
>> with object references because most browsers replace the object by
>> creating a
>> new one and the javascript stuff bind on the dom-bject). What seems to
>> work is
>> to put the javascript stuff into the  tag using the
>> onComponentRendered()
>> to "reactivate" the behavior.
>>
>> the ugly is you have to reload the menu in every ajax-event reredering the
>> component with menu.
>>
>> hth
>> alex
>>
>>
>> -
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>>
>>
>
>
> --
> Dave Kallstrom
>



-- 
Dave Kallstrom
Index: src/main/java/org/wicketstuff/yui/markup/html/menu2/contextMenu/YuiContextMenuBehavior.java
===
--- src/main/java/org/wicketstuff/yui/markup/html/menu2/contextMenu/YuiContextMenuBehavior.java	(revision 5131)
+++ src/main/java/org/wicketstuff/yui/markup/html/menu2/contextMenu/YuiContextMenuBehavior.java	(working copy)
@@ -17,6 +17,8 @@
 
 public class YuiContextMenuBehavior extends AbstractDefaultAjaxBehavior {
 
+	private static final long serialVersionUID = -2453827056594475980L;
+	private static final String CONTEXT_MENU = "ContextMenu";
 	private List menus = new ArrayList();
 	private YuiContextMenu defaultMenu;
 
@@ -30,24 +32,24 @@
 		for (int i = 0; i < menus.length; i++) {
 			this.menus.add(menus[i]);
 		}
-		this.defaultMenu = this.menus.get( 0 );;
+		this.defaultMenu = this.menus.get(0);
 	}
-	
-	public void applyAttributes( Component comp, String menuId, IModel targetId ) {
-		YuiContextMenu menu = getMenuById( menuId );
-		assert( menu != null);
-		applyAttributes( comp, menu, targetId );
+
+	public void applyAttributes(Component comp, String menuId, IModel targetId) {
+		YuiContextMenu menu = getMenuById(menuId);
+		assert (menu != null);
+		applyAttributes(comp, menu, targetId);
 	}
-	
-	public void applyAttributes( Component comp, YuiContextMenu menu, IModel targetId ) {
+
+	public void applyAttributes(Component comp, YuiContextMenu menu, IModel targetId) {
 		comp.add(new AttributeModifier("targetId", true, targetId));
-		comp.add(new AttributeModifier("contextMenuId", true, new Model( menu.getMenuId(;
+		comp.add(new AttributeModifier("contextMenuId", true, new Model(menu.getMenuId(;
 	}
 
+	@Override
 	protected void respond(AjaxRequestTarget target) {
 		String action = RequestCycle.get().getRequest().getParameter("action");
-		String targetId = RequestCycle.get().getRequest().getParameter(
-"targetId");
+		String targetId = RequestCycle.get().getRequest().getParameter("targetId");
 		String menuId = RequestCycle.get().getRequest().getParameter("contextMenuId");
 
 		YuiContextMenu menu = getMenuById(menuId);
@@ -79,43 +81,88 @@
 	}
 
 	public CharSequence getCallBackScriptForMenu(String action) {
-		return gene

Re: yui context menu after ajax request

2010-01-18 Thread Dave Kallstrom
Interesting... I'll give that a try.. Thanks...

On Mon, Jan 18, 2010 at 6:06 PM, Alexander Elsholz <
alexander.elsh...@widas.de> wrote:

> for my problem with dojo this works:
>
> public void refreshMenu(AjaxRequestTarget pTarget) {
>
>   String js =  "dojo.addOnLoad(function(){\n + menu.generateJS()
> + "\n});" ;
>pTarget.appendJavascript(sss);
> }
>
>
> and i know the same stuff works for jquery and yui. the problem is that the
> header javascript brokes after rerendering the component (i think its a
> problem
> with object references because most browsers replace the object by creating
> a
> new one and the javascript stuff bind on the dom-bject). What seems to work
> is
> to put the javascript stuff into the  tag using the
> onComponentRendered()
> to "reactivate" the behavior.
>
> the ugly is you have to reload the menu in every ajax-event reredering the
> component with menu.
>
> hth
> alex
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


-- 
Dave Kallstrom


Re: yui context menu after ajax request

2010-01-18 Thread Alexander Elsholz
for my problem with dojo this works: 

public void refreshMenu(AjaxRequestTarget pTarget) {

   String js =  "dojo.addOnLoad(function(){\n + menu.generateJS()
 + "\n});" ;
pTarget.appendJavascript(sss);
}


and i know the same stuff works for jquery and yui. the problem is that the
header javascript brokes after rerendering the component (i think its a problem
with object references because most browsers replace the object by creating a
new one and the javascript stuff bind on the dom-bject). What seems to work is
to put the javascript stuff into the  tag using the onComponentRendered()
to "reactivate" the behavior. 

the ugly is you have to reload the menu in every ajax-event reredering the
component with menu.

hth
alex


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: yui context menu after ajax request

2010-01-18 Thread Dave Kallstrom
That breaks all the menu item links. So far I have tried everything
imaginable to rebuild the menu post ajax request and nothing works. I have
tried rebuilding the entire context menu behavior and also re-rendering the
markup that contains the menu even going so far as to re-render the entire
panel that contains the markup. From what I can tell there is no way to add
to the menu and then re-render it via ajax.

On Mon, Jan 18, 2010 at 3:03 PM, Alexander Elsholz <
alexander.elsh...@widas.de> wrote:

> rerender the menu javascripcode in ajaxevent.
>
> alex
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


-- 
Dave Kallstrom


Re: yui context menu after ajax request

2010-01-18 Thread Alexander Elsholz
rerender the menu javascripcode in ajaxevent.

alex


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



yui context menu after ajax request

2010-01-16 Thread Dave Kallstrom
The wicket-stuff YUI library seems to have a problem with updating the menu
correctly after an ajax request. When the page and panel are first rendered
everything works fine. However when I click on the link for any menu item
the the menu breaks. I checked out the examples but there doesn't seem to be
a way to correctly refresh the menu via ajax.  I really need to be able to
add menu items through and ajax request and then re-render the menu.

Am I missing something? Or is this not possible.

JAVA:
wicket 1.4.5
wicket-stuff 1.4

public class MenuPanel extends Panel {

private static final long serialVersionUID = -617306781692788500L;
private WebMarkupContainer container;

public MenuPanel(String id) {
super(id);
YuiContextMenu contextMenu = buildMenu();
container = new WebMarkupContainer("container");
YuiContextMenuBehavior behavior = new
YuiContextMenuBehavior(contextMenu);
behavior.applyAttributes(container, contextMenu, new
Model("target"));
container.add(behavior);
add(container.setOutputMarkupId(true));
}

private YuiContextMenu buildMenu() {
YuiContextMenu contextMenu = new YuiContextMenu("Menu");
contextMenu.add(new MenuItem("One", new MenuAction("One")));

contextMenu.add(new MenuItem("Two", new MenuAction("Two")));

contextMenu.add(new MenuItem("Three", new
MenuAction("Three")));
contextMenu.add(new MenuItem("Four", new
MenuAction("Four")));
return contextMenu;
}

private class MenuAction implements IYuiMenuAjaxAction, Serializable
{

private String name;

public MenuAction(String name) {
this.name = name;
}

@Override
public void onClick(AjaxRequestTarget target, String
targetId) {
System.out.println(name + " " + targetId);
buildMenu();
target.addComponent(container);

}

@Override
public IModel getName() {
return new Model(name);
}

@Override
public void onClick() {
// TODO Auto-generated method stub

}

}
}
HTML

http://www.w3.org/TR/html4/loose.dtd";>


Menu:



-- 
Dave Kallstrom