Class IlxWPort
- java.lang.Object
-
- ilog.webui.dhtml.IlxWPort
-
- All Implemented Interfaces:
- ilog.webui.dhtml.IlxWConstants
public class IlxWPort extends java.lang.Object implements ilog.webui.dhtml.IlxWConstants
IlxWPort
represents a port for printing web components to an HTML page.Overview
A port encapsulates the writer of the servlet response given in theIlxWPort
constructor.When you display components on an HTML page through an
IlxWPort
, component deployers must always call theopen()
method before printing any components, and theclose()
method after having printed all components they want to display on the page.Code example
The following code example shows how to do a print operation using a
IlxWPort
instance.public void doPrint(IlxWPort port,boolean readonly,HttpSession session, HttpServletResponse response, IlrBusinessRule element) throws Exception { port.open(); if (readonly) { IlrSession rtsSession = element.getSession(); String html = getHTMLDefinition(rtsSession,(IlrDecisionTable)element); port.getXmlWriter().print(html); } else { DTableEditor tableEditor = new DTableEditor(element.getSession(), session, (IlrDecisionTable)element); tableEditor.print(port); } port.close(); }
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.String
PARENT_WINDOW_NOT_IN_SAME_DOMAIN
-
Constructor Summary
Constructors Constructor and Description IlxWPort(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletOutputStream out)
Constructs a new port.IlxWPort(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.io.Writer out)
Constructs a new port.
-
Method Summary
Methods Modifier and Type Method and Description void
addDependency(ilog.webui.dhtml.IlxWDependencyProvider user, ilog.webui.dhtml.IlxWDependencyProvider used)
void
addUpdatingRequest(IlxWRequestDesc desc)
Adds an updating request descriptor to the manager's updating request list.void
close()
Ends printing to the port.void
closeForm()
Closes a form.java.lang.String
disableOnload(java.lang.String jsCode)
Gets the given Javascript code and wraps it in an if-then block which will execute the given code only if the page is not locked.void
generateIFrames(int portNumber)
java.lang.Object
getAttribute(java.lang.String string)
Returns the object bound with the specified name in this port, ornull
if no object is bound under that name.IlxWBrowserInfo
getBrowserInfo()
Gets the browser information object associated with this port.javax.servlet.ServletContext
getContext()
Gets the servlet context associated with this port.static IlxWPort
getCurrentPort()
Gets the current port.boolean
getEncloseInForm()
Gets theEncloseInForm
flag.java.lang.String
getFloatingWindowName()
javax.servlet.http.HttpServletRequest
getRequest()
Gets the servlet request associated with this port.javax.servlet.http.HttpServletResponse
getResponse()
Gets the servlet response associated with this port.java.lang.String
getServletPath()
Gets the path of the controller servlet on the server.java.lang.String
getViewServletPath()
java.io.PrintWriter
getWriter()
Gets the writer encapsulated by this port.protected void
initResponse()
Initializes the response.void
invalidatePage()
Invalidates the whole page.void
invokeLater(java.lang.Runnable doRun)
CausesdoRun.run()
to be executed asynchronously.boolean
isGenerateIFramesInClose()
void
open()
Opens the port.void
openForm()
Opens a form.void
setAttribute(java.lang.String string, java.lang.Object value)
Binds an object to this port, using the specified name.void
setEncloseInForm(boolean b)
Sets theEncloseInForm
flag.void
setFloatingWindowName(java.lang.String floatingWindowName)
void
setGenerateIFramesInClose(boolean flag)
-
-
-
Field Detail
-
PARENT_WINDOW_NOT_IN_SAME_DOMAIN
public static final java.lang.String PARENT_WINDOW_NOT_IN_SAME_DOMAIN
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
IlxWPort
public IlxWPort(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.io.Writer out)
Constructs a new port.- Since:
- JRules 3.5
- Parameters:
context
- The current servlet context.request
- The current request.response
- The current response.out
- The writer where the HTML page will be printed. Typically, this is either the writer given by the response passed in thedoGet/doPost
method of a servlet, or theout
variable of a JSP page.
-
IlxWPort
public IlxWPort(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletOutputStream out)
Constructs a new port.- Since:
- JRules 3.5
- Parameters:
context
- The current servlet context.request
- The current request.response
- The current response.out
- TheServletOutputStream
where the HTML page will be printed. Typically, this is either the stream given by the response passed in thedoGet/doPost
method of a servlet, or theout
variable of a JSP page.
-
-
Method Detail
-
setAttribute
public void setAttribute(java.lang.String string, java.lang.Object value)
Binds an object to this port, using the specified name. If an object of the same name is already bound to the container, the object is replaced.- Parameters:
string
- The name to which the object is bound; cannot benull
.value
- The object to be bound; cannot benull
.
-
getAttribute
public java.lang.Object getAttribute(java.lang.String string)
Returns the object bound with the specified name in this port, ornull
if no object is bound under that name.- Parameters:
string
- A string specifying the name of the object.- Returns:
- The object with the specified name.
-
getWriter
public java.io.PrintWriter getWriter()
Gets the writer encapsulated by this port.
This method encapsulates the writer passed to the port constructor. ThisPrintWriter
has itsautoflush
property set totrue
. Do not forget to call one of theprintln
method in order to flush the underlying buffer.- Throws:
- if the port has no output stream already set.IllegalStateException
- Returns:
- The writer encapsulated by this port.
- See Also:
PrintWriter
-
setGenerateIFramesInClose
public void setGenerateIFramesInClose(boolean flag)
-
isGenerateIFramesInClose
public boolean isGenerateIFramesInClose()
-
getBrowserInfo
public IlxWBrowserInfo getBrowserInfo()
Gets the browser information object associated with this port. This object is computed according to the request initially passed to the port constructor.
-
getServletPath
public java.lang.String getServletPath()
Gets the path of the controller servlet on the server.- Returns:
- The path of the controller servlet servlet.
- See Also:
IlxWController
-
getFloatingWindowName
public java.lang.String getFloatingWindowName()
-
setFloatingWindowName
public void setFloatingWindowName(java.lang.String floatingWindowName)
-
getViewServletPath
public java.lang.String getViewServletPath()
-
open
public void open() throws java.io.IOException
Opens the port. Component deployers must call this method before printing any components to the port. Calling this method generates a JavaScript code block on the current writer, which is used by the web components on the client side.- Throws:
- if an error occurs while printing to the current writer.IOException
java.io.IOException
- See Also:
close()
,IlxWComponent.print(ilog.webui.dhtml.IlxWPort)
-
addDependency
public void addDependency(ilog.webui.dhtml.IlxWDependencyProvider user, ilog.webui.dhtml.IlxWDependencyProvider used)
-
close
public void close() throws java.io.IOException
Ends printing to the port. Component deployers must call this method after having printed all components to the port. This method generates a JavaScript code block on the current writer, which is used by the web components on the client side.- Throws:
- if an error occurs while printing on the current writer.IOException
- if the port is not open.java.lang.IllegalStateException
java.io.IOException
- See Also:
open()
,IlxWComponent.print(ilog.webui.dhtml.IlxWPort)
-
generateIFrames
public void generateIFrames(int portNumber) throws java.io.IOException
- Throws:
java.io.IOException
-
getRequest
public javax.servlet.http.HttpServletRequest getRequest()
Gets the servlet request associated with this port. This is the request passed to the port constructor.- Returns:
- The servlet request associated with this port
-
getResponse
public javax.servlet.http.HttpServletResponse getResponse()
Gets the servlet response associated with this port. This is the response passed to the port constructor.- Returns:
- The servlet response associated with this port
-
getContext
public javax.servlet.ServletContext getContext()
Gets the servlet context associated with this port. This is the context passed to the port constructor.- Returns:
- The servlet context associated with this port.
-
initResponse
protected void initResponse()
Initializes the response. This method is called by theopen()
method and initializes the headers of the current response, asking the page not to be cached on the web browser and setting the content type of the page to text/html. Usually, you do not have to change this behavior. Nevertheless, if you wish to initialize headers in a different way, you may write your ownIlxWPort
class and redefine theinitResponse
method.
-
openForm
public void openForm() throws java.io.IOException
Opens a form. This will print an opening form tag on this port's writer. This may be useful if you wish to print some components using <input> tags (button, text field, text area, and so on).- Throws:
java.io.IOException
-
closeForm
public void closeForm() throws java.io.IOException
Closes a form.- Throws:
java.io.IOException
- See Also:
openForm()
-
getCurrentPort
public static IlxWPort getCurrentPort()
Gets the current port. This port is local to the current thread and should have been set by the framework as aThreadLocal
variable. This method is intended to be used in order to retrieve the current port in a context where the port is not directly accessible through the current scope (as a parameter of the current method, for instance). Under certain circumstances, you may need to retrieve the current port through this method.Suppose for instance you want to add a tree model listener (
javax.swing.tree.TreeModelListener
) on the tree component (ilog.webui.dhtml.components.IlxWTree
), and need the value of a request parameter in one of the listener method.
As the port is not directly accessible from thetreeXXX(TreeModel)
methods, you will have to retrieve the port withgetCurrentPort
. Here is the code you will typically write:class MyTreeModelListener implements TreeModelListener { public void treeNodesChanged(TreeModelEvent e) { IlxWPort port = IlxWPort.getCurrentPort(); if (port!=null) { String myParam = port.getRequest().getParameter("myParam"); System.err.println("myParam: "+myParam); ... } } }
When usingIlxWPort.getCurrentPort
you should always test if the returned port isnull
in case the current execution context is outside a web components request/response context.- Returns:
- the current port, if it exists. Otherwise returns
null
.
-
invalidatePage
public void invalidatePage()
Invalidates the whole page. On browsers supporting incremental update (IE5), it means that the page must be fully re-printed in the response, instead of only refreshing invalidated components.
On older browsers, this method has no effect, as the page is always re-printed by the framework.IMPLEMENTATION NOTE: Calling this method has the same effect than calling:
port.addUpdatingRequest(IlxWRequestDesc("myjsp.jsp", "_self"))
but this is much more efficient as the page is directly forwarded in the current response instead of being requested from the client.
-
addUpdatingRequest
public void addUpdatingRequest(IlxWRequestDesc desc)
Adds an updating request descriptor to the manager's updating request list. Typically, component deployers will add an updating request when working with multiple frames. In fact, it may happen that a component is modified on the server while a request is being processed but the request is not the one that will redisplay the modified component. Therefore, if the modified component belongs to another frame than the one used as the target of the the current send request, the component has no chance to be refreshed, unless you add an updating request to the manager.The updating request list is sent to the client the next time a port associated with the manager's session is closed (by @{link IlxWPort#close}): a JavaScript code block is appended to the end of the HTML page to ask the specified requests to be sent to the server. Once is has been printed, the updating request list is cleared.
- Parameters:
desc
- The request descriptor giving the path of the request to send and the name of the target frame where the response will be displayed.
-
setEncloseInForm
public void setEncloseInForm(boolean b)
Sets theEncloseInForm
flag. By default, this flag is true, meaning that theopen()
andclose()
methods respectively generate the <form> and </form> HTML tags.
Actually, most of the existing web components generate form elements (<input type="submit">, <input type="text">, etc.) Those form elements are not used by the framework as the parameters of a request sent by an enclosing form, but simply as gadgets whose interaction is managed by JavaScript handlers. However, with old generation browsers (for example, Netscape Navigator 3/4), an enclosing form tag is needed, otherwise those gadgets are not displayed at all on the browser.
This is the reason why, by default, a port encloses the printed components in a form tag (using theopenForm()
andcloseForm()
methods). However, in some cases, you may not want this HTML form to be printed. For instance, you may already have printed a<form>
opening tag in your HTML page and because nested forms are usually not supported by web browsers, you may experience some problems. In those cases, you must set theencloseInForm
flag tofalse
.- See Also:
open()
,close()
,openForm()
,closeForm()
-
getEncloseInForm
public boolean getEncloseInForm()
Gets theEncloseInForm
flag.- See Also:
setEncloseInForm(boolean)
-
invokeLater
public void invokeLater(java.lang.Runnable doRun)
CausesdoRun.run()
to be executed asynchronously. This will happen after all pending events of the current incoming request have been processed, and just before sending the response.
-
disableOnload
public java.lang.String disableOnload(java.lang.String jsCode)
Gets the given Javascript code and wraps it in an if-then block which will execute the given code only if the page is not locked. A page is considered as locked by the client-side of the web components framework, when a request has been sent to the controller and a response is waited.If, in the implementation of a web component proxy, you want to perform a client interaction which manipulates the client side of the framework, for instance call the JavaScript method IlxWPort.sendData() when a link is clicked, you should always protect your call with this method.
- Since:
- JRules 7.0
-
-