3 Replies Latest reply on May 10, 2009 1:39 AM by Cruz Fernandez

    What is the added value of SeamPropertyModel in jboss-seam-wicket

    Martijn Lindhout Newbie

      Don't know when to use it

        • 2. Re: What is the added value of SeamPropertyModel in jboss-seam-wicket
          Paul Mooney Newbie

          I'm going to hazard a guess here,
          The SeamPropertyModel is (in some way) Seam's alternative to the loadable-detachable property model. Using the SeamPropertyModel lets you take advantage of the bijection mechanism, and simultaneously prevents wicket from Serializing the model object. This leaves you with a pseudo model object loading and detaching because the model object is never actually attached to the model, rather it is bijected in and out of it. Does that sound about right?


          Is it possible to have an alternate propertymodel that takes two strings: the context name of the model object, and the property expression of the component. And the getObject() method would call Component.getInstance(modelObjectName)?

          • 3. Re: What is the added value of SeamPropertyModel in jboss-seam-wicket
            Cruz Fernandez Newbie

            Paul Mooney wrote on Jan 12, 2009 18:24:



            Is it possible to have an alternate propertymodel that takes two strings: the context name of the model object, and the property expression of the component. And the getObject() method would call Component.getInstance(modelObjectName)?


            I think the idea of Paul is right, and the SeamPropertyModel should encapsulate a context-seam object (without need to inject it in the page and rewrite getObject each time). The same idea can be applied to a CompoundPropertyModel.


            package org.jboss.seam.wicket;
            
            import org.apache.wicket.model.IModel;
            import org.jboss.seam.Component;
            import org.jboss.seam.RequiredException;
            
            /**
             * A wrapper model for getting a SEAM object by its name It should contemplate
             * all the cases of Injection
             * 
             * @author cruz
             * 
             */
            public class SeamModel implements IModel {
                 private static final long serialVersionUID = 1L;
            
                 private String name;
                 private boolean create;
            
                 private Object seamObject;
            
                 public SeamModel(String name) {
                      this.name = name;
                      create = false;
                 }
            
                 public SeamModel(String name, boolean create) {
                      this.name = name;
                      this.create = create;
                 }
            
                 public Object getObject() {
                      if (seamObject == null) {
                           seamObject = Component.getInstance(name, create);
                           if (seamObject == null)
                                throw new RequiredException("Couldn't find an instance '"
                                          + name + "' of object");
                      }
                      return seamObject;
                 }
            
                 public void setObject(Object object) {
                      this.seamObject = object;
                 }
            
                 public void detach() {
                      seamObject = null;
                 }
            
            }
            



            We can the make SeamPropertyModel:


            package org.jboss.seam.wicket;
            
            import org.apache.wicket.model.PropertyModel;
            
            public class SeamPropertyModel extends PropertyModel {
                 private static final long serialVersionUID = 1L;
            
                 /**
                  * Constructs a SeamPropertyModel with a SEAM object-name as a parameter
                  * 
                  * @param name
                  * @param expression
                  */
                 public SeamPropertyModel(String name, String expression) {
                      super(new SeamModel(name), expression);
                 }
            
                 /**
                  * Creates a SeamPropertyModel attached to a SeamModel. Allows creation of object
                  * @param name Name of the object in the SEAM context
                  * @param expression Expression that access the field
                  * @param create if the object should be instantiated by SEAM
                  */
                 public SeamPropertyModel(String name, String expression, boolean create) {
                      super(new SeamModel(name, create), expression);
                 }
            }
            



            And a SeamCompoundPropertyModel:


            package org.jboss.seam.wicket;
            
            import org.apache.wicket.model.CompoundPropertyModel;
            
            /**
             * Creates a compoundPropertyModel with a SEAM object,
             * It can be created in the context
             * It should contemplate all the Injection cases
             * @author cruz
             *
             */
            public class SeamCompoundPropertyModel extends CompoundPropertyModel {
                 private static final long serialVersionUID = 1L;
                 
                 public SeamCompoundPropertyModel(String name) {
                      super(new SeamModel(name));
                 }
                 
                 public SeamCompoundPropertyModel(String name, boolean create) {
                      super(new SeamModel(name,create));
                 }
            
            
            }