How to bind Hibernate domain objects to the UI layer

Dear All,
I am trying to bind FX UI controls to properties of a Hibernate Domain object. Is there any good example to refer to for this purpose?
Thanks & Regards,
Nitin Gupta

Assuming you do not formulate your hibernate objects as pojos with javafx properties directly, if the hibernate object is a pojo with or without PCL, you can convert the properties of the pojo to observable values (or properties) directly. These are used in a bind statement.
Check out what jgoodies does with BeanAdapter or PresentationModel. You need the same concept. I've attached a class that does this for a pojo already (its an incomplete port of jgoodies PresentationModel). It will work for any pojo. It does not have setter support as it was just a demonstration. Its efficient for a pojo with a large number of properties. You could also write a very short property connector to produce one observable value per property. The value of the class below is to be able to swap out the bean being observed without having to change or reset the property observable values each time. Bind once and then just reset the bean (think master detail).
package scenegraphdemo;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ObjectPropertyBase;
import javafx.beans.property.Property;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.WritableValue;
* An object binding object that creates object bindings based on property names
* specified as strings. This is a convenience class to avoid having observable
* values directly dependent on the underlying bean. The actual bean the
* properties connect can be changed dynamically using the channel or
* <code>setBean</code>. This allows you to setup binding when you don't have
* the bean to bind to or the bean to bind to will change as in the detail part
* of a master-detail screen. Generally, the return values from
* <code>getProperty()</code> should be used for binding not the factory itself.
* The object should be a domain object bean with bean methods to get or set the
* value using java bean naming conventions OR it should use javafx property
* definition conventions. The factory will automatically listen for standard
* java bean changes using <code>PropertyChangeListener</code> approaches unless
* you indicate to not to.
* <p>
* When the bean itself changes, the properties fire to indicate that their
* values may have changed and the observing object should update itself. This
* object allows you to integrate your javafx/POJOs into the binding
* infrastructure without being dependent on the actual underlying bean. If you
* are familiar with jgoodies <code>BindingAdapter</code> this is a similar
* class.
* <p>
* This only handles reading bean properties. Need to add set() logic.
* <p>
* TODO: Make this work better. Many corner cases to cover.
* <p>
* TODO: Instead of just method calls on POJOs, also check for PCL. Note that
* javafx properties won't work easily they are always tied to the underlying
* object so I would have to write another CaptiveObjectProperty object that is
* essentially a delegator.
public class BeanPropertyFactory<T> extends ObjectProperty<T> {
     ObservableValue<T> channel;
     Map<String, CaptiveObjectProperty> properties = new HashMap<String, CaptiveObjectProperty>();
     boolean listenForBeanPCLEvents = true;
     public boolean isListenForBeanPCLEvents() {
          return listenForBeanPCLEvents;
     public void setListenForBeanPCLEvents(boolean listenForBeanPCLEvents) {
          this.listenForBeanPCLEvents = listenForBeanPCLEvents;
          if (getBean() != null)
               removeBeanPCLListener(getBean());
      * The bean channel where the bean is obtained.
      * @return
     public ObservableValue<T> getChannel() {
          return channel;
     public BeanPropertyFactory() {
          setChannel(new ObjectProperty());
     public BeanPropertyFactory(ObservableValue<T> channel) {
          if (channel == null)
               setChannel(new ObjectProperty());
          else
               setChannel(channel);
     protected void setChannel(ObservableValue<T> channel) {
          if (this.channel != null) {
               removeBeanChangeListener(this.channel);
          this.channel = channel;
          if (this.channel != null) {
               addBeanChangeListener(this.channel);
               updateStringProperty(getBean());
          invalidateProperties();
          fireValueChangedEvent();
     protected StringProperty stringProperty = new StringProperty();
      * The string property is an observable toString property. It cannot be set.
      * @return
     public StringProperty beanStringProperty() {
          return stringProperty;
     public String getBeanString() {
          return beanStringProperty().getValue();
      * A listener that listens to changes in the bean channel. This only fires
      * when the bean changes not when the properties on the bean change. The
      * default actions updates the "string" property representation of this
      * object as well as attaches property change listeners.
      * @author Mr. Java
     protected class BeanChangeListener implements ChangeListener {
          @Override
          public void changed(ObservableValue arg0, Object arg1, Object arg2) {
               if (arg1 != null) {
                    BeanPropertyFactory.this.removeBeanPCLListener(arg1);
               if (arg2 != null) {
                    BeanPropertyFactory.this.addBeanPCLListener(arg2);
               updateStringProperty(arg2);
     protected void updateStringProperty(Object obj) {
          if (obj != null)
               beanStringProperty().setValue(obj.toString());
          else
               beanStringProperty().setValue("null");
     protected void removeBeanChangeListener(ObservableValue<T> obj) {
          if (beanChangeListener == null)
               beanChangeListener = createBeanChangeListener();
          if (obj != null) {
               obj.addListener(beanChangeListener);
     protected void addBeanChangeListener(ObservableValue<T> obj) {
          if (beanChangeListener == null)
               beanChangeListener = createBeanChangeListener();
          if (obj != null)
               obj.removeListener(beanChangeListener);
      * The instance of a change listener for detecting when the bean in the bean
      * channel changes.
     ChangeListener beanChangeListener = new BeanChangeListener();
      * Subclass can override to create their bean change listener.
      * @return
     protected ChangeListener createBeanChangeListener() {
          return new BeanChangeListener();
     public BeanPropertyFactory(T bean) {
          setChannel(new ObjectProperty(bean));
     public Property getProperty(String property) {
          if (property == null || property.isEmpty())
               throw new IllegalArgumentException("Property cannot be null");
          if (properties.containsKey(property))
               return properties.get(property);
          CaptiveObjectProperty p = new CaptiveObjectProperty(this, property);
          properties.put(property, p);
          return p;
     @Override
     public T getValue() {
          return getBean();
      * A listener that listens for property change events on the bean. When the
      * bean changes, the listener must be removed then attached to the new bean
      * but can use the same instance of this class. The action is to inform any
      * existing property objects that the property has changed. The detection of
      * property changes is centralized in the factory class for efficiency.
     protected class BeanPropertyListener implements PropertyChangeListener {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
               if (properties.containsKey(evt.getPropertyName())) {
                    CaptiveObjectProperty p = properties.get(evt.getPropertyName());
                    p.propertyChanged();
               updateStringProperty(getBean());
      * The cached listener instance to listen to the bean (in the bean channel)
      * property change events if it supports PCL.
     PropertyChangeListener beanPropertyListener;
      * Subclasses can override to implement their own behavior. Its best to
      * extend from <code>BeanPropertyListiner</code> to include the default
      * behavior.
      * @return
     protected PropertyChangeListener createBeanPropertyListener() {
          return new BeanPropertyListener();
      * Add a listener only if the PCL methods exist. This listens for property
      * changes on the bean's property not changes in the actually bean held by
      * the bean channel.
     protected void addBeanPCLListener(Object obj) {
          if (!isListenForBeanPCLEvents())
               return;
          if (obj != null) {
               if (BeanPropertyUtils.hasPCL(obj.getClass())) {
                    if (beanPropertyListener == null)
                         beanPropertyListener = createBeanPropertyListener();
                    BeanPropertyUtils.addPCL(obj, beanPropertyListener, null);
      * Remove a listener only if the PCL methods exist.
      * @see #attachBeanPCLListener
     protected void removeBeanPCLListener(Object obj) {
          if (obj != null) {
               if (BeanPropertyUtils.hasPCL(obj.getClass())) {
                    if (beanPropertyListener == null)
                         beanPropertyListener = createBeanPropertyListener();
                    BeanPropertyUtils.removePCL(obj, beanPropertyListener, null);
      * Invalidate the properties in the property cache. Then changed the bean in
      * the bean channel. Then fire a value changed event.
      * @param bean
     public void setBean(T bean) {
          invalidateProperties();
          if (getChannel() instanceof WritableValue) {
               ((WritableValue) getChannel()).setValue(bean);
          } else {
               throw new IllegalArgumentException(
                         "Could not set bean value into a non-writable bean channel");
          fireValueChangedEvent();
      * Called to indicate that the underlying bean changed.
     protected void invalidateProperties() {
          for (CaptiveObjectProperty p : properties.values()) {
               p.invalidate();
     public T getBean() {
          return getChannel().getValue();
      * Lazily get the method representing the property prior to getting or
      * setting. Because this is a property, it can also be bound to.
      * @author Mr. Java
      * @param <T>
     protected static class CaptiveObjectProperty<T> extends
               ObjectPropertyBase<T> {
           * The string name of the property.
          String readPropertyName, writePropertyName;
           * If the property is really a javafx property, it is stored here.
          Property<T> enhancedProperty;
           * Used if the property is not an enhanced property.
          Method readMethod, writeMethod;
           * The factory that holds the bean we obtain values against.
          BeanPropertyFactory factory;
          public CaptiveObjectProperty(BeanPropertyFactory factory,
                    String property) {
               this.readPropertyName = property;
               this.factory = factory;
          public CaptiveObjectProperty(BeanPropertyFactory factory,
                    String property, String writePropertyName) {
               this.readPropertyName = property;
               this.writePropertyName = writePropertyName;
               this.factory = factory;
          @Override
          public Object getBean() {
               if (factory == null || factory.getBean() == null)
                    return null;
               return factory.getBean();
          @Override
          public void store(T value) {
               if (writeMethod == null && enhancedProperty == null) {
                    getWriteMethod(value.getClass());
               if (writeMethod == null && enhancedProperty == null) {
                    return;
               try {
                    if (enhancedProperty != null) {
                         enhancedProperty.setValue(value);
                         return;
                    if (getBean() == null)
                         return;
                    writeMethod.invoke(getBean(), value);
                    return;
               } catch (Exception e) {
                    e.printStackTrace();
          @Override
          public T getValue() {
               if (readMethod == null && enhancedProperty == null) {
                    getReadMethod();
               if (readMethod == null && enhancedProperty == null)
                    return null;
               try {
                    if (enhancedProperty != null)
                         return enhancedProperty.getValue();
                    if (factory.getBean() == null)
                         return null;
                    Object rval = readMethod.invoke(getBean());
                    return (T) rval;
               } catch (Exception e) {
                    e.printStackTrace();
               return null;
          @Override
          public String getName() {
               return readPropertyName;
           * Invalidate the method. Perhaps the bean changed to another object and
           * we should find the method on the new object. This is called prior to
           * the <code>getBean()</code> being changed.
          public void invalidate() {
               readMethod = null;
               fireValueChangedEvent();
           * This is used to externally signal that the property has changed. It
           * is quite possible that this object does not detect those changes and
           * hence, an external object (in all cases the BeanPropertyFactory) will
           * signal when a change occurs. Property change detection is centralized
           * in the factory for efficiency reasons.
          public void propertyChanged() {
               fireValueChangedEvent();
          protected Property getJavaFXReadProperty(String propertyName) {
               if (factory.getBean() == null)
                    return null;
               String methodName = getName() + "Property";
               try {
                    Method mtmp = factory.getBean().getClass()
                              .getMethod(methodName, new Class<?>[0]);
                    enhancedProperty = (Property) mtmp.invoke(factory.getBean(),
                              new Object[0]);
                    return enhancedProperty;
               } catch (Exception e) {
                    // e.printStackTrace();
                    // silently fail here
               return null;
          protected void getWriteMethod(Class<?> argType) {
               if (factory == null || factory.getBean() == null)
                    return;
               if (enhancedProperty == null)
                    enhancedProperty = getJavaFXReadProperty(getName());
               if (enhancedProperty != null)
                    return;
               writeMethod = getPojoWriteMethod(getName(), argType);
           * Sets the method, either an enhanced property or the POJO method via
           * reflection.
           * @return
          protected void getReadMethod() {
               if (factory == null || factory.getBean() == null)
                    return;
               enhancedProperty = getJavaFXReadProperty(getName());
               if (enhancedProperty != null)
                    return;
               // Look for standard pojo method.
               readMethod = getPOJOReadMethod(getName());
           * Return a get method using reflection.
           * @param propertyName
           * @return
          protected Method getPOJOReadMethod(String propertyName) {
               if (factory.getBean() == null)
                    return null;
               // Look for standard pojo method.
               String methodName = getGetMethodName();
               try {
                    Method mtmp = factory.getBean().getClass()
                              .getMethod(methodName, new Class<?>[0]);
                    return mtmp;
               } catch (Exception e) {
                    // silently fail here
                    // e.printStackTrace();
               return null;
          protected String getGetMethodName() {
               String methodName = "get"
                         + Character.toUpperCase(getName().charAt(0));
               if (getName().length() > 1)
                    methodName += getName().substring(1);
               return methodName;
           * Return a set method using reflection.
           * @param propertyName
           * @param argType
           * @return
          protected Method getPojoWriteMethod(String propertyName,
                    Class<?> argType) {
               if (factory.getBean() == null)
                    return null;
               String methodName = getSetMethodName();
               try {
                    Method mtmp = factory.getBean().getClass()
                              .getMethod(methodName, argType);
                    return mtmp;
               } catch (Exception e) {
                    // silently fail here
                    // e.printStackTrace();
               return null;
          protected String getSetMethodName() {
               String methodName = "set"
                         + Character.toUpperCase(getName().charAt(0));
               if (getName().length() > 1)
                    methodName += getName().substring(1);
               return methodName;
      * Obtain a property using the binding path. The binding path should be
      * simple property names separated by a dot. The bean has to specified
      * because the return value is a property that can be used directly for
      * binding. The first property specified in the binding path should be a
      * property on the bean.
      * <p>
      * The difference between this and <code>Bindings.select()</code> is not
      * much other that it uses the bean factory machinery and the path can be
      * specified as a string. Of course, the bean can be a plain pojo.
      * @param bindingPath
      * @return
     public static Property propertyFromBindingPath(Object bean,
               String bindingPath) {
          if (bindingPath == null || bindingPath.isEmpty())
               return null;
          BeanPropertyFactory lastFactory = null;
          Property lastProperty = null;
          String[] parts = bindingPath.split("\\.");
          if (parts.length > 0) {
               for (int i = 0; i < parts.length; i++) {
                    if (parts.length() <= 0 || parts[i].isEmpty()) {
                         throw new IllegalArgumentException("Binding path part " + i
                                   + " has no length");
                    BeanPropertyFactory newFactory;
                    if (i == 0)
                         newFactory = new BeanPropertyFactory(bean);
                    else
                         newFactory = new BeanPropertyFactory(
                                   (WritableValue) lastProperty);
                    lastProperty = newFactory.getProperty(parts[i].trim());
                    lastFactory = newFactory;
          return lastProperty;
     * Alot like <code>Bindings.select</code> but also handles pojos.
     * @param bean
     * @param path
     * @return
     public static Property propertyFromBindingPath(Object bean, String... path) {
          String tmp = "";
          for (int i = 0; i < path.length; i++) {
               tmp += path[i];
               if (i <= path.length - 1)
                    tmp += ".";
          return propertyFromBindingPath(bean, tmp);
and a supporting classpackage scenegraphdemo;
import java.beans.PropertyChangeListener;
* Static methods for manipulating PCL for standard java beans.
* @author Mr. Java
public class BeanPropertyUtils {
     protected final static Class<?>[] NO_ARGS = new Class<?>[] { PropertyChangeListener.class };
     protected final static Class<?>[] ARGS = new Class<?>[] { String.class,
               PropertyChangeListener.class };
     protected final static String pclAddMethodName = "addPropertyChangeListener";
     protected final static String pclRemoveMethodName = "removePropertyChangeListener";
     * Return true if the class has PCL methods. Does not check for remove.
     * <p>
     * addPropertyChangeListener(PropertyChangeListener)
     * <p>
     * addPropertyChangeListener(String, PropertyChangeListener)
     * @param bean
     * @return
     public static boolean hasPCL(Class<?> clazz) {
          try {
               if (clazz.getMethod(pclAddMethodName, NO_ARGS) != null) {
                    return true;
          } catch (Exception e) {
               // silently fail
          try {
               if (clazz.getMethod(pclAddMethodName, ARGS) != null) {
                    return true;
          } catch (Exception e) {
               // silently fail
          return false;
     * Add a listener.
     * @param bean
     * @param listener
     * @param propertyName
     public static void addPCL(Object bean, PropertyChangeListener listener,
               String propertyName) {
          try {
               if (propertyName == null) {
                    bean.getClass().getMethod(pclAddMethodName, NO_ARGS)
                              .invoke(bean, new Object[] { listener });
               } else {
                    bean.getClass()
                              .getMethod(pclAddMethodName, ARGS)
                              .invoke(bean,
                                        new Object[] { propertyName, listener });
          } catch (Exception e) {
               e.printStackTrace();
     * Remove a listener.
     * @param bean
     * @param listener
     * @param propertyName
     public static void removePCL(Object bean, PropertyChangeListener listener,
               String propertyName) {
          try {
               if (propertyName == null) {
                    bean.getClass().getMethod(pclRemoveMethodName, NO_ARGS)
                              .invoke(bean, new Object[] { listener });
               } else {
                    bean.getClass()
                              .getMethod(pclRemoveMethodName, ARGS)
                              .invoke(bean,
                                        new Object[] { propertyName, listener });
          } catch (Exception e) {
               e.printStackTrace();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

Similar Messages

  • How to bind a UI element to the context

    Hi Experts,
               I have a problem binding UI element to the context. In my code i have to create TabStrips dynamically and under this tabstrip number of UI elements would be there. For this i have a code like this..
    IWDTransparentContainer theActionContainer =(IWDTransparentContainer)view.getElement("RootUIElementContainer");
         IWDTabStrip ts = (IWDTabStrip) view.createElement(IWDTabStrip.class,"TabStrip");
              IWDTab tab1 = (IWDTab) view.createElement(IWDTab.class,"Tab1");
              IWDInputField in = (IWDInputField) view.createElement(IWDInputField.class,"in");
              IWDCaption header1 = (IWDCaption) view.createElement(IWDCaption.class,"Header1");
              header1.setText("Tab1");
              tab1.setContent(in);
              ts.addTab(tab1);
              IWDTab tab2 = (IWDTab) view.createElement(IWDTab.class,"Tab2");
              IWDInputField in2 = (IWDInputField) view.createElement(IWDInputField.class,"in2");
              IWDCaption header2 = (IWDCaption) view.createElement(IWDCaption.class,"Header2");
              header2.setText("Tab2");
              tab2.setHeader(header2);
              ts.addTab(tab2);
              theActionContainer.addChild(ts);
    <b>when i run this code it is giving following exceptions..</b>
    The initial exception that caused the request to fail, was:
       com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: Property 'value' of AbstractInputField with id 'in' in view 'LoginView' must be bound to the context
        at com.sap.tc.webdynpro.clientserver.uielib.standard.impl.AbstractInputField.getValue(AbstractInputField.java:1260)
        at com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.InputFieldAdapter.getValue(InputFieldAdapter.java:582)
        at com.sap.tc.ur.renderer.ie6.InputFieldRenderer.render(InputFieldRenderer.java:56)
        at com.sap.tc.webdynpro.clientimpl.html.renderer.uielements.base.RenderManager.render(RenderManager.java:435)
        at com.sap.tc.webdynpro.clientimpl.html.renderer.uielements.base.RenderManager.render(RenderManager.java:134)
        ... 63 more
    com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: Property 'value' of AbstractInputField with id 'in' in view 'LoginView' must be bound to the context
         at com.sap.tc.webdynpro.clientserver.uielib.standard.impl.AbstractInputField.getValue(AbstractInputField.java:1260)
         at com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.InputFieldAdapter.getValue(InputFieldAdapter.java:582)
         at com.sap.tc.ur.renderer.ie6.InputFieldRenderer.render(InputFieldRenderer.java:56)
         at com.sap.tc.webdynpro.clientimpl.html.renderer.uielements.base.RenderManager.render(RenderManager.java:435)
         at com.sap.tc.webdynpro.clientimpl.html.renderer.uielements.base.RenderManager.render(RenderManager.java:134)
         at com.sap.tc.ur.renderer.ie6.TabStripRenderer.renderTabStripItemContentFragment(TabStripRenderer.java:1867)
         at com.sap.tc.ur.renderer.ie6.TabStripRenderer.renderTabStripFragment(TabStripRenderer.java:838)
    From these exceptions what  i understood is, i need to bind these UI elements to context.
       Can any body tell me how to bind a UI element to the context if I understood the exceptions correct..
    Thanks in Advance,
    Murthy.

    HI,
    lets say Ctx is your context attribute,
    IWDAttributeInfo attrInfo = wdContext.getNodeInfo.getAttribute("Ctx");
    then , as per your code,
    IWDInputField in = (IWDInputField) view.createElement(IWDInputField.class,"in");
    <b>in.bindValue(attrInfo);</b>
    if your contex attribute is child of some other node then do like this,
    IWDAttributeInfo attrInfo = wdContext.getNodeInfo.getChildNode("SalesOrder",0)getAttribute("Ctx");
    //this is when Ctx is child of node SalesOrder, and we are taking Ctx from its 0th element
    then ,
    IWDInputField in = (IWDInputField) view.createElement(IWDInputField.class,"in");
    <b>in.bindValue(attrInfo);</b>
    include this in your code ,
    let me know if you face any problem
    regards
    reward points if it helps

  • How to center a JFrame object on the screen?

    Does somebody know how to center a JFrame object on the screen. Please write an example because I'm new with java.
    Thank you.

    //this will set the size of the frame
    frame.setSize(frameWidth,frameHeigth);
    //get screen size
    Toolkit kit=Toolkit.getDefaultToolkit();
    //calculate location for frame
    int x=(kit.getScreenSize().width/2)-(frameWidth/2);
    int y=(kit.getScreenSize().height/2)-(frameHeigth/2);
    //set location of frame at center of screen
    frame.setLocation(x,y);

  • How to place am mime object on the smartform ?

    Hi All,
    How to place am mime object on the smartform ?
    Is there any function module to read a mime object from mime repository?
    Any help would be appreciated.
    Regards,
    Raja Ram.

    Hi Vishwa,
    Thanks for your prompt response.
    How to get the obj ID of a MIME object?
    I checked in So2_MIME_REPOSITORY bur couldn't find?
    Is there any mapping table between MIME object and object ID ?
    I am very new to MIME objects.
    Please tell me.
    Regards,
    Raja Ram.

  • How do I remove an object from the foreground of a photo eg a fence?

    How do I remove an object from the foreground of a photo eg a fence?

    What version of Photoshop?
    If CC then try here
    Learn Photoshop CC | Adobe TV

  • How can I write new objects to the existing file with already written objec

    Hi,
    I've got a problem in my app.
    Namely, my app stores data as objects written to the files. Everything is OK, when I write some data (objects of a class defined by me) to the file (by using writeObject method from ObjectOutputStream) and then I'm reading it sequencially by the corresponding readObject method (from ObjectInputStream).
    Problems start when I add new objects to the already existing file (to the end of this file). Then, when I'm trying to read newly written data, I get an exception:
    java.io.StreamCorruptedException
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    Is there any method to avoid corrupting the stream? Maybe it is a silly problem, but I really can't cope with it! How can I write new objects to the existing file with already written objects?
    If anyone of you know something about this issue, please help!
    Jai

    Here is a piece of sample codes. You can save the bytes read from the object by invoking save(byte[] b), and load the last inserted object by invoking load.
    * Created on 2004-12-23
    package com.cpic.msgbus.monitor.util.cachequeue;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    * @author elgs This is a very high performance implemention of Cache.
    public class StackCache implements Cache
        protected long             seed    = 0;
        protected RandomAccessFile raf;
        protected int              count;
        protected String           cacheDeviceName;
        protected Adapter          adapter;
        protected long             pointer = 0;
        protected File             f;
        public StackCache(String name) throws IOException
            cacheDeviceName = name;
            f = new File(Const.cacheHome + name);
            raf = new RandomAccessFile(f, "rw");
            if (raf.length() == 0)
                raf.writeLong(0L);
         * Whne the cache file is getting large in size and may there be fragments,
         * we should do a shrink.
        public synchronized void shrink() throws IOException
            int BUF = 8192;
            long pointer = getPointer();
            long size = pointer + 4;
            File temp = new File(Const.cacheHome + getCacheDeviceName() + ".shrink");
            FileInputStream in = new FileInputStream(f);
            FileOutputStream out = new FileOutputStream(temp);
            byte[] buf = new byte[BUF];
            long runs = size / BUF;
            int mode = (int) size % BUF;
            for (long l = 0; l < runs; ++l)
                in.read(buf);
                out.write(buf);
            in.read(buf, 0, mode);
            out.write(buf, 0, mode);
            out.flush();
            out.close();
            in.close();
            raf.close();
            f.delete();
            temp.renameTo(f);
            raf = new RandomAccessFile(f, "rw");
        private synchronized long getPointer() throws IOException
            long l = raf.getFilePointer();
            raf.seek(0);
            long pointer = raf.readLong();
            raf.seek(l);
            return pointer < 8 ? 4 : pointer;
         * (non-Javadoc)
         * @see com.cpic.msgbus.monitor.util.cachequeue.Cache#load()
        public synchronized byte[] load() throws IOException
            pointer = getPointer();
            if (pointer < 8)
                return null;
            raf.seek(pointer);
            int length = raf.readInt();
            pointer = pointer - length - 4;
            raf.seek(0);
            raf.writeLong(pointer);
            byte[] b = new byte[length];
            raf.seek(pointer + 4);
            raf.read(b);
            --count;
            return b;
         * (non-Javadoc)
         * @see com.cpic.msgbus.monitor.util.cachequeue.Cache#save(byte[])
        public synchronized void save(byte[] b) throws IOException
            pointer = getPointer();
            int length = b.length;
            pointer += 4;
            raf.seek(pointer);
            raf.write(b);
            raf.writeInt(length);
            pointer = raf.getFilePointer() - 4;
            raf.seek(0);
            raf.writeLong(pointer);
            ++count;
         * (non-Javadoc)
         * @see com.cpic.msgbus.monitor.util.cachequeue.Cache#getCachedObjectsCount()
        public synchronized int getCachedObjectsCount()
            return count;
         * (non-Javadoc)
         * @see com.cpic.msgbus.monitor.util.cachequeue.Cache#getCacheDeviceName()
        public String getCacheDeviceName()
            return cacheDeviceName;
    }

  • How to add a ChartOfAccounts object into the database.

    how to add a ChartOfAccounts object into the database. please shows sample code
    thanks

    Dim CoA As SAPbobsCOM.ChartOfAccounts
                CoA = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oChartOfAccounts)
                CoA.Code = 11223344
                CoA.ExternalCode = "a1234"
                CoA.ForeignName = "f Test Account"
                CoA.Name = "Test Account"
                CoA.AccountType = SAPbobsCOM.BoAccountTypes.at_Other
                CoA.ActiveAccount = SAPbobsCOM.BoYesNoEnum.tYES
                CoA.FatherAccountKey = 100001
                If CoA.Add <> 0 Then
                    MessageBox.Show(oCompany.GetLastErrorDescription)
                Else
                    MessageBox.Show("Added Account")
                End If
    Remember the father account key must be a valid account number in the company where you are trying to add the new account.  (The G/L Account code seen in the SBO client)

  • Creating a new cell factory, how to bind to my object's property

    As near as I can tell, the javafx binding using observable values, alot like jgoodies and its not like SWT databinding or WPF binding.
    I was creating a cell factory for a TreeView. Just using a label to display the contents and calling toString, alot like the way it works now. However, I could not figure out to create a binding that would bind to a property on my domain object. Is there a way to specify the binding to the Label's text property so that whatever object that the cell's item's value has I can bind to a property that I specify on it e.g. the "name" property. But I could not see how to do that. Also, the only way I could figure out how to update the Label's value was from updateItem. I thought maybe I could even setup the binding in updateItem so that when the TreeItem's value changed at least it would automatically update the label binding, but the API did not seem to support that.
    What's the right coding pattern to use when using straight Java coding?
    I know in jgoodies I could do this using the PresentationModel approach or master-detail SWT or WPF with just specifying the property on the item's property that I want in WPF.
    public static class MyTreeCell extends TreeCell<Object> {
              Label label;
              public MyTreeCell() {
                   label = new Label();
                   setNode(label);
              @Override
              public void updateItem(TreeItem<Object> arg0, boolean arg1) {
                   if (arg0 != null && arg0.getValue() != null) {
                        System.out.println("New value: " + arg0.getValue());
                        label.setText(arg0.getValue().toString());
                   } else {
                        System.out.println("New value is null and this println is called alot, why is that?");
                   super.updateItem(arg0, arg1);
         }

    Well the presentation model thing worked fine and I have some machinery for the cell factory/cell item to obtain a tree cell based on the domain object type (a template/factory is placed into the properties in the scenegraph hierarchy). But its not smooth yet and the pattern does not quite translate well into javafx. Because the cell factory produces cells that could be used for a variety of domain object types, all the logic gets pushed down to the treecell subclass which makes it messy. Maybe this is where CSS selectors need to come in, you specify the class of a tree cell for a specific domain object type and you can set that at the root of the application so it cascades. I'll see if this approach works.
    Here's the code for the javafx version of jgoodies' presentation model, less the corner cases. This allows you to bind to a property and change the bean underneath that the property accesses. I'm not convinced that having properties has observable values directly on the objects is the right model for javafx because of the coupling to the actual object the property represents. Sometimes, you need to represent the property concept separate from the actual object instance. Maybe this already exists in the library.
          * An object binding object that creates object bindings based on property
          * names specified as strings. This is a convenience class. Generally, the
          * return values from <code>getProperty()</code> should be used for binding
          * not the factory itself. The object should be a domain object bean with
          * bean methods to get or set the value using java bean naming conventions.
          * When the bean itself changes, the properties fire to indicate that their
          * values may have changed and the observing object should update itself.
          * <p>
          * This only handles reading bean properties. Need to add set() logic.
          * <p>
          * TODO: Make this work better. Many corner cases to cover. Include PCL.
         public static class BeanBindingFactory<T> extends ObjectBinding<T> {
              T bean;
              Map<String, CaptiveObjectProperty> properties = new HashMap<String, CaptiveObjectProperty>();
              public Property getProperty(String property) {
                   if (property == null || property.isEmpty())
                        throw new IllegalArgumentException("Property cannot be null");
                   if (properties.containsKey(property))
                        return properties.get(property);
                   CaptiveObjectProperty p = new CaptiveObjectProperty(this, property);
                   properties.put(property, p);
                   return p;
              public void setBean(T bean) {
                   this.bean = bean;
                   for (CaptiveObjectProperty p : properties.values()) {
                        p.invalidate();
                   fireValueChangedEvent();
              public T getBean() {
                   return bean;
              @Override
              protected T computeValue() {
                   return bean;
               * Lazily get the method representing the property.
               * @author Mr. Java
               * @param <T>
              protected static class CaptiveObjectProperty<T> extends
                        ObjectPropertyBase<T> {
                   String property;
                   Method m;
                   BeanBindingFactory factory;
                   public CaptiveObjectProperty(BeanBindingFactory factory,
                             String property) {
                        this.property = property;
                        this.factory = factory;
                   @Override
                   public Object getBean() {
                        if (factory == null || factory.getBean() == null)
                             return null;
                        return factory.getBean();
                   @Override
                   public T getValue() {
                        if (m == null) {
                             m = getMethod();
                        if (m == null)
                             return null;
                        try {
                             Object rval = m.invoke(factory.getBean());
                             return (T) rval;
                        } catch (Exception e) {
                             e.printStackTrace();
                        return null;
                   @Override
                   public String getName() {
                        return property;
                    * Invalidate the method. Perhaps the bean changed to another object
                    * and we should find the method on the new object.
                   public void invalidate() {
                        m = null;
                        fireValueChangedEvent();
                   protected Method getMethod() {
                        if (factory == null || factory.getBean() == null)
                             return null;
                        String methodName = "get"
                                  + Character.toUpperCase(getName().charAt(0));
                        if (getName().length() > 1)
                             methodName += getName().substring(1);
                        try {
                             Method mtmp = factory.getBean().getClass()
                                       .getMethod(methodName, new Class<?>[0]);
                             return mtmp;
                        } catch (Exception e) {
                             e.printStackTrace();
                        return null;
         }

  • How to bind data (from database) to the Dictionary structure in Web Dynpro

    Hi,
    I am getting Hashtable object from the database related classes and I want to bind this data to the Dictionary field in Web Dynpro. So, I can bind this Dictionary field type to the Context variable.
    Please let me know the detailed procedure.
    Thanks
    Tatayya M

    Tatayya,
    Look at this sample tutorial , It will defintely help you with the Data Dictionary .
    https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/bad3e990-0201-0010-3985-fa0936d901b4
    https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/38650ecd-0401-0010-10a0-f9d8fd37edee

  • How to bind "Image Field" object on a database

    Hi to all
    I inserted into a dynamic PDF (Livecycle ES3 trial) an image field, but I don't understand how I can to bind a JPG into a database.
    In (F5) preview... I'm able to open a image file on filesystem and visualize it on PDF form... but then? How to bind on database?
    In my several tentatives I'm using a MS Access 2010 database table, where I defined a OLE object... but doesn't work.
    Thank you at all.
    visert

    Hi,
    I have not tried to do this, but this document provides some instructions.
    http://partners.adobe.com/public/developer/en/livecycle/lc_designer_XML_schemas.pdfhttp://partners.adobe.com/public/developer/en/livecycle/lc_designer_XML_schemas.pdf
    Hope it helps
    Bruce

  • XSLT - How to pass a Java object to the xslt file ?

    Hi ,
    I need help in , How to pass a java object to xslt file.
    I am using javax.xml.transform.Tranformer class to for the xsl tranformation. I need to pass a java object eg
    Class Employee {
    private String name;
    private int empId;
    public String getName() {
    return this.name;
    public String getEmpId() {
    return this.empId;
    public String setName(String name) {
    this.name = name;
    public String setEmpId(int empId){
    this.empId = empId;
    How can i access this complete object in the xsl file ? is there any way i can pass custom objects to xsl using Transformer class ?

    This is elementary. Did you ask google ? http://www.google.com/search?q=calling+java+from+xsl
    ram.

  • How do I create an object on the fly

    Hello there,
         I was wondering if it is possible to create an object on-the-fly. For example:- I have a class called Customer which holds the name, address and phone number of a customer. While the program is running I get a new customer, Mr Brown. How can I create a new Customer object which will hold the details of Mr Brown.
    yours in anticipation
    seaview

    If I understood you right, you are thinking far too complicated.
    So, when you click a button, a new object shall be created and stored. So basically you write a listener to your button that contains a method like this:
    public void actionPerformed(ActionEvent e){
       Customer newCustomer = new Customer(textfield.getText());
       listOfCustomers.add(newCustomer);
    }Maybe what got you confused is the object's name. Remember this: variables and field names DON'T exist anymore at runtime! They are just meant to help you when programming. If you want Mr. Brown as a customer, you have to provide a field in the customer class for the name. If a field is required for the existence of an object, you usually write a custom constructor for it, which accepts an according parameter.

  • How to synchronize test schema objects with the prod schema objects.

    Hi,
    I have a requirement of synchronizing test schema objects with the production schema objects. Please let me know the below
    1. if there is a standardized method for such activity,
    2. if there are oracle utilities for this task.
    3. If i had to do this job manually, can you let me know the check list if any.
    Thanks
    Purushotham M

    http://www.oracle.com/technetwork/issue-archive/2012/12-sep/o52sqldev-1735911.html
    You could try database diff tool in sql developer(but there are some licence restrictions).
    I don't know your database version, you could try DBMS_COMPARISON package also.
    Look at this link http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_comparison.htm
    Other solution is to create db link between test and production database, and then you can try different types of queries like
    select table_name from user_tables
    minus
    select table_name from user_tables@db_link_to_other_database
    And you can do this for columns, indexes and so on.
    But you must have proper DDL scripts for this, to generate sync script.
    Also there is a question about work process, you are doing sync in reverse order(from production to test). Test db is for test, after test you go to production db with proper ddl and dml scripts, so these schemas shouldn't be different in the first place(talking about schema, not data here).

  • How to pass a session variable to the bussines layer?

    Hello,
    I am doing a management application, and I need to store the login user that make insertions on any table, and the pages does not has backing beans.
    I had try to do that bindding the value field of a hidden attribute with the session variable, but it only change the value of the one. My second attempt was make an javascript function to do that on the page´s load, but it not looks like a good solution.
    Someone knows a way to sent the session value to the bussines layer? O a way to access from the Bussines layer to the session?
    Thanks
    Tony

    <p>
    Hi,
    </p>
    <p>
    Another solution (that I always use) is storing simultaneously the same data in HttpSession (in view layer) and session hashtable (in businness layer).
    </p>
    <p>
    You can put and get these data in any businness component using following methods:
    </p>
    <p>
    <font face="courier new,courier" size="2" color="#0000ff">
    private void setToJboSession(String key, Object val){</font>
    <font face="courier new,courier" size="2" color="#0000ff"> Hashtable userData = getDBTransaction().getSession().getUserData();
    if (userData == null) {
    userData = new Hashtable();
     userData.put(key, val);
    }</font>
    </p>
    <p>
     and
    </p>
    <p>
    <font face="courier new,courier" size="2" color="#0000ff">
    private Object getFromJboSession(String key){
     return getDBTransaction().getSession().getUserData().get(key);
    }</font>
    </p>
    <p>
    Kuba 
    </p>

  • Handling file objects in the EJB layer

    It is seen that file handling in the EJB violates the specs.
    But, I have the requirement to read and parse some xpdl(xml specification) file in EJB.
    The parsing function is already in the EJB layer and the filepath is obtained as input from jsp(in the request) in a servlet.
    Im passing the filepath as a parameter to the bean method before parsing.
    Now the requirement is to construct the File object out of xpdl file and pass it as a parameter to EJB method. How can this be achieved?

    Hi,
    I'm not sure if this is helpful or not, but I just wanted to ask: If you know you need to parse the file on the EJB side, why not just go and do it? If you can always guarantee that files will be present in the same location that the beans are deployed to, then I don't think there is anything stopping you from reading them, if you know the full path to each file?
    You wrote that the path to the file is obtained from a JSP page. If those files need to be parsed anyway, you could move the parsing code to your JSPs (servlets), and use ServletContext.getResourceAsStream to read the contents. Then you could send the contents as a parameter to your EJB call.
    One last thing: if the files are large, you might want to consider using JMS and message-driven beans to do the reading/parsing job. Your MDBs could then call the EJBs, but you would have to return your results in an asynchronous manner.
    Just a couple of thoughts.
    Mark

Maybe you are looking for

  • Invoice Verification for Import PO

    Dear Friends, We are going live. We are uploading data. For certain Imports, For 10000 Kgs, Import Duties has been paid in february, Out of which, 5000 kgs has been received. For Remaining 5000kgs GRN is pending. So we are creating PO for 5000 Kgs. F

  • Good morning, I have an Apple Mac Id, now never receive emails confirming purchases.  Can someone kindly explain how to change my Id.

    Good morning,  I have an array of mac products and a very old .mac address which is also an email address.  Since the changeover to iCloud, I no longer get a confirmation email for any purchases. Can anyone help please?

  • Anyone Successfully Using iChat Today? (Fri, Jun23rd)

    Just checking to see if anyone is successfully getting an AV chat session going today. I usually connect with no problems, but since the past day or so, I haven't been able to connect with either any of my buddies (California/New York/Shanghai). Migh

  • Grouping Function usage in SQL

    All, How does grouping function work, does it also depends on the sequence of columns used in group by rollup   select deptno,job, group_id(), sum(sal), grouping(deptno) , grouping(job)   from emp   group by rollup (deptno, job)    If the query is ru

  • Download/upload abap objects to/from local PC

    Hi all,         I need to download objects of a tcode (like includes, reports etc) on to PC and  upload it to different server. Can anybody please send me the programs to upload and download objects. Thanks in Advance