Re: Wasp/Swarm Questions was Re: Component parent null after replace
protected final void setReplacementClass(Class replacementClass) { if (replacementClass == null || !MarkupContainer.class.isAssignableFrom(replacementClass)) throw new WicketRuntimeException("This link requires a " + MarkupContainer.class + ", not a " + replacementClass); this.replacementClass = replacementClass; setSecurityCheck(generateSecurityCheck()); } } On 9/11/07, Martijn Dashorst <[EMAIL PROTECTED]> wrote: Create your custom request cycle, and add a getter that uses the session's username/id to retrieve the user from the database, and cache it locally. Martijn On 9/11/07, Anthony Schexnaildre <[EMAIL PROTECTED]> wrote: This makes sense. Where would you stick the user on the requestcycle? It's not obvious from the javadocs. Is there a "wicket way"? -Anthony On Sep 11, 2007, at 10:05 AM, Maurice Marrink wrote: Martijn, you are absolutely right, i forgot we moved the user from the session to the requestcycle. Just keep the id for your user in the session and keep the actual user for this request in the requestcycle. This way each thread will have its own instance of the user. Maurice On 9/11/07, Martijn Dashorst <[EMAIL PROTECTED]> wrote: Just a quick note: storing objects that are not thread safe in your session is asking for trouble. While Wicket does limit page processing to one request at a time, other requests like resources can run in parallel. What does this mean? One thing that comes to mind is that when two requests for the same session are being processed, and one is done before the other it will detach the user model. What are the semantics now for the other thread? For instance if you have a detachable model storing a User object in your session and use Hibernate you are in a world of hurt, or rather Hibernate will sometimes bork because your Session tries to attach the single User instance to multiple Hibernate Session objects. Exceptions will be having a party. Now this is not meant as a Hibernate bashing reply, it just happens that Hibernate correctly detects multiple threads modifying the same object's state and stops tampering with it. Martijn -- Buy Wicket in Action: http://manning.com/dashorst Apache Wicket 1.3.0-beta3 is released Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0- beta3/ -- --- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Buy Wicket in Action: http://manning.com/dashorst Apache Wicket 1.3.0-beta3 is released Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta3/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Wasp/Swarm Questions was Re: Component parent null after replace
IL PROTECTED] MarkupContainer} */ protected final void setReplacementClass(Class replacementClass) { if (replacementClass == null || !MarkupContainer.class.isAssignableFrom(replacementClass)) throw new WicketRuntimeException("This link requires a " + MarkupContainer.class + ", not a " + replacementClass); this.replacementClass = replacementClass; setSecurityCheck(generateSecurityCheck()); } } On 9/11/07, Martijn Dashorst <[EMAIL PROTECTED]> wrote: Create your custom request cycle, and add a getter that uses the session's username/id to retrieve the user from the database, and cache it locally. Martijn On 9/11/07, Anthony Schexnaildre <[EMAIL PROTECTED]> wrote: This makes sense. Where would you stick the user on the requestcycle? It's not obvious from the javadocs. Is there a "wicket way"? -Anthony On Sep 11, 2007, at 10:05 AM, Maurice Marrink wrote: Martijn, you are absolutely right, i forgot we moved the user from the session to the requestcycle. Just keep the id for your user in the session and keep the actual user for this request in the requestcycle. This way each thread will have its own instance of the user. Maurice On 9/11/07, Martijn Dashorst <[EMAIL PROTECTED]> wrote: Just a quick note: storing objects that are not thread safe in your session is asking for trouble. While Wicket does limit page processing to one request at a time, other requests like resources can run in parallel. What does this mean? One thing that comes to mind is that when two requests for the same session are being processed, and one is done before the other it will detach the user model. What are the semantics now for the other thread? For instance if you have a detachable model storing a User object in your session and use Hibernate you are in a world of hurt, or rather Hibernate will sometimes bork because your Session tries to attach the single User instance to multiple Hibernate Session objects. Exceptions will be having a party. Now this is not meant as a Hibernate bashing reply, it just happens that Hibernate correctly detects multiple threads modifying the same object's state and stops tampering with it. Martijn -- Buy Wicket in Action: http://manning.com/dashorst Apache Wicket 1.3.0-beta3 is released Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0- beta3/ -- --- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Buy Wicket in Action: http://manning.com/dashorst Apache Wicket 1.3.0-beta3 is released Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta3/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Wasp/Swarm Questions was Re: Component parent null after replace
This makes sense. Where would you stick the user on the requestcycle? It's not obvious from the javadocs. Is there a "wicket way"? -Anthony On Sep 11, 2007, at 10:05 AM, Maurice Marrink wrote: Martijn, you are absolutely right, i forgot we moved the user from the session to the requestcycle. Just keep the id for your user in the session and keep the actual user for this request in the requestcycle. This way each thread will have its own instance of the user. Maurice On 9/11/07, Martijn Dashorst <[EMAIL PROTECTED]> wrote: Just a quick note: storing objects that are not thread safe in your session is asking for trouble. While Wicket does limit page processing to one request at a time, other requests like resources can run in parallel. What does this mean? One thing that comes to mind is that when two requests for the same session are being processed, and one is done before the other it will detach the user model. What are the semantics now for the other thread? For instance if you have a detachable model storing a User object in your session and use Hibernate you are in a world of hurt, or rather Hibernate will sometimes bork because your Session tries to attach the single User instance to multiple Hibernate Session objects. Exceptions will be having a party. Now this is not meant as a Hibernate bashing reply, it just happens that Hibernate correctly detects multiple threads modifying the same object's state and stops tampering with it. Martijn -- Buy Wicket in Action: http://manning.com/dashorst Apache Wicket 1.3.0-beta3 is released Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta3/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Wasp/Swarm Questions was Re: Component parent null after replace
Please hijack away. I have been quite happy with Wasp and Swarm. It's simple and painless but quite flexible. The examples are the life saver though. To be honest, the security framework is why I chose to use Wicket for this project instead of Tapestry. I am however having a few issues figuring out some "best practices" that maybe you or some other experienced Wasp/Swarm users may be able to shed some light on. 1. Where would you store a reference to the logged in user. Currently have it in a DetachableModel in a custom session. There has to be a better place to put the user reference that fits more directly with the security framework. 2. I very much like your SecureTab example but something like a SecurePanelLink within the framework would be helpful. I have been working on my own that mirrors the SecurePageLink as much as possible but it is still a bit wonky. This is helpful because once you get into a tab layout, navigation to other panels that are not directly attached to a tab becomes annoying at best. I am working through it but seems like someone must have solved this issues a few times over in an elegant fashion. Maybe some kind of "panel stack" with tab integration? 3. I don't understand the DataPermissions, configuration and their use cases. I must admit I have not spent the time to dig through the example extensively but I don't understand the use cases enough to know why I would want to spend the time. 4. I am working on an application that will eventually have very complicated permission structure. Right now I am fumbling a solution together for phase one. Eventually I would like to be able to "filter" the date returned to a user based on some permissions while not coupling the security layer to the Dao's to tightly. A typical structure would be as follows: O - Organisation U - User O / / \ \ / | | \ U U U O / | \ U O O / || \ U U U U Consider a use case where you have a hierarchy of Financial Transaction Processors with the following 2 user types/principals: Customer Service - Allowed to see transactions and act on them if the transactions are for their direct organisation Billing - Allowed to see transaction and act on them for their direct organisation and any sub-organisations The final goal would be to have an interface much like that in the wicket-phonebook example where the DataProvider ( or something else ) would feed the appropriate results out of the hibernate dao's into the DataTable based on the users permissions. Any clues to some elegant approach? -Anthony On Sep 9, 2007, at 6:12 PM, Maurice Marrink wrote: Allow me to hijack this topic because my eye sees the magic word ISecureComponent :D Glad to come across another user of Wasp and Swarm. Any comments / questions about them? Maurice On 9/9/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote: heh, seems a lot of people run into it. the short is that you have to do this: lets say you have a ref to the panel: private Panel panel; what you do is this: panel.replaceWith(new Panel()); and then later again panel.replaceWith(new Panel()); ^ the second time will fail beause you have removed panel from hierarchy already - you replaced it with another panel. the proper way to do it is to keep the reference up to date, so Panel temp=new Panel(); panel.replaceWith(temp); panel=temp; that way when it happens the second time it will properly act on the new panel that is inside the hierarchy now. -igor On 9/9/07, Anthony Schexnaildre <[EMAIL PROTECTED]> wrote: I am trying to create a link that will replace one panel with another on the page. This seems as though it should be an easy task but after many attempts and searching the net for examples I have yet to get it working so the replacement can happen more than one without the component becoming orphaned. On the second replace attempt i get the following exception. Anyone have the solution? Thank you, Anthony java.lang.IllegalStateException: This method can only be called on a component that has already been added to its parent. at org.apache.wicket.Component.replaceWith(Component.java: 2266) at com.pinwise.pinbase.web.components.links.SecurePanelLink $4.onClick(SecurePanelLink.java:142) at org.apache.wicket.markup.html.link.Link.onLinkClicked (Link.java:222) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.wicket.RequestListenerInterface.invoke (RequestListenerInterface.java:186) = = public UserPanel(String id) { super(id); UserFormPanel userFormPanel = new UserFormPanel("userFormPanel"); add( userFormPanel ); List colum
Re: Component parent null after replace
Igor, Thank you for your reply. I did see another message from you recently on this same topic but the key the problem was having the "private Panel panel;" field to store the reference. -Anthony On Sep 9, 2007, at 5:09 PM, Igor Vaynberg wrote: heh, seems a lot of people run into it. the short is that you have to do this: lets say you have a ref to the panel: private Panel panel; what you do is this: panel.replaceWith(new Panel()); and then later again panel.replaceWith(new Panel()); ^ the second time will fail beause you have removed panel from hierarchy already - you replaced it with another panel. the proper way to do it is to keep the reference up to date, so Panel temp=new Panel(); panel.replaceWith(temp); panel=temp; that way when it happens the second time it will properly act on the new panel that is inside the hierarchy now. -igor On 9/9/07, Anthony Schexnaildre <[EMAIL PROTECTED]> wrote: I am trying to create a link that will replace one panel with another on the page. This seems as though it should be an easy task but after many attempts and searching the net for examples I have yet to get it working so the replacement can happen more than one without the component becoming orphaned. On the second replace attempt i get the following exception. Anyone have the solution? Thank you, Anthony java.lang.IllegalStateException: This method can only be called on a component that has already been added to its parent. at org.apache.wicket.Component.replaceWith(Component.java:2266) at com.pinwise.pinbase.web.components.links.SecurePanelLink $4.onClick(SecurePanelLink.java:142) at org.apache.wicket.markup.html.link.Link.onLinkClicked (Link.java:222) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.wicket.RequestListenerInterface.invoke (RequestListenerInterface.java:186) = = public UserPanel(String id) { super(id); UserFormPanel userFormPanel = new UserFormPanel("userFormPanel"); add( userFormPanel ); List columns = new ArrayList(); final Model m = new Model(userFormPanel); columns.add(new PropertyColumn(new Model("Actions"), "id") { public void populateItem(Item cellItem, String componentId, final IModel model) { EditActionPanel panel = new EditActionPanel(componentId, model); panel.add( SecurePanelLink.createSecurePanelLink( "edit", m, UserFormPanel.class, model ) ); cellItem.add( panel ); } }); columns.add(new PropertyColumn(new Model("Username"), "username", "username")); columns.add(new PropertyColumn(new Model("First Name"), "firstName", "firstName")); columns.add(new PropertyColumn(new Model("Last Name"), "lastName", "lastName")); add(new DefaultDataTable("table", columns, new SortableUserDataProvider(), 10)); } SecurePanelLink public class SecurePanelLink extends Link implements ISecureComponent { /** * */ private static final long serialVersionUID = 1L; protected IPanelLink panelLink; /** * @param id * @param c */ public SecurePanelLink(String id, final Class c) { super(id); // Ensure that c is a subclass of Panel if (!Panel.class.isAssignableFrom(c)) { throw new IllegalArgumentException("Class " + c + " is not a subclass of Panel"); } this.panelLink = createIPanelLink( id, c ); setSecurityCheck(new LinkSecurityCheck(this, c)); } public SecurePanelLink(String id, final Class c, Model existingPanel) { super(id); // Ensure that c is a subclass of Panel if (!Panel.class.isAssignableFrom(c)) { throw new IllegalArgumentException("Class " + c + " is not a subclass of Panel"); } this.panelLink = createIPanelLink( id, c ); setSecurityCheck(new LinkSecurityCheck(this, c)); } private IPanelLink createIPanelLink( String id, final Class c ) { return new IPanelLink() { private static final long serialVersionUID = 1L; public Panel getPanel( String id ) {
Component parent null after replace
I am trying to create a link that will replace one panel with another on the page. This seems as though it should be an easy task but after many attempts and searching the net for examples I have yet to get it working so the replacement can happen more than one without the component becoming orphaned. On the second replace attempt i get the following exception. Anyone have the solution? Thank you, Anthony java.lang.IllegalStateException: This method can only be called on a component that has already been added to its parent. at org.apache.wicket.Component.replaceWith(Component.java:2266) at com.pinwise.pinbase.web.components.links.SecurePanelLink $4.onClick(SecurePanelLink.java:142) at org.apache.wicket.markup.html.link.Link.onLinkClicked (Link.java:222) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.wicket.RequestListenerInterface.invoke (RequestListenerInterface.java:186) = = public UserPanel(String id) { super(id); UserFormPanel userFormPanel = new UserFormPanel("userFormPanel"); add( userFormPanel ); List columns = new ArrayList(); final Model m = new Model(userFormPanel); columns.add(new PropertyColumn(new Model("Actions"), "id") { public void populateItem(Item cellItem, String componentId, final IModel model) { EditActionPanel panel = new EditActionPanel(componentId, model); panel.add( SecurePanelLink.createSecurePanelLink( "edit", m, UserFormPanel.class, model ) ); cellItem.add( panel ); } }); columns.add(new PropertyColumn(new Model("Username"), "username", "username")); columns.add(new PropertyColumn(new Model("First Name"), "firstName", "firstName")); columns.add(new PropertyColumn(new Model("Last Name"), "lastName", "lastName")); add(new DefaultDataTable("table", columns, new SortableUserDataProvider(), 10)); } SecurePanelLink public class SecurePanelLink extends Link implements ISecureComponent { /** * */ private static final long serialVersionUID = 1L; protected IPanelLink panelLink; /** * @param id * @param c */ public SecurePanelLink(String id, final Class c) { super(id); // Ensure that c is a subclass of Panel if (!Panel.class.isAssignableFrom(c)) { throw new IllegalArgumentException("Class " + c + " is not a subclass of Panel"); } this.panelLink = createIPanelLink( id, c ); setSecurityCheck(new LinkSecurityCheck(this, c)); } public SecurePanelLink(String id, final Class c, Model existingPanel) { super(id); // Ensure that c is a subclass of Panel if (!Panel.class.isAssignableFrom(c)) { throw new IllegalArgumentException("Class " + c + " is not a subclass of Panel"); } this.panelLink = createIPanelLink( id, c ); setSecurityCheck(new LinkSecurityCheck(this, c)); } private IPanelLink createIPanelLink( String id, final Class c ) { return new IPanelLink() { private static final long serialVersionUID = 1L; public Panel getPanel( String id ) { // Create panel using panel factory return getPanelFactory().newPanel(id, c ); } public Panel getPanel( String id, IModel model) { // Create panel using panel factory return getPanelFactory().newPanel(id, c, model); } public Panel getPanel( Panel panel, IModel model) { // Create panel using panel factory return getPanelFactory().newPanel(panel.getId(), c, model); } public Class getPanelIdentity() { return c; } }; } /** * */ public static SecurePanelLink createSecurePanelLink( String id, Class clazz ) { return new SecurePanelLink( id, clazz ) { /**