Re: Wicket context menu component
Hi Sebastien, Thats great news, I prefer to use library version as it has a lot of advantages over rolling my own solution. I tried yours and it works fine for me. I think example of how to recognize which link was clicked in demo would be helpful for others, as context menu will certainly need this for real world scenario. Here how I did it (let me know if thats how its intended to use): final ContextMenu menu = new ContextMenu(menu, Arrays.asList(menuItem1, menuItem2, menuItem3, menuItem4)) { private static final long serialVersionUID = 1L; private AjaxFallbackLinkUser selectedLink = null; @SuppressWarnings(unchecked) @Override protected void onContextMenu(AjaxRequestTarget target, Component component) { selectedLink = ((AjaxFallbackLinkUser)component); } @Override public void onClick(AjaxRequestTarget target, IMenuItem item) { switch (item.getTitle().getObject()) { case Context menu 1: if (selectedLink != null) { selectedLink.onClick(target); } break; case Context menu 2: System.out.println(Clicked + item.getTitle().getObject() + on + selectedLink.getModelObject().getNickname()); break; case Context menu 3: System.out.println(Clicked + item.getTitle().getObject() + on + selectedLink.getModelObject().getNickname()); break; case Context menu 4: System.out.println(Clicked + item.getTitle().getObject() + on + selectedLink.getModelObject().getNickname()); break; } } }; Big thanks and best regards! :) bronius -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-context-menu-component-tp4659306p4659541.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket context menu component
Yes I agree, thanks again :) -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-context-menu-component-tp4659306p4659544.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket context menu component
Ok thanks again for helping out! :) Well I found that 'options.$trigger.attr(id)' from parameters returns id of link pressed (did not try yet on wicket side, but I think it should work) and 'key' returns which context menu was pressed. Now my links represents users and context menu some actions to do on users (say view profile). So now I kinda can set user id as link id and then retrieve link id from 'options.$trigger.attr(id)' and load user and do action from context menu on it. But for some reason it does not feel right :) Is it ok to implement it like that? What do you think? I don't have much wicket experience, but wicketish way for me seems that context menu behavior could be added to link component and then from that behavior I could invoke link's onClick lets say. How would you would go forward from here for that kind of use case? -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-context-menu-component-tp4659306p4659436.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket context menu component
Hi thanks for help! With your explanations and MenuBehavior example I made it work. Now one last thing is to recognize which link was chosen for context menu. I see this documentation about callback: (function) callback Specifies the default callback to be used in case an item does not expose its own callback. The default callback behaves just like item.callback. Example: {callback: callback: function(key, opt){ alert(Clicked on + key + on element + opt.$trigger.attr(id)); }} Is opt.$trigger.attr(id) what I want? How does this work out? I debugged my select event for RequestCycleUtils.getQueryParameterValue(options) but it returns nothing. Here is my current working version of context menu: public class ContextMenuBehavior extends JQueryBehavior implements IJQueryAjaxAware { private static final long serialVersionUID = 1L; private String selector; private ListMenuItem menuItems; private MapString, MenuItem menuItemsMap = new HashMapString, MenuItem(); private JQueryAjaxBehavior onSelectBehavior; public ContextMenuBehavior(String selector, ListMenuItem menuItems) { super(contextMenu); this.selector = selector; this.menuItems = menuItems; for (MenuItem menuItem : menuItems) { menuItemsMap.put(menuItem.getId(), menuItem); } add(new JavaScriptResourceReference(ContextMenuBehavior.class, jquery.ui.position.js)); add(new JavaScriptResourceReference(ContextMenuBehavior.class, jquery.contextMenu.js)); add(new CssResourceReference(ContextMenuBehavior.class, jquery.contextMenu.css)); } // Methods // @Override public void bind(Component component) { super.bind(component); component.add(this.onSelectBehavior = this.newOnSelectBehavior()); } // Events // @Override public void onConfigure(Component component) { super.onConfigure(component); this.setOption(select, this.onSelectBehavior.getCallbackFunction()); } @Override protected String $() { // build menu items for jquery StringBuilder items = new StringBuilder(items: {); int nbOfMenuItems = menuItems.size(); for (int i = 0; i nbOfMenuItems; i++) { MenuItem menuItem = menuItems.get(i); items.append(').append(menuItem.getId()).append(': {name: ').append(menuItem.getTitle().getObject()) .append(', icon: ').append(menuItem.getIcon()).append('}); if (i nbOfMenuItems - 1) { items.append(,); } } items.append(}); return String.format($(function(){$.contextMenu({selector: '%s', callback: %s, %s});});, selector, onSelectBehavior.getCallbackFunction(), items.toString()); } @Override public void onAjax(AjaxRequestTarget target, JQueryEvent event) { if (event instanceof SelectEvent) { IMenuItem item = this.menuItemsMap.get(((SelectEvent) event).getKey()); if (item != null) { item.onClick(target); } } } protected JQueryAjaxBehavior newOnSelectBehavior() { return new JQueryAjaxBehavior(this) { private static final long serialVersionUID = 1L; @Override protected CallbackParameter[] getCallbackParameters() { return new CallbackParameter[] { CallbackParameter.explicit(key), CallbackParameter.context(options) }; } @Override protected JQueryEvent newEvent() { return new SelectEvent(); } }; } protected static class SelectEvent extends JQueryEvent { private final String key; public SelectEvent() { super(); this.key = RequestCycleUtils.getQueryParameterValue(key).toString(); } public String getKey() { return this.key; } } } -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-context-menu-component-tp4659306p4659381.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket context menu component
Hi, Yes I checked it. I also was reading this: http://code.google.com/p/wicket-jquery-ui/wiki/HowToCreatePlugin2. However context menu plug in was not standard here is jquery example: $(function(){ $.contextMenu({ selector: '.context-menu-one', callback: function(key, options) { var m = clicked: + key; window.console console.log(m) || alert(m); }, items: { edit: {name: Edit, icon: edit}, cut: {name: Cut, icon: cut}, copy: {name: Copy, icon: copy}, paste: {name: Paste, icon: paste}, delete: {name: Delete, icon: delete}, sep1: -, quit: {name: Quit, icon: quit} } }); $('.context-menu-one').on('click', function(e){ console.log('clicked', this); }) }); Now the problem is I don't have knowledge about jquery, but from what I understand it creates context menu instance with parameters: selector, callback and items. Differently from menu it does not have any markup (items are passed as parameters and thats it) and also jquery syntax is different. Menu jquery example is just like this: $(function() { $( #menu ).menu(); }); Thats why I extended JQueryAbstractBehavior, as jquery initialization is quite different. What I implemented shows context menu, and callback function is invoked(from jquery parameter), but I lack knowledge on how to convert that callback function to wicket one. Menu example is ok, but its different and also it seems I understand what separate methods do, but because of my inexperience I lack bigger picture understanding how everything works together. Any help is really appreciated :) -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-context-menu-component-tp4659306p4659334.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Wicket context menu component
Hello, I needed context menu component, but surprisingly it does not exit for current version, so decided to roll my own, even though i have very little Wicket experience and know absolutely nothing about jquery, so im like that dog :) http://apache-wicket.1842946.n4.nabble.com/file/n4659306/7TjIrsT.jpg Anyway I managed to get something working like this (maybe it will be helpful for someone or maybe someone smarter will show me my mistakes): 1. Added https://github.com/sebfz1/wicket-jquery-ui dependency. 2. Chosen to use this jquery plugin: http://medialize.github.io/jQuery-contextMenu/index.html 3. After spending some time I managed to create Behavior like this: public class ContextMenuBehavior extends JQueryAbstractBehavior { private static final long serialVersionUID = 1L; private String selector; private ListMenuItem menuItems; public ContextMenuBehavior(String selector, ListMenuItem menuItems) { super(contextMenu); this.selector = selector; this.menuItems = menuItems; add(new JavaScriptResourceReference(ContextMenuBehavior.class, jquery.ui.position.js)); add(new JavaScriptResourceReference(ContextMenuBehavior.class, jquery.contextMenu.js)); add(new CssResourceReference(ContextMenuBehavior.class, jquery.contextMenu.css)); } @Override protected String $() { // build menu items for jquery StringBuilder items = new StringBuilder(items: {); int nbOfMenuItems = menuItems.size(); for (int i = 0; i nbOfMenuItems; i++) { MenuItem menuItem = menuItems.get(i); items.append(').append(menuItem.getId()).append(': {name: ').append(menuItem.getTitle().getObject()).append(', icon: ').append(menuItem.getIcon()).append('}); if (i nbOfMenuItems - 1) { items.append(,); } } items.append(}); return String.format($(function(){$.contextMenu({selector: '%s', callback: function(key, options) {var m = 'clicked: ' + key; window.console console.log(m) || alert(m); }, %s});});, selector, items.toString()); } } 4. $() method just prints jquery context menu initialization stuff from here: http://medialize.github.io/jQuery-contextMenu/demo.html 5. Now when add this behavior to Page and add div class=userContextMenu to html right click on it gives me context menu so its working. Clicking on menu also shows me simple alert message as it is in callback parameter. 6. So far so good, but now Im interested in how to link this to wicket component listener. I will put this menu on multiple links, so i would like to receive both on which link user clicked for context menu and which menu item he have chosen. How would you implement this? Also am I even on the right track? Is it good approach? Im sorry if this is stupid question :) -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-context-menu-component-tp4659306.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: UrlResourceReference for images
Relative is not good because resources are served from different application, just currently both applications are deployed on same tomcat so they have urls http://localhost:8080/app1 and http://localhost:8080/app2. When smart wicket renders image src i get something like this: app2/image?item=123amp;id=1 so it thinks this is url of my main application (app1), but its not. When i modify with firebug to use full http://localhost:8080/app2 it works fine. So only solution is to override UrlRenderer? That would mean I would have to override also RequestCycle? Just for such simple case? Maybe there is simpler solution? -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/UrlResourceReference-for-images-tp4659261p4659271.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: UrlResourceReference for images
Yes that would be great, but src=app2/image?item-123 does not work (image is not loaded) and after changing it with firebug to src=http://localhost:8080/app2/image?item-123; works fine. Any ideas why is that? Any stupid mistake i overlooked? Maybe wicket interprets relative url as http://localhost:8080/app1/app2/image?item-123 somehow? Maybe because when i build url I put app2 as segment? (url.getSegments().add(app2);) I will try different way to construct url later. Thanks for help appreciate it :) -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/UrlResourceReference-for-images-tp4659261p4659279.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: UrlResourceReference for images
Hi, I just tried it and it worked! Thanks guys for help, this situation really surprised me :) On the bright side at least I learned about framework when solving this little problem of mine as its easy to go inside and check how it works (im quite new to wicket). Best regards! -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/UrlResourceReference-for-images-tp4659261p4659283.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
UrlResourceReference for images
Hello, Im trying to serve images from other server, but need to build url for images on server side. This looks very simple and on most frameworks very easy to accomplish, but on wicket I simply do not understand what to do... Im trying like this: final Image img = new Image(IMAGE_ID_ADIMG, new UrlResourceReference(createUrl(null))); First of all Url api is extremely hard to work with, very hard to create url i need, I think there should be some option to simply create it with simple string. Anyway Url.parse method does not create full url for me (i have localhost:8080/site1 and localhost:8080/site2, but when url is created i get only site2 without full address). So I tried it myself like this: private Url createUrl(Charset charset) { Url url = new Url(charset) { private static final long serialVersionUID = 1L; @Override public String toString(final Charset charset) { return toString(StringMode.FULL, charset); } }; url.setProtocol(http); url.setHost(localhost); url.setPort(8080); url.getSegments().add(site2); url.getSegments().add(image); url.setQueryParameter(param1, 1); url.setQueryParameter(param2, 2); return url; } Not really nice, but at least Url object returned normal full url that i needed in toString. However UrlResourceReference still rendered not full url and thats where i got too pissed off and decided I need some rest :) I'm just interested if I'm even on the right track? How you would implement it? And why this simple thing is so complicated? :) I admit I was a bit drunk :) and don't have that much of experience with wicket, but this part looked really strange for me. But I suspect I'm missing something. The problem is probably because both applications have same start (http://localhost:8080) and wicket is too smart. As image from other random website is shown successfully. Looking forward hearing from you :) -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/UrlResourceReference-for-images-tp4659261.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org