Dynamic URL’s depending on environment

Our project requires that we launch various URL’s in SubPages.

The development team develops on Local Hosts, then deploy to a Development Server, then an Acceptance Server and finally a Production Server. These URL’s are different between the various servers and also different on the Local Host.

How can we detect within our application on which server or local host it is executing?. We need to build the URL dynamically depending on the server or local host.

Any ideas on how we can do this

Hi Werner,

The preferred way is to use relative urls. If for some reason you need to use absolute urls, you can do the followin:

  1. In your first layout of the application add an adapter listener
  2. Add an XCIDATADEF control “mydata” to this layout. The XCIDATADEF is used to transport not rendered data to Natural.
  3. In the adapter listener, fill the “mydata” field with the hostname. Here are some code snippets:

public class MyAdapterListener implements IAdapterListener
    private Adapter m_adapter = null;
    public void init(Adapter adapter)
        m_adapter = adapter;
    public void reactOnDataTransferEnd()
       if ( m_adapter != null && m_adapter instanceof IDynamicAccess )
            HttpServletRequest request = m_adapter.findHttpServletRequest();
            String hostname = request.getLocalName();
            ((IDynamicAccess)m_adapter).setPropertyValue("mydata", hostname);                     
  1. The mydata-value can be accessed from within your Natural application in the usual way.

One question: At which places do you need absolute URLs?

Best Regards,