Getting a DIV's content and keeping page context
Yann Bizeul <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.devel |
|---|---|
| Message-ID | <[email protected]> |
I guess this is a traditionnal question about webobjects, but I did
not find an answer in the archives and AJAX frameworks I found are
poorly documented, since I am a beginner, I did not succeed to use them.
The problem is quite simple, I have a page containing :
- 1 WOPopUpButton with a list of 60+ countries
- 1 DIV containig WOTextFields with the address parts for the chosen
country (City, state, Zip, etc...)
This div is a WOComponent (AddressComponent) I call in my page, with
an "address" binding, according to the country set in the address, it
diplays the different field for that country.
The reason why I'm doing this is that I want to avoid reloading the
whole page, I want my site to be the very ergonomic, and I want to be
able to dynamically reload DIV containins dynamic WO elements.
When the page is initially requested, it embed the AddressComponent,
and everything works fine, I can submit the form and bindings are
fully functionnal.
Then I change the country, the changeCountry method is called (see
javascript attached at the end of the mail).
As you can see, I perform a GET request on the AddressComponent
directly, I think that is where I'm wrong, because doing this does
get AddressComponent as the root component where it was a
subcomponent before, the text field names are completely out of
context once the DIV is reloaded.
For example, this text field in the original page
<input size="15" type="text" name="7.6.1.4.0.CityComponent">
becomes :
<input size="15" type="text" name="1.4.0.CityComponent">
I hope things are a bit clearer and you will be able to help me :-)
<script type="text/javascript">
function changeAddressCountry(code)
{
http = getHTTPObject();
http.open("Get","<webobject name="ResourceURL1"></webobject>?
countryCode=" + code,false);
http.send(null);
if (http.status==200) {
var div_handle = document.getElementById("address");
if(div_handle){
div_handle.innerHTML =''+http.responseText;
alert(http.responseText);
}
}
}
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
</script>
Le 15 août 06 à 07:44, John Bruce a écrit :
> Can you let me know what the javascript is trying to do? Is it to edit
> the address in the particular format for that country?
>
> Depending on what you are trying to do it may be better to not use
> Javascript - either way it might be best to get it working using
> normal wo actions and then try to do it with javascript.
>
> -John
>
> On 8/15/06, Yann Bizeul <[email protected]> wrote:
>> Thanks to Miguel and John for their usefull answers.
>>
>> The result is I make a big red cross to my idee to programmatically
>> generate components :-)
>>
>> Using WOSwitchComponent, I'm almost successfull implementing exactly
>> what I want, but I have a problem with the dynamic part of the code
>> (the javascript that realods a DIC content).
>>
>> When my page is loaded, the components hierarchy is a full page with
>> my header, the global component, my address component, each field in
>> it, etc...
>>
>> But when I use Javascript to get a new form for the new address
>> format, it is completely out of the context, and for example, my City
>> text field that look like this in the code with the original
>> request :
>>
>> <input size="15" type="text" name="7.6.1.4.0.CityComponent">
>>
>> Become that after the DIV update :
>> <input size="15" type="text" name="1.4.0.CityComponent">
>>
>> As you can see, since the root component is itself, the identifiers
>> are wrong.
>>
>> How can I deal with that ?
>>
>>
>> Yann Bizeul • yann at tynsoe.org
>> Cocoa Developer
>>
>> Tynsoe Projects
>> BuddyPop • GeekTool • SSH Tunnel Manager • ...
>> http://projects.tynsoe.org/
>>
>>
>> _______________________________________________
>> WebObjects-dev mailing list
>> [email protected]
>> http://www.omnigroup.com/mailman/listinfo/webobjects-dev
>>