I found a bug in Wicket's handling of newConversionException(). Here's my updated source-code:


/*
 * Page.java
 *
 * Created on March 10, 2005, 5:23 PM
 */

package com.be.desktopbeautifier.web.mailinglist;

import java.util.Date;
import java.util.Locale;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServletRequest;
import wicket.IFeedback;
import wicket.markup.html.WebPage;
import wicket.markup.html.form.Button;
import wicket.markup.html.form.Form;
import wicket.markup.html.form.RequiredTextField;
import wicket.markup.html.link.PageLink;
import wicket.markup.html.panel.FeedbackPanel;
import wicket.markup.html.panel.Panel;
import wicket.model.BoundCompoundPropertyModel;
import wicket.model.CompoundPropertyModel;
import wicket.model.Model;
import wicket.protocol.http.WebRequest;
import wicket.util.convert.ConversionException;
import wicket.util.convert.Converter;
import wicket.util.convert.converters.AbstractConverter;

/**
* Mailing list page.
*
* @author Gili Tzabari
*/
public class Page extends WebPage
{
/**
* Creates a new instance of Page.
*/
public Page()
{
Model applicationModel = new Model()
{
public Object getObject(wicket.Component component)
{
return getApplication();
}
};
HttpServletRequest request = ((WebRequest) getRequest()).getHttpServletRequest();
String userAgent = request.getHeader("User-Agent");
int ua = userAgent.indexOf("MSIE ");
Panel browserCSS;
if (ua==-1)
browserCSS = new CSS2("browserSpecificCSS");
else
browserCSS = new IExplorerCSS("browserSpecificCSS");
add(browserCSS);


PageLink download = new PageLink("download", com.be.desktopbeautifier.web.mailinglist.Page.class);
add(download);


    FeedbackPanel status = new FeedbackPanel("status");
    add(status);

    Form form = new SubscriptionForm("form", status);
    add(form);
  }

  private class InternetAddressConverter extends AbstractConverter
  {
    protected Class getTargetType()
    {
      return InternetAddress.class;
    }

public Object convert(Object value, Locale locale)
{
try
{
InternetAddress result = new InternetAddress((String) value);
result.validate();
return result;
}
catch (AddressException e)
{
throw newConversionException("'" + value + "' is not a valid address", value, null);
}
}
};


  private class SubscriptionForm extends Form
  {
    public SubscriptionForm(String name, IFeedback feedback)
    {
      super(name, feedback);

BoundCompoundPropertyModel model = new BoundCompoundPropertyModel(new SubscriptionModel());
setModel(model);


Converter converter = (Converter) getConverter();
converter.set(InternetAddress.class, new InternetAddressConverter());
RequiredTextField email = new RequiredTextField("email", InternetAddress.class);
add(email);


      model.bind(email, InternetAddress.class);
      add(new Button("submit"));
    }

    public void onSubmit()
    {
      try
      {
        Properties props = System.getProperties();
        props.put("mail.smtp.host", "desktopbeautifier.com");
        Session session = Session.getDefaultInstance(props, null);

Message msg = new MimeMessage(session);
CompoundPropertyModel compoundModel = (CompoundPropertyModel) getModel();
SubscriptionModel model = (SubscriptionModel) compoundModel.getNestedModel();
msg.setFrom(model.getEmail());
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[EMAIL PROTECTED]"));


        msg.setSubject("subscribe [EMAIL PROTECTED]");
        msg.setSentDate(new Date());
        msg.setText("");
        Transport.send(msg);
      }
      catch (AddressException e)
      {
        throw new IllegalStateException(e);
      }
      catch (MessagingException e)
      {
        throw new IllegalStateException(e);
      }
      setResponsePage(new com.be.desktopbeautifier.web.main.Page());
    }
  }

  private class SubscriptionModel
  {
    private InternetAddress email;

    public void setEmail(InternetAddress value)
    {
      email = value;
    }

    public InternetAddress getEmail()
    {
      return email;
    }
  }
}

        Now, if you enter "blah" as the email address, this code will execute:

throw newConversionException("'" + value + "' is not a valid address", value, null);

        the problem is that Wicket then dies with:

wicket.WicketRuntimeException: Method public abstract void wicket.markup.html.form.IFormSubmitListener.onFormSubmitted() of interface IFormSubmitListener threw an exception
at wicket.protocol.http.WebRequestCycle.invokeInterface(WebRequestCycle.java:297)
at wicket.protocol.http.WebRequestCycle.invokeInterface(WebRequestCycle.java:322)
at wicket.protocol.http.WebRequestCycle.callComponentListener(WebRequestCycle.java:235)
at wicket.protocol.http.WebRequestCycle.parseRequest(WebRequestCycle.java:118)
at wicket.RequestCycle.request(RequestCycle.java:361)
at wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:165)
at wicket.protocol.http.WicketServlet.doPost(WicketServlet.java:189)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at wicket.protocol.http.WebRequestCycle.invokeInterface(WebRequestCycle.java:288)
... 22 more
Caused by: java.util.MissingResourceException: Unable to find resource: form.email.TypeValidator
at wicket.Localizer.getString(Localizer.java:147)
at wicket.Localizer.getString(Localizer.java:88)
at wicket.markup.html.form.validation.AbstractValidator.error(AbstractValidator.java:90)
at wicket.markup.html.form.validation.AbstractValidator.error(AbstractValidator.java:117)
at wicket.markup.html.form.validation.TypeValidator.onValidate(TypeValidator.java:107)
at wicket.markup.html.form.validation.StringValidator.onValidate(StringValidator.java:33)
at wicket.markup.html.form.validation.AbstractValidator.validate(AbstractValidator.java:150)
at wicket.markup.html.form.FormComponent$ValidatorList.validate(FormComponent.java:153)
at wicket.markup.html.form.FormComponent.validate(FormComponent.java:546)
at wicket.markup.html.form.Form$DefaultFormValidationStrategy$1.formComponent(Form.java:105)
at wicket.markup.html.form.Form$5.component(Form.java:410)
at wicket.MarkupContainer.visitChildren(MarkupContainer.java:471)
at wicket.markup.html.form.Form.visitFormComponents(Form.java:406)
at wicket.markup.html.form.Form$DefaultFormValidationStrategy.validate(Form.java:100)
at wicket.markup.html.form.Form.validate(Form.java:374)
at wicket.markup.html.form.Form.onValidate(Form.java:341)
at wicket.markup.html.form.Form.onFormSubmitted(Form.java:218)
... 27 more


This is not the exception that we're expecting to take place. Eelco, I think you are in the best position to reproduce and fix this issue.

Gili


------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to