have a look at the attached files, thats based on your code snippet,
you will get the idea.
regards
dipu
On Nov 27, 2007 7:17 AM, tsuresh <[EMAIL PROTECTED]> wrote:
>
> Hi Dipu,
> Could you please tell me what to write in the method
> onSelecitionChanged(). It would be easier for me to understand if you
> provide the code example. I studied the link
> http://cwiki.apache.org/WICKET/dropdownchoice-examples.html but could not
> understand it.
> thanks
>
>
> Dipu Seminlal wrote:
> >
> > there are two ways to do it
> >
> > override the wantOnSelectionChangedNotifications of the user dropdown
> > to return true and override onSelectionChanged to do what you want,
> > but this will result in server round trips ( refer the java of
> > DropDownChoice )
> >
> > or use an AjaxFormComponentUpdatingBehavior on the onChange event of
> > the dropdown.
> >
> > regards
> > Dipu
> >
> > On Nov 26, 2007 7:14 AM, tsuresh <[EMAIL PROTECTED]> wrote:
> >>
> >> Hello wicketeers,
> >> I have a form to edit the attributes of User. User has the attributes
> >> username, mail and role.I have a dropdownchoice filled with list of
> >> users.
> >> When I select the user his mail should be displayed in textfield and his
> >> role should be displayed in dropdownchoice. And i should be able to edit
> >> his
> >> mail and role. I have already made the form to fill the first drop down
> >> choice.I have made function view(username) in User class which helps in
> >> viewing attributes of the user(user selected in dropdown), But I have no
> >> idea to populate the remaining form components.How to do this? My code
> >> for
> >> form is as below:
> >>
> >> public UserEdit(){
> >>
> >> User user= new user();
> >> CompoundPropertyModel userEditModel = new
> >> CompoundPropertyModel(user);
> >> Form form = new userEditForm("user",userEditModel);
> >> add(form);
> >> add(new FeedbackPanel("feedback").setOutputMarkupId(true));
> >> DropDownChoice ddc = null;
> >> try{
> >> ddc = new DropDownChoice("username",user.list());
> >> }catch(SQLException e){
> >> String err = e.getMessage();
> >> }
> >>
> >> TextField mailComp = new TextField("mail");
> >> DropDownChoice roleDdc =null;
> >> try{
> >> roleDdc = new DropDownChoice("role.name",r.list());
> >> }catch(SQLException e){
> >> String err = e.getMessage();
> >> }
> >> form.add(ddc);
> >> form.add(mailComp);
> >> form.add(roleDdc);
> >> }
> >>
> >> class UserEditForm extends Form {
> >> public UserEditForm(String id,IModel model) {
> >> super(id,model);
> >> }
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Populate-form-according-to-selected-item-in-dropdownchoice-tf4873352.html#a13944776
> >> Sent from the Wicket - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Populate-form-according-to-selected-item-in-dropdownchoice-tf4873352.html#a13965803
>
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
/* TestPage.java
* com.xmltravel.fab1.wicket.testcontrol
* fab1gui1.3
*
* Created on 27 Nov 2007 by FULL NAME HERE (dipu should fix this)
*
* Copyright:
* Multicom Products Ltd. 2007
* Bristol, England.
*
*/
package com.xmltravel.fab1.wicket.testcontrol;
import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import com.xmltravel.fab1.wicket.page.BasePage;
public class TestPage extends BasePage
{
private static final long serialVersionUID = 1L;
private CompoundPropertyModel userEditModel;
private static List<String> roles = new ArrayList<String>();
static
{
roles.add("Manger");
roles.add("Admin");
roles.add("Super User");
roles.add("User");
}
private static List<User> users = new ArrayList<User>();
static
{
User user1= new User("user1",roles.get(0),"[EMAIL PROTECTED]");
User user2= new User("user2",roles.get(1),"[EMAIL PROTECTED]");
User user3= new User("user3",roles.get(2),"[EMAIL PROTECTED]");
users.add(user1);
users.add(user2);
users.add(user3);
}
public TestPage()
{
add(new FeedbackPanel("feedback").setOutputMarkupId(true));
userEdit();
}
public void userEdit()
{
User user= new User("user1",roles.get(0),"[EMAIL PROTECTED]");
userEditModel = new CompoundPropertyModel(user);
final Form form = new UserEditForm("user",userEditModel);
add(form);
final DropDownChoice ddc = new DropDownChoice("username",users,new UserNameRenderer());
final TextField mailComp = new TextField("mail");
final DropDownChoice roleDdc = new DropDownChoice("role",roles);
final WebMarkupContainer container = new WebMarkupContainer("container");
container.setOutputMarkupId(true);
container.add(mailComp);
container.add(roleDdc);
AjaxFormComponentUpdatingBehavior behavior = new AjaxFormComponentUpdatingBehavior("onchange")
{
private static final long serialVersionUID = 1L;
protected void onUpdate(AjaxRequestTarget target)
{
String userId = ddc.getInput();
User user = findUserById(userId);
mailComp.setModelObject(user.getMail());
roleDdc.setModelObject(user.getRole());
target.addComponent(container);
}
};
ddc.add(behavior);
form.add(ddc);
form.add(container);
}
//you must have this method in your DAO
private User findUserById(String id)
{
for (User user: users)
{
if(user.getId().equals(id))
{
return user;
}
}
return null;
}
}
class UserEditForm extends Form
{
private static final long serialVersionUID = 1L;
public UserEditForm(String id,IModel model)
{
super(id,model);
}
}
class UserNameRenderer implements IChoiceRenderer
{
private static final long serialVersionUID = 1L;
public Object getDisplayValue(Object object)
{
return ((User)object).getUsername();
}
public String getIdValue(Object object, int index)
{
if(object instanceof User)
{
return ((User)object).getId();
}
return object+"";
}
}
/* User.java
* com.xmltravel.fab1.wicket.testcontrol
* fab1gui1.3
*
* Created on 27 Nov 2007 by FULL NAME HERE (dipu should fix this)
*
* Copyright:
* Multicom Products Ltd. 2007
* Bristol, England.
*
*/
package com.xmltravel.fab1.wicket.testcontrol;
import org.apache.wicket.IClusterable;
public class User implements IClusterable
{
private static final long serialVersionUID = 1L;
private String id;
private String role;
private String mail;
private String username;
public User(String username, String role, String mail )
{
this.username = username;
this.role = role;
this.mail = mail;
this.id=username+role+mail;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]