I have some very basic questions about the usage of forms. I've tried to
follow the examples, but am still having some problems. Code and HTML
are posted below.
First, what actually happens when a page is submitted? I noticed that
the page reloads, but based on the System.err.print messages, the
ExamplePage is only being instantiated once, and not after a reload. I
would have thought that it would be instantiated again, since this is
what happens, for instance, during a browser refresh.
Second, how do I retrieve the values from the form? You'll notice below
that there is a label that I want to display with the value from the
form. However, this value always comes up null (maybe related to the
issue above??).
Thanks for the help!
Dave
------------
Code:
public class ExamplePage
extends WebPage
{
private static final long serialVersionUID = 1L;
private ExampleForm m_form;
private String m_freeExpressionField;
public ExamplePage( final ServiceManager serviceManager )
{
super( serviceManager );
final String msg = "~~~Instantiating ExamplePage~~~\n";
System.err.print( msg );
m_form = new ExampleForm( "exampleForm" );
add( m_form );
add( new Label( "page.test.label", getField() ) );
}
private String getField()
{
System.err.print( "Field value: " + m_freeExpressionField +
"\n" );
return m_freeExpressionField;
}
private class ExampleForm
extends Form
{
public ExampleForm( final String name )
{
super( name, new CompoundPropertyModel( new FormModel() ) );
add( new TextField( "freeExpressionField" ) );
add( new ImageButton( "goButton" ) );
}
public void onSubmit()
{
final FormModel model = (FormModel)getModelObject();
m_freeExpressionField = model.getFreeExpressionField();
info( "Form submitted" );
}
}
}
HTML:
<html xmlns:wicket="http://wicket.sourceforge.net/">
<head>
<title>Page Title</title>
</head>
<body>
<wicket:extend>
<p wicket:id="page.test.label">Test Label</p>
<form wicket:id="exampleForm" id="pubmedForm">
<input wicket:id="freeExpressionField" size="45"
type="text" value=""/>
<input wicket:id="goButton" type="image"
value="buttonFactory:save:Save"/>
</form>
</wicket:extend>
</body>
</html>
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user