add(new TextField("..", new PropertyModel(getPage(), "field"));
notice this model is equivalent to the one for the label. the label reads the model while the textfield writes into it.
-Igor
On 1/12/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
please see here for page lifecycle explanation
http://thread.gmane.org/gmane.comp.java.wicket.user/7195
your label is not being updated because its value is set only once in its constructor
add( new Label( "page.test.label", getField() ) );
since the page is not recreated and neither is the label the value never changes
to update the label dynamically specify a model instead of a string
add(new Label("page.test.label", new PropertyModel(this, "field"));
hope this helps, let us know if you have more questions.
-IgorOn 1/12/06, David Leangen <[EMAIL PROTECTED]> wrote:
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
