Problem with Application getInitParameter()

2008-12-05 Thread Tauren Mills
Maybe I'm going nuts, but I can't figure out what is wrong.  It seems so
simple, but it isn't working.  I call getInitParameter in my application
twice.  One time it returns a value, the other it gets a null.  And the
correct xml is there in web.xml.

First, here is the pertinent application code (I've trimmed out unimportant
stuff):

public class DynamicApplication extends WicketeerBaseApplication {

private MerchantInfo merchantInfo;
private String siteBaseUrl;

public MerchantInfo getMerchantInfo() {
return merchantInfo;
}
public void setMerchantInfo(MerchantInfo merchantInfo) {
this.merchantInfo = merchantInfo;
}
public String getSiteBaseUrl() {
return siteBaseUrl;
}
public void setSiteBaseUrl(String siteBaseUrl) {
this.siteBaseUrl = siteBaseUrl;
}

@Override
protected void init() {
super.init();
this.siteBaseUrl = getInitParameter(site-base-url);
this.merchantInfo =
GoogleOrderService.loadMerchantInfo(getServletContext(),getInitParameter(checkout-config-file));
}
}

Now here are the pertinent parts from web.xml:

!-- Base URL of the website.  Used in linkbacks from google checkout.
--
context-param
param-namesite-base-url/param-name
param-valuehttp://localhost:8080//param-value
/context-param

!-- location of configuration file for google checkout with respect to
context
 root. Using the default path here. --
context-param
param-namecheckout-config-file/param-name
param-value/WEB-INF/checkout-config.xml/param-value
/context-param

So, when the application init() runs, merchantInfo gets properly populated
with the correct MerchantInfo instance based on the contents of
checkout-config.xml.  So the init param name and value were read correctly.

But, then when I try to just get a simple string value for site-base-url, I
get back a null.  I've looked for typos, tried retyping the web.xml section,
swapping the order of getInitParam in init(), restarting... all sorts of
stuff.  It just always gets null.

Any possible thoughts on what might cause this?  Using wicket-1.3.3.
Pulling my hair out.  Maybe its just late and I need to sleep.

Is there a better way to get the server name so I don't even need to hard
code it?  urlFor() only gives back the path, not the server.

Thanks,
Tauren


Re: Problem with Application getInitParameter()

2008-12-05 Thread Nav Che
Maybe you want to try this :


((WebRequest)getRequestCycle().getRequest()).getHttpServletRequest().getServerName()

//Naveen
On Fri, Dec 5, 2008 at 6:58 AM, Tauren Mills [EMAIL PROTECTED] wrote:

 Maybe I'm going nuts, but I can't figure out what is wrong.  It seems so
 simple, but it isn't working.  I call getInitParameter in my application
 twice.  One time it returns a value, the other it gets a null.  And the
 correct xml is there in web.xml.

 First, here is the pertinent application code (I've trimmed out unimportant
 stuff):

 public class DynamicApplication extends WicketeerBaseApplication {

private MerchantInfo merchantInfo;
private String siteBaseUrl;

public MerchantInfo getMerchantInfo() {
return merchantInfo;
}
public void setMerchantInfo(MerchantInfo merchantInfo) {
this.merchantInfo = merchantInfo;
}
public String getSiteBaseUrl() {
return siteBaseUrl;
}
public void setSiteBaseUrl(String siteBaseUrl) {
this.siteBaseUrl = siteBaseUrl;
}

@Override
protected void init() {
super.init();
this.siteBaseUrl = getInitParameter(site-base-url);
this.merchantInfo =

 GoogleOrderService.loadMerchantInfo(getServletContext(),getInitParameter(checkout-config-file));
}
 }

 Now here are the pertinent parts from web.xml:

!-- Base URL of the website.  Used in linkbacks from google checkout.
 --
context-param
param-namesite-base-url/param-name
param-valuehttp://localhost:8080//param-value
/context-param

!-- location of configuration file for google checkout with respect to
 context
 root. Using the default path here. --
context-param
param-namecheckout-config-file/param-name
param-value/WEB-INF/checkout-config.xml/param-value
/context-param

 So, when the application init() runs, merchantInfo gets properly populated
 with the correct MerchantInfo instance based on the contents of
 checkout-config.xml.  So the init param name and value were read correctly.

 But, then when I try to just get a simple string value for site-base-url, I
 get back a null.  I've looked for typos, tried retyping the web.xml
 section,
 swapping the order of getInitParam in init(), restarting... all sorts of
 stuff.  It just always gets null.

 Any possible thoughts on what might cause this?  Using wicket-1.3.3.
 Pulling my hair out.  Maybe its just late and I need to sleep.

 Is there a better way to get the server name so I don't even need to hard
 code it?  urlFor() only gives back the path, not the server.

 Thanks,
 Tauren