Reputation: 16525
I have a form:
private Class TestForm extends Form<TestString>{
public TestForm(TestString testString){
super("testForm", new CompoundPropertyModel<TestString>(testString));
final TextField<String> test = new TextField<String>("test"));
add(test);
... //submit button
}
The TestString
class contains just one field: test
.
Is it possible to get value of string other than by pushing the submit button? With behaviors or something else?
I tried to add AjaxEventBehavior
and inside of this behavior called the methods text.getValue()
and testString.getTest()
but with no success.
Upvotes: 0
Views: 4218
Reputation: 833
As mentioned you could use AjaxFormComponentUpdatingBehaviour and use an onchange event (or an OnChangeAjaxBehaviour), this does of course mean that any time your onUpdate(AjaxRequestTarget target) function gets called is not necessarily the users final intended input. For example: Let's say you type 'test', your update function will get called 4 times, but only the final call is the final word as the user wishes to submit it.
One important thing I want to mention for your scenario is that you cannot simply look for an onblur event because (in your example) the only time the user is likely to be blurring off the TextField is if they are trying to click on the submit button, at which point it's a little to late to worry about AJAX, because it's being submitted...
Perhaps if you provide more details about why you need the value of the string without pushing the submit button, then someone can come up with a better idea (of course it could be that the onchange event is just fine for you, in which case great!). If however (taking a wild stab in the dark) you need it to validate the input before the user submits the form, then you can actually do this after submission:
Upvotes: 0
Reputation: 2511
You must submit the form somehow. You could use a AjaxFormSubmitBehavior setting the default form behaviour to false with setDefaultProcessing(false). Doing so you skip form validation and you can read text value with text.getValue().
Upvotes: 2