Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

Testing Form with AjaxSubmitLink

$
0
0
How do you submit a form via WicketTester and an AjaxSubmitLink?

*HomePage.java:*

public class HomePage extends WebPage

private static final long serialVersionUID = 1L;

private String email;

public HomePage( final PageParameters parameters )

super( parameters );

Form form = new Form( "form" );
add( form );

form.add( new EmailTextField( "email", new PropertyModel(this, "email") ) );
form.add( new AjaxSubmitLink("submit")

@Override
protected void onSubmit( AjaxRequestTarget target, Form<?> form )

int i = 0;

});

*HomePage.html*

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<body>

<form wicket:id="form">
<input type="email" wicket:id="email" placeholder="Email">
<button type="submit" wicket:id="submit">Sign Up</button>
</form>

</body>
</html>

*Unit Test:*

@Test
public void testPanel() throws Exception

WicketTester tester = new WicketTester();
tester.startPage( HomePage.class );

FormTester formTester = tester.newFormTester( "form" );
formTester.setValue( "email", "test [ at ] test.com" );
formTester.submit( "submit" );

Viewing all articles
Browse latest Browse all 5648

Trending Articles