ilog.webui.dhtml

Class IlxWComponent

  • All Implemented Interfaces:
    ilog.webui.dhtml.IlxWConstants, ilog.webui.dhtml.IlxWCSSModelProvider, ilog.webui.dhtml.IlxWDependencyProvider, ilog.webui.dhtml.IlxWJSObject, java.io.Serializable
    Direct Known Subclasses:
    ilog.rules.webui.dtable.IlrDTWTable, IlrDTWTableComponent, IlrDTWTableView, IlrWSyntacticEditor, IlrWTokenActionManager, IlrWToolBar, IlrWTree, IlrWValueEditorActionManager, IlxWActionHolder, IlxWButton, IlxWCalendar, IlxWDialog, IlxWIcon, IlxWLabel, ilog.webui.dhtml.components.IlxWLabelWrapper, IlxWList, ilog.webui.dhtml.components.IlxWMenuHolder, IlxWMenuItem, IlxWMessageList, IlxWTextElement


    public abstract class IlxWComponent
    extends IlxWContainer
    implements ilog.webui.dhtml.IlxWConstants, ilog.webui.dhtml.IlxWJSObject
    The base class for the web components.

    A web component is intended to be deployed in a servlet or a JSP page. It uses the method print(ilog.webui.dhtml.IlxWPort) to print its graphical representation to the designated port.

    To be used (that is, displayed on a web browser), a component has to be associated with a manager (see IlxWManager). Once a component has been stored in a manager, it can be printed to the current response writer through a port (see IlxWPort).

    The following code shows how you can integrate a web component in a servlet:

      import ilog.webui.dhtml.*;
      import ilog.webui.dhtml.components.*;
    
      public MyServlet extends HttpServlet {
    
        public void doGet(HttpServletRequest request,
                          HttpservletResponse response) {
          doPost(request, response);
        }
    
        public void doPost(HttpServletRequest request,
                           HttpservletResponse response) {
          // Gets the manager associated with the current session.
          IlxWManager manager = IlxWManager.getManager(request.getSession());
          final String treeId = "MyServlet.myTree";
          IlxWTree tree;
          synchronized (manager) {
            // Gets the component in the manager, or creates it if null.
            tree = (IlxWTree)manager.getComponentNamed(treeId);
            if (tree==null) {
              tree = new IlxWTree();
              // register the tree in the manager.
              tree.setName(treeId);
              manager.add(tree);
            }
          }
          PrintWriter out = response.getWriter();
          ServletContext ctx = getServletContext();
          // Creates a port.
          IlxWPort port = new IlxWPort(ctx, request, response, out);
          // Prints the well-known HTML code.
          out.println("<html>");
          out.println("<body>");
          // Opens the port (this generates some JavaScript code)
          port.open();
          out.println("<h1>This is the tree</h1>");
          // Prints the tree.
          tree.print(port);
          // Closes the port (this generates some JavaScript code)
          port.close();
          out.println("</body>");
          out.println("</html>");
        }
    
      }
     

    Once rendered to an HTML page, a web component has two representations:

    • on the server side: a Java object which is an instance of IlxWComponent associated with the current session by its manager.
    • on the client side: a JavaScript proxy which represents the Java object on the client. The graphical representation is in HTML. Component deployers do not have access to this proxy. It is automatically generated when a component is printed, and is managed by the component itself.
    The web components maintain coherence between their client side and their server side through the controller servlet (IlxWController).
    See Also:
    IlxWManager, IlxWPort, IlxWController, Serialized Form
    • Constructor Detail

      • IlxWComponent

        public IlxWComponent()
        Constructs a new web component.
    • Method Detail

      • setName

        public void setName(java.lang.String name)
        Sets the name of this component. This will be useful to retrieve a component by its name in a container.
        See Also:
        getName()
      • invalidate

        public void invalidate()
        Invalidates this component so that its print method is called as soon as possible.
        It means that next time a request is sent to the server to refresh a page that previously displayed this component, the component will be also redisplayed on the page.

        Note: With browsers that do not support incremental redisplaying, like Netscape 3 or Netscape 4, calling invalidate has no effect because the whole page is redisplayed each time the server is called (the target is set to _self).
        On the other hand, with browsers like MS IE5, only the components that need to be redisplayed will be actually refreshed. This is the reason why we need to specify that a component modified on the server has to be redisplayed.

        Component deployers will typically call this method at the end of the implementation of a business method of the component. Suppose you have a component with a setColor method, you will typically implement it as follows:

           class MyComponent extends IlxWComponent {
             ...
             public void setColor(String color) {
               this.color = color;
               invalidate();
             }
           }
         

      • validate

        public void validate()
        Validate this component. This will tell the framework not to render the component the next time a response is sent to the server, even if if invalidate() had been called before.
      • printComponent

        protected abstract void printComponent(IlxWPort port)
                                        throws java.io.IOException
        Prints the HTML code that will display the graphical representation of this component. This method is called by the print(ilog.webui.dhtml.IlxWPort) method.
        Throws:
        IOException - if an error occurs while printing the components.
        java.io.IOException
        Parameters:
        port - The port on which the component will be printed.
        See Also:
        print(ilog.webui.dhtml.IlxWPort)
      • getRealHtmlTagName

        protected java.lang.String getRealHtmlTagName(IlxWPort port)
      • doPrint

        protected void doPrint(IlxWPort port)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • detach

        protected void detach()
      • firePropertyChange

        protected void firePropertyChange(java.lang.String propertyName,
                              java.lang.Object oldValue,
                              java.lang.Object newValue)
        Support for reporting property changes. If oldValue and newValue are not equal and the PropertyChangeEvent listener list isn't empty, then fire a PropertyChange event to each listener.
        Parameters:
        propertyName - The name of the property that was changed.
        oldValue - The old value of the property.
        newValue - The new value of the property.
        See Also:
        PropertyChangeSupport
      • addPropertyChangeListener

        public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
        Adds a PropertyChangeListener to the listener list.

        The listener is registered for all properties. A PropertyChangeEvent will get fired in response to setting a property.

        Parameters:
        listener - The PropertyChangeListener to be added.
      • addPropertyChangeListener

        public void addPropertyChangeListener(java.lang.String propertyName,
                                     java.beans.PropertyChangeListener listener)
        Adds a PropertyChangeListener for a specific property.

        The listener will be invoked only when a call on firePropertyChange names that specific property. If the listener is null, no exception is thrown and no action is performed.

        Parameters:
        propertyName - The name of the property to listen on.
        listener - The PropertyChangeListener to be added.
      • removePropertyChangeListener

        public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
        Removes a PropertyChangeListener from the listener list.

        This removes a PropertyChangeListener that was registered for all properties.

        Parameters:
        listener - The PropertyChangeListener to be removed.
      • removePropertyChangeListener

        public void removePropertyChangeListener(java.lang.String propertyName,
                                        java.beans.PropertyChangeListener listener)
        Removes a PropertyChangeListener for a specific property.

        If the listener is null, no exception is thrown and no action is performed.

        Parameters:
        propertyName - The name of the property that was listened on.
        listener - The PropertyChangeListener to be removed.
      • getStyle

        public IlxWComponent.DynamicStyleMap getStyle()
        Gets the dynamic style map of this component.

        Returns:
        The dynamic style map. Cannot be null.
      • notifyDependencies

        public void notifyDependencies(IlxWPort port)
        Specified by:
        notifyDependencies in interface ilog.webui.dhtml.IlxWDependencyProvider
        Overrides:
        notifyDependencies in class IlxWContainer

© Copyright IBM Corp. 1987, 2017