[Wicket-user] How do you update domain object from Model/DropDownChoice

2007-03-31 Thread Kurt R. Hoehn
I'm a divorced Struts programmer the breakup took place when I found
Wicket.  So I'm new to Wicket and I have a question about
Model/DropDownChoice/Domain Object updating.

Sorry about the long email.

Here is my question:

How do I update the Buyer object with a different Profile object if the
user selected a different Profile object on the form.  I tried the
onSelectionChanged in the DropDownChoice component and that worked but I
would have to hit the submit button twice and that didn't feel right. 

So what is the most correct way to do this with in wicket?

My environment is:
Java 1.5
Wicket 2.0-SNAPSHOT
Wicket-Spring 2.0-SNAPSHOT
Hibernate 3.2.1-GA
Spring 2.0.2

Here is my code:

public class Profile
{
private String identity;
private String name;

... setters/getters ...
}

public class Buyer
{
private String identity;
private String firstName;
private String lastName;

private Profile profile;

... setters/getters ...
}

BuyerPage.html:




Select Profile


Profile1
Profile2




Last Name



First Name



...








public class BuyerPage extends MyBasePage
{
...

public BuyerPage(PageParameters params)
{
Buyer buyer = new Buyer();

IModel buyerModel = new CompoundPropertyModel(buyer);
new FeedbackPanel(this, "feedback");

identity = params.getString("identity");
if( identity != null )
{
buyer.setIdentity(identity);
buyer = buyerManager.findByIdentity(buyer);
if( buyer != null )
{
buyerModel = new CompoundPropertyModel(buyer);
}
}
else
{
isNew = true;
buyer.setProfile(getProfile());
}

initializeForm(buyerModel);
}

protected void initializeForm(IModel buyerModel)
{
BuyerForm form = new BuyerForm(this, "buyerForm", buyerModel);
TextField lastName = new TextField(form,
"contact.lastName");
lastName.setRequired(true);

TextField firstName = new TextField(form,
"contact.firstName");
firstName.setRequired(true);

... other components ...

Profile profile = buyerModel.getObject().getProfile();
new DropDownChoice(form, "profile", new
Model(profile), profileManager.getProfiles(getProfile()),
new IChoiceRenderer() {
public Object getDisplayValue(Profile profile)
{
return profile.getName();
}

public String getIdValue(Profile profile, int i)
{
return profile.getIdentity();
}
})
}

class BuyerForm extends Form
{
public BuyerForm(MarkupContainer markupContainer, String s,
IModel buyerModel)
{
super(markupContainer, s, buyerModel);
}

public void onSubmit()
{
buyerManager.save( getModelObject() );
setResponsePage(BuyerListPage.class);
}
}
}


TIA,
-kurt



-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] How do you update domain object from Model/DropDownChoice

2007-03-31 Thread Igor Vaynberg

On 3/31/07, Kurt R. Hoehn <[EMAIL PROTECTED]> wrote:


Wicket 2.0-SNAPSHOT
Wicket-Spring 2.0-SNAPSHOT



wicket 2.0 has been discontinued for various reasons. you might want to
switch your project to the 1.x branch.



new DropDownChoice(form, "profile",
profileManager.getProfiles(getProfile()),



thats all you need - ie dont specify the model. that way ddc will use the
compound property model you have and put its selection into the "profile"
property for you.

also notice that profilemanager.getprofiles(getprofile()) should be new
LoadableDetachableModel() { load() { return profilemanager.getprofiles...

-igor
-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] How do you update domain object from Model/DropDownChoice

2007-03-31 Thread Kurt R. Hoehn
That worked great!  Thank you for the assistance and advice.

-kurt

On Sat, 2007-03-31 at 09:17 -0800, Igor Vaynberg wrote:
> On 3/31/07, Kurt R. Hoehn <[EMAIL PROTECTED]> wrote:
> Wicket 2.0-SNAPSHOT
> Wicket-Spring 2.0-SNAPSHOT
> 
> wicket 2.0 has been discontinued for various reasons. you might want
> to switch your project to the 1.x branch.
> 
> 
> 
> new DropDownChoice(form, "profile",
> profileManager.getProfiles(getProfile()),
> 
> thats all you need - ie dont specify the model. that way ddc will use
> the compound property model you have and put its selection into the
> "profile" property for you. 
> 
> also notice that profilemanager.getprofiles(getprofile()) should be
> new LoadableDetachableModel() { load() { return
> profilemanager.getprofiles...
> 
> -igor
> 
> 
> 
> 
> -
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> ___ Wicket-user mailing list 
> Wicket-user@lists.sourceforge.net 
> https://lists.sourceforge.net/lists/listinfo/wicket-user


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] How do you update domain object from Model/DropDownChoice

2007-03-31 Thread Martijn Dashorst
I've written up a new example document for workign with drop down
choice components, as they seem to be a source of confusion (should be
available any time soon when Apache syncs the servers)

http://incubator.apache.org/wicket/examples.html

Martijn

On 3/31/07, Kurt R. Hoehn <[EMAIL PROTECTED]> wrote:
> That worked great!  Thank you for the assistance and advice.
>
> -kurt
>
> On Sat, 2007-03-31 at 09:17 -0800, Igor Vaynberg wrote:
> > On 3/31/07, Kurt R. Hoehn <[EMAIL PROTECTED]> wrote:
> > Wicket 2.0-SNAPSHOT
> > Wicket-Spring 2.0-SNAPSHOT
> >
> > wicket 2.0 has been discontinued for various reasons. you might want
> > to switch your project to the 1.x branch.
> >
> >
> >
> > new DropDownChoice(form, "profile",
> > profileManager.getProfiles(getProfile()),
> >
> > thats all you need - ie dont specify the model. that way ddc will use
> > the compound property model you have and put its selection into the
> > "profile" property for you.
> >
> > also notice that profilemanager.getprofiles(getprofile()) should be
> > new LoadableDetachableModel() { load() { return
> > profilemanager.getprofiles...
> >
> > -igor
> >
> >
> >
> >
> > -
> > Take Surveys. Earn Cash. Influence the Future of IT
> > Join SourceForge.net's Techsay panel and you'll get the chance to share your
> > opinions on IT & business topics through brief surveys-and earn cash
> > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> > ___ Wicket-user mailing list 
> > Wicket-user@lists.sourceforge.net 
> > https://lists.sourceforge.net/lists/listinfo/wicket-user
>
>
> -
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> ___
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>


-- 
Learn Wicket at ApacheCon Europe: http://apachecon.com
Join the wicket community at irc.freenode.net: ##wicket
Wicket 1.2.5 will keep your server alive. Download Wicket now!
http://wicketframework.org

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user