Showing posts with label webobjects. Show all posts
Showing posts with label webobjects. Show all posts

26 March 2009

WebObjects application launching as MainBundle.woa

For some unknown reason a couple of WebObjects applications were not not launching as the APPLICATION_NAME.woa but as MainBundle.woa and totally unusable as such.

When launching from Eclipse I got an error on locating Info.plist in JavaDTWGeneration.framework, JavaEOGeneration.framework and JavaEOProject.framework that was causing the problem.

Reinstalled Webobjects 5.4.3 and everything when back to normal.

01 July 2008

NSArray sorting

Don't forget the little magic in

EOSortOrdering.sortedArrayUsingKeyOrderArray( form.elements(), new NSArray( ERXS.asc( Element.ORDER_KEY ) ) );

27 March 2008

The caret synbol( ^ ) in bindings

The caret symbol( ^ ) indicates that the value should be taken from the parent component.

11 March 2008

Getting resources from Unit Tests

Since Unit Tests are run from the command line( or Ant ) access to Resources of a WebObjects project are no good with ResourceManager. Simple functions to get resources based on the filesystem:


/**
* Returns a path to a resource filename in a folder(s) under the root folder
* */
private String resourceLocationString( String filename, String folder ) {
String urlToFile = getClass().getResource( "/" ).toString();
urlToFile = urlToFile.replace( "bin/", "" );
urlToFile = urlToFile.replace( "file:", "" ); // now we should be at the projects root directory
urlToFile = urlToFile.concat( folder + "/" + filename );
return urlToFile;
}

/**
* Returns data for pdf file
* */
private byte[] bytesForPDFResource( String urlToFile ) throws FileNotFoundException, IOException {
FileInputStream in = new FileInputStream( urlToFile );
byte[] data = new byte[in.available()];
in.read(data);
return data;
}

18 January 2008

Executing SQL

Need to call simple SQL commands, like getting the next primary key by calling a sequence:


NSArray rawRows = EOUtilities.rawRowsForSQL( EDITING_CONTEXT, MODEL_NAME, SQL_STRING, NSArray.EmptyArray );
NSDictionary rowWithPK = (NSDictionary)rawRows.objectAtIndex( 0);
Object maxPK = rowWithPK.objectForKey( "NR" );

22 November 2007

Symbolic link

Keep forgetting how to add a framework:

cd /Libarary/Frameworks

Then add your framework like this example with EkjaFramework in my Developer workspace:
ln -s /Developer/workspace/EkjaFramework/dist/EkjaFramework.framework/ EkjaFramework.framework

15 November 2007

WOCheckBox binding

Keep forgettins it's the cheked binding to use, not value or selection.

18 October 2007

SQL Server 2000 IDENTITY_INSERT

SQL Server has got identity for primary keys( see this article ) that was preventing me from inserting into a table with EO.

To get by this you can just set the identity insert to on with:

EOUtilities.rawRowsForSQL( ec, modleName, "SET IDENTITY_INSERT tableName ON", NSArray.EmptyArray );

Note that you might need to get the new primary key( identity ) yourself, ex.:

NSArray rawRows = EOUtilities.rawRowsForSQL( ec, modleName, "SELECT MAX(idenityColumnName) as NR FROM tableName", NSArray.EmptyArray );
NSDictionary rowWithPK = (NSDictionary)rawRows.objectAtIndex(0);
Object maxPK = rowWithPK.objectForKey("NR");
int primaryKey = (new Integer(maxPK.toString())).intValue();

02 October 2007

Disable the WebServicesAssistant at launch

Add the following parameter into the WO launch configuration:

-WSAssistantEnabled=false

Add this to your default WOApplication launch preferences

27 September 2007

Fetching raw rows

setFetchesRawRows( true ); must be set before setRawRowKeyPaths

WOImage with data binding

A WOImage with data bound to NSData( read from DB ) was not showing up on print.
Binding the "key" to a unique identifier for every image did the trick.
Hugi pointed this out to me, he had run into it some years ago, seems the NSData is only kept for a short period of time in the cache and setting the key will extend it's lifetime there.

20 September 2007

Unique ID for element

When working with JavaScript I often need a unique ID for the current component I'm woking with:


ERXStringUtilities.replaceStringByStringInString( ".", "_", context().elementID().toString() );

Get previous page name

I wanted to enable the user to go back to the previous page without using a WOActionResults to set the name of the component calling the nextPage. WOContext has a method called page that did this for me with ease ;)


String previousPage = context().page().name();

19 September 2007

SQL output from WO

-EOAdaptorDebugEnabled YES

new WOComponent instance

Need to create a wocomponent instance in java, you'll need : Application.application().createContextForRequest( new WORequest( "GET", "", "HTTP/ 1.0", null, null, null) ) to create the request

WOFileUpload

Created a WOFileUpload and connected the inputStream attribute to an input stream but nothing worked, kept getting a NP untill I connected FilePath to a String variable, then the WOFileUpload worked like charm( annoying charm that took too much of my time to figure out ).

Overwriting valueForKeyPath

I need to access a localalized strings file for the right language and I don't like the Localizer method.
I wanted to access it through Application and in the WOD files by simply adding "application.@ls.MY_STRING_TO_GET_FROM_LOCALIZED_STRING".

Added the following to Application.java:


  public Object valueForKeyPath( String keypath ) {

// Catch all keypaths starting with ls and do whatever you want with it
        if( keypath.startsWith( "@ls" ) )
            return localizedStringForKey( keypath.substring( 4, keypath.length() ) );

        return super.valueForKeyPath( keypath );
    }

    public String localizedStringForKey( String key ) {
        return WOApplication.application().resourceManager().stringForKey( key, "localizedStrings", "!!LOCALIZED_STRING_NOT_FOUND!!", "app", languages() );
    }