you are using a server-side tab panel with tab links that are not submit links, that means
a) only form elements that are on the current tab when you press submit are processed b) any time you switch tabs you lose form data from the previous tab. -igor On Wed, Mar 18, 2009 at 3:17 PM, Mathias P.W Nilsson <[email protected]> wrote: > > When using an ajaxlink my modelObjectAsString on a textField is always empty. > > It is always set to where it was when the page was generated > > package se.edgesoft.hairless.web.page.site.checkout; > > import java.util.LinkedList; > import java.util.List; > > import org.apache.wicket.ajax.AjaxRequestTarget; > import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; > import org.apache.wicket.ajax.markup.html.AjaxLink; > import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink; > import org.apache.wicket.extensions.ajax.markup.html.tabs.AjaxTabbedPanel; > import org.apache.wicket.extensions.markup.html.tabs.AbstractTab; > import org.apache.wicket.markup.html.WebMarkupContainer; > import org.apache.wicket.markup.html.form.ChoiceRenderer; > import org.apache.wicket.markup.html.form.DropDownChoice; > import org.apache.wicket.markup.html.form.Form; > import org.apache.wicket.markup.html.form.TextField; > import org.apache.wicket.markup.html.panel.Panel; > import org.apache.wicket.model.CompoundPropertyModel; > import org.apache.wicket.model.IModel; > import org.apache.wicket.model.LoadableDetachableModel; > import org.apache.wicket.model.Model; > import org.apache.wicket.spring.injection.annot.SpringBean; > > import se.edgesoft.hairless.entities.presentation.Presentation; > import se.edgesoft.hairless.entities.presentation.PresentationType; > import se.edgesoft.hairless.entities.translation.Translation; > import se.edgesoft.hairless.entities.translation.TranslationType; > import se.edgesoft.hairless.entities.user.User; > import se.edgesoft.hairless.model.order.payment.IPayment; > import se.edgesoft.hairless.model.order.payment.KreditorFactory; > import se.edgesoft.hairless.model.order.payment.KreditorPayment; > import se.edgesoft.hairless.model.order.payment.PaymentFactory; > import se.edgesoft.hairless.model.order.payment.PaymentMethod; > import se.edgesoft.hairless.model.presentation.PresentationManager; > import se.edgesoft.hairless.model.translation.TranslatorManager; > import se.edgesoft.hairless.web.page.site.OverviewablePage; > > public class PurchasePage extends OverviewablePage{ > > AjaxTabbedPanel panel; > private IPayment payment; > �...@springbean( name = "PaymentFactory" ) > private PaymentFactory paymentFactory; > �...@springbean( name = "KreditorFactory" ) > private KreditorFactory kreditorFactory; > > public KreditorFactory getKreditorFactory() { > return kreditorFactory; > } > > > public PaymentFactory getPaymentFactory() { > return paymentFactory; > } > > > public IPayment getPayment() { > return payment; > } > > > public void setPayment(IPayment payment) { > this.payment = payment; > } > > > public PurchasePage(){ > Presentation presentation = new PresentationManager( getStore() > ).getPresentation( PresentationType.CART ); > Translation translation = new TranslatorManager( getStore() > ).getTranslation( TranslationType.CART ); > setBackground( presentation ); > addOverview( translation, presentation ); > addPromotion( true ); > > IModel countryModel = new LoadableDetachableModel(){ > > �...@override > protected Object load() { > return getCountryDao().getCountries(); > } > > }; > > IModel userModel = new LoadableDetachableModel(){ > > �...@override > protected Object load() { > return new User(); > } > > }; > > final Form purchaseForm = new Form( "purchase.form" ); > add( purchaseForm ); > > final WebMarkupContainer userContainer = new > WebMarkupContainer( > "userContainer",new CompoundPropertyModel(userModel)){ > �...@override > public boolean isVisible(){ > if( ! isLoggedIn() ) return false; > > return true; > } > > }; > userContainer.setOutputMarkupId( true ); > > > final DropDownChoice country = new DropDownChoice( "country" , > countryModel, new ChoiceRenderer( "name" , "name") ); > country.add( new AjaxFormComponentUpdatingBehavior( "onchange" > ){ > > �...@override > protected void onUpdate(AjaxRequestTarget target) { > target.addComponent( panel ); > } > > }); > > final TextField firstName = new TextField( "firstName" ); > firstName.setOutputMarkupId( true ); > userContainer.add( firstName ); > > final TextField street = new TextField( "street" ); > street.setOutputMarkupId( true ); > userContainer.add( street ); > > final TextField socialSecurityNumber = new TextField( > "socialSecurityNumber", new Model( "") ); > //socialSecurityNumber.setModelObject( new String("")); > socialSecurityNumber.setOutputMarkupId( true ); > purchaseForm.add( socialSecurityNumber ); > > userContainer.add( country ); > > purchaseForm.add( userContainer ); > purchaseForm.setOutputMarkupId( true ); > > final List tabs = new LinkedList(); > tabs.add( new KreditorTab( new Model( "Faktura")){ > public Panel getPanel(String panelId){return new > PaymentMethodPanel( > panelId ){ > �...@override > public void onPaymentChanged( IPayment > payment, AjaxRequestTarget target > ) { > setPayment(payment); > target.addComponent(userContainer); > } > �...@override > public List<IPayment> getPayments() { > List<IPayment> payments = new > LinkedList<IPayment>(); > for( IPayment payment : > getPaymentFactory().getPayments() ){ > if( > payment.getPaymentMethod().equals( PaymentMethod.KREDITOR)){ > if( ((KreditorPayment) > payment).getCampaign() == -1 ) > payments.add( payment > ); > } > } > return payments; > } > > �...@override > public boolean isVisible(){ > if( isLoggedIn() && > getUser().getCountry().getCode().equals( "SE" ) ){ > return true; > } > > return false; > } > }; > } > > �...@override > public boolean isSwedishOnly() { > return true; > } > > > }); > tabs.add( new PaymentTab( new Model( "Kortbetalning")){ > public Panel getPanel(String panelId){return new > PaymentMethodPanel( > panelId ){ > �...@override > public void onPaymentChanged( IPayment > payment, AjaxRequestTarget target > ) { > setPayment(payment); > } > �...@override > public List<IPayment> getPayments() { > List<IPayment> payments = new > LinkedList<IPayment>(); > for( IPayment payment : > getPaymentFactory().getPayments() ){ > if( > payment.getPaymentMethod().equals( PaymentMethod.CREDIT_CARD)){ > payments.add( payment > ); > } > } > return payments; > } > > > > }; > } > > �...@override > public boolean isSwedishOnly() { > // TODO Auto-generated method stub > return false; > } > > > }); > > tabs.add( new KreditorTab( new Model( "Delbetalning")){ > public Panel getPanel(String panelId){return new > PaymentMethodPanel( > panelId ){ > �...@override > public void onPaymentChanged( IPayment > payment, AjaxRequestTarget target > ) { > setPayment(payment); > } > �...@override > public List<IPayment> getPayments() { > List<IPayment> payments = new > LinkedList<IPayment>(); > for( IPayment payment : > getPaymentFactory().getPayments() ){ > if( > payment.getPaymentMethod().equals( PaymentMethod.KREDITOR)){ > if( ((KreditorPayment) > payment).getCampaign() != -1 ) > payments.add( payment > ); > } > } > return payments; > } > > �...@override > public boolean isVisible(){ > if( isLoggedIn() && > getUser().getCountry().getCode().equals( "SE" ) ){ > return true; > } > > return false; > } > }; > } > > �...@override > public boolean isSwedishOnly() { > return true; > } > > > }); > > tabs.add( new PaymentTab( new Model( "Postförskott")){ > public Panel getPanel(String panelId){return new > PaymentMethodPanel( > panelId ){ > �...@override > public void onPaymentChanged( IPayment > payment, AjaxRequestTarget target > ) { > setPayment(payment); > > } > > �...@override > public List<IPayment> getPayments() { > List<IPayment> payments = new > LinkedList<IPayment>(); > for( IPayment payment : > getPaymentFactory().getPayments() ){ > if( > payment.getPaymentMethod().equals( PaymentMethod.POST_PARCEL)){ > payments.add( payment > ); > } > } > return payments; > } > > �...@override > public boolean isVisible(){ > if( isLoggedIn() && > getUser().getCountry().getCode().equals( "SE" ) ){ > return true; > } > > return false; > } > > > }; > } > > �...@override > public boolean isSwedishOnly() { > // TODO Auto-generated method stub > return true; > } > > > > }); > > panel = new AjaxTabbedPanel("dsf" , tabs ){ > �...@override > protected WebMarkupContainer newLink(java.lang.String > linkId, final int > index){ > return new AjaxLink( linkId ){ > int selectedTab = getSelectedTab(); > boolean selected = (index == > selectedTab); > > �...@override > public void onClick(AjaxRequestTarget > target) { > setSelectedTab(index); > if( target != null ){ > target.addComponent( > panel ); > if( getTabs().get( > index ) instanceof KreditorTab ){ > > socialSecurityNumber.setVisible( true ); > > target.addComponent( userContainer ); > }else{ > > socialSecurityNumber.setVisible( false ); > > target.addComponent( userContainer ); > } > } > > onAjaxUpdate(target); > } > > �...@override > public boolean isEnabled(){ > if( isLoggedIn() ){ > PaymentTab tab = > (PaymentTab)getTabs().get( index ); > if( > tab.isSwedishOnly() ){ > if( > getUser().getCountry().getCode().equals( "SE" ) ){ > return > true; > } > return false; > } > > return true; > } > return false; > } > > }; > } > > }; > panel.setOutputMarkupId( true ); > purchaseForm.add( panel ); > > AjaxLink addressLink = new AjaxLink( "addressLink", new Model( > )){ > > �...@override > public void onClick(AjaxRequestTarget target) { > > if( getPayment() instanceof KreditorPayment ){ > KreditorFactory.Address a = > getKreditorFactory().getAddress( > getStore(), socialSecurityNumber.getModelObjectAsString() ); > if( a != null ){ > street.setModelObject( > a.getAddress() ); > } > > } > //target.addComponent( socialSecurityNumber ); > } > > }; > userContainer.add( addressLink ); > > AjaxSubmitLink submit = new AjaxSubmitLink( "submit" , > purchaseForm ){ > > �...@override > protected void onSubmit(AjaxRequestTarget target, Form > form) { > > System.out.println( getPayment() ); > > } > > �...@override > public boolean isEnabled(){ > if( ! isLoggedIn() ) return false; > > return true; > } > > }; > > purchaseForm.add( submit ); > > > } > > > private abstract class PaymentTab extends AbstractTab{ > private static final long serialVersionUID = 1L; > > public PaymentTab(IModel title) { > super(title); > } > > public abstract boolean isSwedishOnly(); > } > > private abstract class KreditorTab extends PaymentTab{ > > public KreditorTab(IModel title) { > super(title); > } > } > } > > > -- > View this message in context: > http://www.nabble.com/Explaination-of-Ajax-in-Wicket-tp22589797p22589797.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] > >
