Trying to avoid reinventing the wheel here. I have a Google Web Toolkit page that I’m about to deploy, but the web service I'm talking to will have a different relative address on the deployed server than my local test machine.
So I'm looking for an easy way to deploy with some kind of easily editable configuration file that I can put on basic server-side settings. I have a couple of ideas on how to do this, but they seem somewhat hacked, and it seems to me that there should be a solution to this problem (in the end, the settings for each server are VERY common thing!)
Any ideas?
Edit: Since this does not seem to attract much attention, let me outline my initial thoughts: Keep a static file local to the GWT files that I request with an AJAX call, before any other logic. When the file is returned, I look through my data and save it as globally accessible vars, and then enable the page construction logic. It seems awkward, and there is a big drawback in waiting for AJAX to return before any download, but it will work. Any best deals? (You are welcome?)
My solution: I found the solution myself, but it is quite specific for my exact scenario, so I don’t know how useful it is for the average user. I will post it here anyway if someone finds this useful.
The page I'm working on is actually a GWT control built into ASP.net. Using this and opening the GWT Dictionary class, I put together a “settings” system, for example:
First, the setup I want (in this case, the address for the web service) is set in the ASP.net Web.Config file
<appSettings> <add key="serviceUrl" value="http://mySite.com/myService.asmx"/> </appSettings>
On the ASP page that embeds the GWT control, I add a “static” javascript object that contains the configuration settings that I need:
<head runat="server"> <title>Picklist Manager</title> <script type="text/javascript" language="javascript"> var AppConfig = { serviceUrl: "<%= ConfigurationManager.AppSettings["serviceUrl"] %>" }; </script> <script type="text/javascript" language="javascript" src="gwtcontrol.nocache.js"></script> </head>
Finally, in GWT, I create a static class "AppConfig" that provides this option:
public class AppConfig { public static String serviceUrl = "defaultUrl"; public static void Initialize() { Dictionary appConfig = Dictionary.getDictionary("AppConfig"); if(appConfig == null) { return; } servicePath = appConfig.get("serviceUrl"); } }
From there, I can call AppConfig.serviceUrl anywhere in my code to get the setting ... whew! So yes, this is a good long hard way to get around this, but it works for me. Of the answers given to Alexander, it seems most important what I was looking for, so generosity goes to him, but thanks to everyone who broke my sticky little problem!