Wednesday, 28 September 2011

Tomcat remote debugging from eclipse

To enable debug on tomcat, set the following line in your catalina.bat

DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

From your eclipse, create a Run Configuration for 'Remote Java Application' on socket 8000 and restart tomcat.

Wednesday, 7 September 2011

Auto scan hibernate entity beans like component-scan for general spring components

Use the following configuration to auto scan your hibernate entity beans.

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

<property name="dataSource" ref="resourcesDataSource" />
<property name="packagesToScan">
<list>
<value>my.packages.hibernate.domain</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>

</property>
</bean>

Tuesday, 23 August 2011

Tomcat 6– Enable httpOnly and secure for jesssionid cookie

 

According to the release notes at http://tomcat.apache.org/tomcat-6.0-doc/changelog.html this looks to be implemented only from 6.0.33. Update your tomcat version before you try this configuration change.

Modify your context.xml under tomcat/conf directory by including this extra tag.

<Context>
<Manager useHttpOnly="true" />

</Context>

To make cookie secure, add the attribute secure="true" to the <Connector definition in server.xml

Friday, 19 August 2011

GWT/SmartGWT– Window popups with widgets

 

Recently I was implementing help infrastructure for our application. I wanted to have a help window open as a real popup and not a div popup that can hold smartgwt widgets to show help info.

There was no direct support for this in gwt or smartgwt however this can be achieved with a small hack.

Open a popup window by using the following JSNI script. This opens a new window popup with your own parameters and return the document from JSNI method. This gives you handle to popup’s document element.

private static native Document createWindowPopup() /*-{
        var win = window.open("", "win", "width=500,height=300,status=1,resizeable=1,scrollbars=1"); // a window object
        win.document.open("text/html", "replace");
        win.focus();
        return win.document;
    }-*/;

If you have handle to this document object you can simply add any widget to this document by

document.appendChild(myWidget.getElement());


Dont forget to close the document after writing to it.

private static native void closeDocument(Document document) /*-{
document.close();
}-*/;

Thursday, 18 August 2011

Smart GWT– Canvas hiding other elements underneath it

Recently when I used Canvas to hold a popup positioned somewhere in the middle, the Canvas was starting from the top left corner of the screen and hiding other elements underneath it. It was really difficult to find how I can position Canvas so that it occupies just the widgets space and not any extra space.

This can be achieved using Canvas.setRect(left, top, width, height);

Friday, 12 August 2011

SmartGwt: Absolute position your widget with setSnapTo

 

If you like to absolute position your widget in smartgwt use setSnapTo

Usage:

widget.setSnapTo(“TL”);
widget.setSnapOffsetLeft(400);
widget.setSnapOffsetTop(200);


If you like to reset this behaviour, use setSnapTo(null) that will reset to its original state. This is particularly useful if you like to popoup one of your widgets and position them absolutely and reset back again

Friday, 5 August 2011

uibinding-smartgwt : compiler errors while doing gwt compile

I see the following exceptions on console while doing a gwt compile on my project. I am using 1.0 version of uibinding-smartgwt from their website

[INFO] Validating newly compiled units
[INFO] [ERROR] Errors in 'jar:file:/C:/Users/ssajddlo/.m2/repository/uibinding-smartgwt/uibinding-smartgwt/1.0/uibinding-smartgwt-1.0.jar!/org/synthful/smartgwt/client/widgets/UIDataSource.java'
[INFO] [ERROR] Line 390: The method setServerConstructor(String) is undefined for the type DataSource
[INFO] [ERROR] Line 394: The method getServerConstructor() is undefined for the type DataSource
[INFO] [ERROR] Errors in 'jar:file:/C:/Users/ssajddlo/.m2/repository/uibinding-smartgwt/uibinding-smartgwt/1.0/uibinding-smartgwt-1.0.jar!/org/synthful/smartgwt/client/widgets/UIDataSourceField.java'
[INFO] [ERROR] Line 367: The method setMaxFileSize(Integer) is undefined for the type DataSourceField
[INFO] [ERROR] Line 371: The method getMaxFileSize() is undefined for the type DataSourceField
[INFO] [ERROR] Line 431: The method setStoreWithHash(HashAlgorithm) is undefined for the type DataSourceField
[INFO] [ERROR] Line 435: The method getStoreWithHash() is undefined for the type DataSourceField
[INFO] [ERROR] Errors in 'jar:file:/C:/Users/ssajddlo/.m2/repository/uibinding-smartgwt/uibinding-smartgwt/1.0/uibinding-smartgwt-1.0.jar!/org/synthful/smartgwt/client/widgets/UIDataSource.java'
[INFO] [ERROR] Line 390: The method setServerConstructor(String) is undefined for the type DataSource
[INFO] [ERROR] Line 394: The method getServerConstructor() is undefined for the type DataSource
[INFO] [ERROR] Errors in 'jar:file:/C:/Users/ssajddlo/.m2/repository/uibinding-smartgwt/uibinding-smartgwt/1.0/uibinding-smartgwt-1.0.jar!/org/synthful/smartgwt/client/widgets/UIDataSourceField.java'
[INFO] [ERROR] Line 367: The method setMaxFileSize(Integer) is undefined for the type DataSourceField
[INFO] [ERROR] Line 371: The method getMaxFileSize() is undefined for the type DataSourceField
[INFO] [ERROR] Line 431: The method setStoreWithHash(HashAlgorithm) is undefined for the type DataSourceField
[INFO] [ERROR] Line 435: The method getStoreWithHash() is undefined for the type DataSourceField
[INFO] [ERROR] Cannot proceed due to previous errors


