Decision Center API

ilog.webui.dhtml
Class IlxWComponent

java.lang.Object
  extended by ilog.webui.dhtml.IlxWContainer
      extended by ilog.webui.dhtml.IlxWComponent
All Implemented Interfaces:
ilog.webui.dhtml.IlxWConstants, ilog.webui.dhtml.IlxWCSSModelProvider, ilog.webui.dhtml.IlxWDependencyProvider, ilog.webui.dhtml.IlxWJSObject, 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:

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

Nested Class Summary
 class IlxWComponent.DynamicStyleMap
          Dynamic style map.
 
Field Summary
 
Fields inherited from class ilog.webui.dhtml.IlxWContainer
listenerList
 
Constructor Summary
IlxWComponent()
          Constructs a new web component.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Adds a PropertyChangeListener for a specific property.
protected  void detach()
           
protected  void doPrint(IlxWPort port)
           
 void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
          Reports a bound property change.
protected  void firePropertyChange(String propertyName, Object oldValue, Object newValue)
          Support for reporting property changes.
 String getName()
          Gets the name of this component.
protected  String getRealHtmlTagName(IlxWPort port)
           
 IlxWComponent.DynamicStyleMap getStyle()
          Gets the dynamic style map of this component.
 void invalidate()
          Invalidates this component so that its print method is called as soon as possible.
 boolean isInvalidated()
          Tells whether the invalidate method has been called since the last time this component has been printed in a port.
 void notifyDependencies(IlxWPort port)
           
 void print(IlxWPort port)
          Prints the component to the given port.
protected abstract  void printComponent(IlxWPort port)
          Prints the HTML code that will display the graphical representation of this component.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Removes a PropertyChangeListener for a specific property.
 void setName(String name)
          Sets the name of this component.
 void validate()
          Validate this component.
 
Methods inherited from class ilog.webui.dhtml.IlxWContainer
add, add, getAttribute, getAttributeNames, getComponent, getComponentCount, getComponentNamed, getComponents, getManager, getParent, getUserAgentRules, indexOf, isAncestorOf, remove, remove, removeAll, removeAttribute, setAttribute, setAuthorRules, setFinalizer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlxWComponent

public IlxWComponent()
Constructs a new web component.

Method Detail

getName

public String getName()
Gets the name of this component.

See Also:
setName(java.lang.String)

setName

public void setName(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();
     }
   }
 


isInvalidated

public boolean isInvalidated()
Tells whether the invalidate method has been called since the last time this component has been printed in a port.

See Also:
invalidate(), print(ilog.webui.dhtml.IlxWPort)

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 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.
IOException
Parameters:
port - The port on which the component will be printed.
See Also:
print(ilog.webui.dhtml.IlxWPort)

print

public final void print(IlxWPort port)
                 throws IOException
Prints the component to the given port. This methods calls the printComponent(ilog.webui.dhtml.IlxWPort) method.

Throws:
IOException - if an error occurs while printing the component.
IllegalStateException - if the given port is not open.
IOException
See Also:
printComponent(ilog.webui.dhtml.IlxWPort)

getRealHtmlTagName

protected String getRealHtmlTagName(IlxWPort port)

doPrint

protected void doPrint(IlxWPort port)
                throws IOException
Throws:
IOException

detach

protected void detach()

firePropertyChange

protected void firePropertyChange(String propertyName,
                                  Object oldValue,
                                  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

firePropertyChange

public void firePropertyChange(String propertyName,
                               boolean oldValue,
                               boolean newValue)
Reports a bound property change.

See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

addPropertyChangeListener

public void addPropertyChangeListener(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(String propertyName,
                                      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(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(String propertyName,
                                         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

Decision Center API

© Copyright IBM Corp. 1987, 2013