Programmatically instantiating WOComponents

Yann Bizeul <[email protected]>
Newsgroups gmane.comp.web.webobjects.devel
Message-ID <[email protected]>
Hello list, please welcome the WONewbie that I am !

I'm starting a new web application using WO because tired of  
reinventing the wheel with each line of PHP, and I really love what I  
see of WO.
But since I'm trying to do things that are beyond my knowledge, and  
that I think this is the better way to learn, I would need your help :-)

Here is the situation :

I made a WOComponent "AddressComponent" to display to the user text  
fields to type a postal address.
The content of this component should be dynamic, and programmatically  
generated, because there is a "country" menu that, when changed,  
reload the DIV where is loaded the form to make it suit different  
localization.

For example, a US address should have a state field, and a french  
address should not.

Basically, here is the way I'm trying to implement this in  
AddressComponent.java :

=== MY CODE ===
	public void appendToResponse(WOResponse aResponse,WOContext aContext)
	{
[...]
		// Using a format string parsed above, get the name of the  
component to add (CityComponent, StreetComponent, ...)
		// There is just a single WOTextField in this component, bound to  
their "address" instance variable
		String componentName = token.substring(0,1).toUpperCase() +  
token.substring(1,token.length()).toLowerCase() + "Component";

		// Get the component
		AbstractAddressComponent component = (AbstractAddressComponent) 
pageWithName(componentName);

		// Set the address and add it to the response
		component.setValueForBinding(address,"address");
		component.appendToResponse(aResponse,aContext);
[...]
		super.appendToResponse(aResponse,aContext);
	}
===============

Visually, it seem to work fine when I load the page, the bindings  
seem to be there because the chosen country is well reflected in the  
displayed form. Even the dynamic update of the address div seem to  
work fine, which is implemented by this excerpt of the code that set  
the result as my DIV's innerHTML:

=== JAVASCRIPT CODE ===
http = getHTTPObject();
http.open("Get","<webobject name="ResourceURL1"></webobject>? 
countryCode=" + code + "&idLocation=" + "<webobject name="String1"></ 
webobject>",false);
===== HTML OUTPUT =====
http = getHTTPObject();
http.open("Get","/cgi-bin/WebObjects/MyApp.woa/wo/ 
xpv37pbTrSRWvRhOjU1weg/2.3?countryCode=" + code,false);
=======================

The problem is that everything in the address is null when I submit  
the form the rest of the form is OK). Obviously, there is something  
wrong with the HTML code generated, every field has the same name and  
an identifier missing (since I have a subcomponent, it should be  
7.6.x, with x incrementing, this is my understanding of the situation):

=== HTML OUTPUT ===
<input size="30" type="text" name="7.6"><br>
<input size="7" type="text" name="7.6"> <input size="15" type="text"  
name="7.6"><br>
<input size="4" type="text" name="7.6"><br>
===================

So I guess I'm doing this the wrong way, and would need some advice.  
I found no sample of programmatically instanciated WOComponent.

By advance, thanks for your help

Yann Bizeul • yann at tynsoe.org
Cocoa Developer

Tynsoe Projects
BuddyPop • GeekTool • SSH Tunnel Manager • ...
http://projects.tynsoe.org/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.