Resolution:
To fix this issue, checkout the project code from svn, rebuild and update the new 1.0.1 version of the created jar file. The issues are resolved in latest svn but the jar is not published.

Thursday, 4 August 2011

SmartGwt - Make TextAreaItem readonly

The readonly attribute is not supported on TextAreaItem. Instead there are a couple of methods setDisabled(true) and setShowDisabled(false) that help disable the TextAreaItem.

But the entire TextAreaItem will be disabled and made unselectable if you set these. What if we like to retain the selectable behaviour of TextAreaItem acting truly as a readonly element and not a disabled element?

Use the following code to make TextAreaItem readonly

myTextArea.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
event.cancel();
cursorPos = myTextArea.getSelectionRange()[0];
}
});

myTextArea.addChangedHandler(new ChangedHandler() {

@Override
public void onChanged(ChangedEvent event) {
myTextArea.setSelectionRange(cursorPos, cursorPos);
}
});

The first handler makes textarea ignore any change events. But the side affect is the cursor position gets automatically changed and moves to end of text are which causes flickering and scrolling on textarea. To avoid this, attach addChangedHandler that gets called after the textarea is changed that could retain your cursor position back.

+1 if this is helpful.

Wednesday, 3 August 2011

smartgwt - set TextAreaItem width to 100%

Even if I set the width of TextAreaItem to * or 100% or in px it doesn't occupy the entire width of form.

To make it occupy the entire width ensure setNoCols(1) to 1 to make the textarea occupy the entire width of form

smartgwt - align buttons to right using HLayout

I was wondering why the buttons were not aligned to right when I did myHLayout.setAlign(Alignment.RIGHT).

The usage is incorrect, try myHLayout.setLayoutAlign(Alignment.RIGHT) instead.

Friday, 29 July 2011

GWT code generator - For the following type(s), generated source was never committed (did you forget to call commit()?)

For the following type(s), generated source was never committed (did you forget to call commit()?)


When you encounter this issue while implementing a code generator in GWT using ClassSourceFileComposerFactory, ensure you are calling writer.commit(logger). If this is not you are missing, make sure you are passing context to composer.createSourceWriter(context, printWriter);

There are lot of examples out there on code generators that doesn't show context being passed. Without context, your writer doesn't commit your source generation changes.

Friday, 15 July 2011

Shared connection pool between multiple webapps of tomcat

For configuring a container managed connection pool you define a resource in context.xml as

<ResourceLink
name="jdbc/myoracle"
global="shared/jdbc/myoracle"
type="javax.sql.DataSource"
factory="org.apache.naming.factory.DataSourceLinkFactory"
username="username"
password="password" />

and do a JNDI lookup to access the resource and get a db connection. Even though the connection pool is maintained by the container, it creates a pool for every webapp on tomcat and doesn't really share the pool between webapps. This usually causes your environments use up too many connections and result in session unavailable exceptions.

To make your webapps use a truely sharable connection pool across all webapps on the container, use the following configuration

1. Remove any definition you have from context.xml (These configuration files are usually found on tomcat_home/conf)
2. Move this definition to server.xml and copy under as

<GlobalNamingResources>
<Resource auth="Container" driverClassName="oracle.jdbc.OracleDriver"
maxActive="2" maxIdle="1" maxWait="-1"
name="shared/jdbc/myoracle" password="password"
type="javax.sql.DataSource" url="jdbc:oracle:thin:@server:1521:XE" username="username"/>
</GlobalNamingResources>

3. Link this resource to your webapplication context by copying the below xml under element

<ResourceLink
name="jdbc/myoracle"
global="shared/jdbc/myoracle"
type="javax.sql.DataSource"
factory="org.apache.naming.factory.DataSourceLinkFactory"
username="username"
password="password" />
4. Restart tomcat
5. Look into your database administration console to verify the connections you are holding.

Now, all your web application contexts link to just a global truely shared connection pool and use less connections.

Tuesday, 12 July 2011

What are the default or test credentials for jasig CAS (Central Authentication Service)

CAS uses SimpleTestUsernamePasswordAuthenticationHandler by default. The only rule for a successful authentication is username and password should match. (eg., tiger/tiger)

Monday, 11 July 2011

GWT ClassFormatError

Ensure your accessor methods (getters) are all final in the corresponding class. This occurred to me when one of my getter methods was non-final