Hi Martin, thanks.

I've already got a solution (from Igor's book mostly, but updated for 1.5)
on how to submit a form over https when the page hosting the form is http. I
was just looking for a way to determine the https port without hard-coding a
reference to WicketApplication. I guess it's not that bad, but was hoping to
get it from the RequestCycle or something. Since we can set the value via
setRootRequestMapper(), it seems like there ought to be a way to read it
back. Not a big deal really.

BTW the approach mentioned on the page you linked (extending a
StatelessForm, which I tried independently) didn't work for me. It's because
StatelessForm aborts if the protocol does not match, so your form just fails
to submit (Perhaps this is new behavior for 1.5?) If you extend a regular
Form but then override getStatelessHint() to return true, it works fine. 

Here's the Form code in case anyone else finds it useful.

public class HttpsForm<T> extends Form<T>
{
    public HttpsForm(String id)
    {
        super(id);
    }

    public HttpsForm(String id, IModel<T> tiModel)
    {
        super(id, tiModel);
    }

    @Override
    protected void onComponentTag(ComponentTag tag)
    {
        super.onComponentTag(tag);
        String action = tag.getAttribute("action");
        String absolute =
getRequestCycle().getUrlRenderer().renderFullUrl(Url.parse(action));
        absolute = absolute.replaceFirst("http://";, "https://";);
        absolute = absolute.replace(":" + getHttpPort(), ":" +
getHttpsPort());
        tag.put("action", absolute);
    }
    
    protected int getHttpPort()
    {
        //provide this method in your WicketApplication
        return ((WicketApplication) getApplication()).getHttpPort();
    }

    protected int getHttpsPort()
    {
        //provide this method in your WicketApplication
        return ((WicketApplication) getApplication()).getHttpsPort();
    }

}




--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/how-to-get-https-port-number-in-Wicket-1-5-tp4295139p4296821.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to