I have a form where one of my text fields intermittently doesn't update when
I change the model, even though I add the component to the AJAX target.
Most of the time it works. When you add a few fields to the ListChoice,
this is where things get dicey.
Here's the scenario: you have a ListChoice of user names and a series of
text fields with data about each user. When you click on a name in the
ListChoice, we use the username as a key and ask the server for the rest of
the data on that user, which I fluff into a UserBean object, whose data is
the model for my TextFields. Then I use AJAX to update the fields:
// Instantiate the TextFields
txtUserName = new TextField<String>( "txtUserName", new
PropertyModel<String>( selectedUser, "userName" ) );
txtUserName.setOutputMarkupId( true );
acctForm.add( txtUserName );
...
txtEmail = new TextField<String>( "txtEmail", new
PropertyModel<String>( selectedUser, "email" ) );
txtEmail.setOutputMarkupId( true );
...
acctForm.add( txtEmail );
// Set up the ListChoice and its onChange behavior
listCtrlUsers = new ListChoice<String>( "userNames", new
PropertyModel<String>( selectedUser, "userName" ), userNames );
listCtrlUsers.add( new AjaxFormComponentUpdatingBehavior( "onchange" )
{
protected void onUpdate( AjaxRequestTarget target )
{
selectedUser = new UserBean( UserAdapter.getUser(
listCtrlUsers.getModelObject() ) );
txtUserName.setModelObject( selectedUser.getUserName() );
txtEmail.setModelObject( selectedUser.getEmail() );
txtPhoneNo.setModelObject( selectedUser.getPhoneNo() );
...
target.addComponent( txtUserName );
target.addComponent( txtEmail );
target.addComponent( txtPhoneNo );
...
}
}
listCtrlUsers.setOutputMarkupId( true );
acctForm.add( listCtrlUsers );
The UserBean is straightforward accessors:
private class UserBean
{
public UserBean( final User user )
{
userName = user.getUserName();
phoneNo = user.getPhoneNo();
email = user.getEmail();
...
}
public String getUserName()
{
return userName;
}
public void setUserName( String strName )
{
userName = strName;
}
...
}
Now, you are able to add to or delete from the ListChoice via calls to the
server that add or delete users, and the ListChoice USUALLY (but not always)
updates. Of course, when it doesn't update it's obvious why everything
falls apart but the fact that it doesn't always update is problemmatic and
similar to the issue where the TextField doesn't update.
Does anyone have any ideas about this?
Thank you for your trouble and time.
--
View this message in context:
http://www.nabble.com/Intermittently-not-updating-TextField-tp19845008p19845008.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]