FAQ

Table of Contents:

  1. Q: How to execute arbitrary Javascript on the Client Side
  2. Q: How to trigger a Download
  3. Q: How do i get rid of the wingS default style for buttons?
  4. Q: For what do I need SDefaultBorder?
  5. Q: How do I get rid of the Nullpointer Exceptions during redeployment of my wingS application in Tomcat?
  6. Q: How to hide the browsers context menu for SPopupMenu?

Q: How to execute arbitrary Javascript on the Client Side

A:

hi dominique and benjamin,

even though our script manager is still quite rudimentary, it does in fact allow you to execute arbitrary javascript on the client side. in org.wings.plaf.css.script there are 2 simple classes dealing with this:

- OnPageRenderedScript
- OnHeadersLoadedScript

both of them implement the ScriptListener interface and can therefore be added to the script manager. scripts encapsulated in the first class get executed as soon as the page/dom is rendered/updated completely. scripts encapsulated in the second class get executed as soon as all js-headers have been loaded completely. so in your case something like this should work:


final StringBuffer script = new StringBuffer();
script.append("var x = window.open('http://www.google.de','my_window',")
       .append("'width=800,height=600,toolbar=0,menubar=0,location=0,")
       .append("status=1,resizable=1,scrollbars=1'); x.focus();");

final SButton open = new SButton("Open window!");
open.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent e) {
         ScriptManager.getInstance().addScriptListener(
             new OnPageRenderedScript(script.toString()));
     }
});
SForm formPanel = new SForm();
formPanel.add(open);


furthermore, such scripts are transient since they are evaluated within the window context and not bound to any dom element (unless your script does this binding manually). hence you don't have to "remove" anything here, just use the above code. whenever the button is clicked the script is sent to the client and evaluated there.

regards,
stephan

 




Q: How to trigger a Download

A:

Let's assume you want to integrate a feature into your wingS GUI that enables the user to download a file by clicking some GUI element. You have to find the corresonding event listener and its actionPerformed() method. Than you include the following code sample. It is executed every time the GUI event is triggered.

File file;
// insert code to create a file on-the-fly or fetch the handle for an existing one // existing files can be located in directories that can't be reached by the user via URL
FileResource resource = new FileResource(file);
resource.setExternalizerFlags(resource.getExternalizerFlags() | ExternalizeManager.REQUEST);

Map headers = new HashMap();
headers.put("Content-Disposition", "attachment; filename=" + file.getName());
resource.setHeaders(headers.entrySet());

final ScriptListener listener = new JavaScriptListener(null, null, "location.href='" + resource.getURL() + "'");SessionManager.getSession().getScriptManager().addScriptListener(listener);

Note, that you don't need to create a file at all, if you have the data in memory already. In this case choose another derivate of SResource or implement your own resource, that generates the content on the fly.




Q: How do i get rid of the wingS default style for buttons?

A:

Quick answer: Try button.setStyle(null).

Long answer: Overwrite/add a new CSS default style for buttons, wings 2 comes with a default CSS style sheet, which also styles the SButtons. Try the Web Developer Plugin, which is freely available for the FireFox browser, then you can live edit the style of the buttons.

To ignore the Styles for SButton elements you could simply a) overwrite and modify the .SButton CSS declarations or b) apply a different/no css class name to SButtons

On initialisation the current PLAF assign the component class name as CSS class name (So SButtons will render <button … class="SButton">). This default CSS styles are predefined in the default wings2 style.

You can either overwrite them by adding custom own styles, meaning registering a new CSS file as demonstrated in wingset demo or by applying antother/no style class to buttons.




Q: For what do I need SDefaultBorder?

A:

Every component has the SDefaultBorder by default. It is installed by the CG on initialization. If a component has the default border associated, its border styling is determined by the rules in the stylesheet. If the border property is set to null, the component will be rendered without a border, no matter if the stylesheet says something different. If a certain SBorder implementation is applied, it will override the stylesheet rules




Q: How do I get rid of the Nullpointer Exceptions during redeployment of my wingS application in Tomcat?

A:

Either retrieve the current CVS version or add the following statement to the webapp context:

<Context ...>
    <Manager className="org.apache.catalina.session.PersistentManager" 
         saveOnRestart="false"/>
</Context>

Tomcat will print following Output: No Store configured, persistence disabled

Here is the solution for Glassfish:

You must have an sun-web.xml configuration file into the WEB-INF folder of your .war application package configured in this way:

<sun-web-app>    
<session-config>
<session-manager>
<manager-properties>
<property name="sessionFilename" value="" />
</manager-properties>
</session-manager>
</session-config>
</sun-web-app>

More details on Jan Luehe's blog

Background: wingS dynamically tries to load and instantiate the PLAF (renderer) classes on session initialization and therefore consults the context class loader. If you stop your application Tomcat tries to serialized your session, hence the whole application state. If this failes (i.e. your classes are not fully serializable) the tomcat does not replace the classloader. So after refresh wingS only sees the outdated, old classlaoder which does no longer know the CG classes. We disabled the session serialization as a whole to avoid this in the future.




Q: How to hide the browsers context menu for SPopupMenu?

A:

If you use Firefox, make sure the option Preferences > Content > Enable Javascript > Advanced > Disable or replace context menus is checked, so that context menus are not hidden by the browsers default context menu.