I have this page class. When submitting the form via the AjaxButton I get a
null pointer exception.
It passes the instanceof in onSubmit but all data is null. I dont get this.
In the LoadableDetachable model I do new CartItem and when displaying the
page the first time I see the drop down choice correctly.

public class ItemPage extends RootPage {
        Long itemId;
        Item item;
        WebPage backPage;
        
        public ItemPage(){
                throw new RestartResponseAtInterceptPageException(Base.class);
        }
        
        public ItemPage(  PageParameters parameters ){
                this( parameters , null );
        }

        public ItemPage( PageParameters parameters, WebPage backPage  ){
                
                this.backPage = backPage;
                
                try{
                        itemId = new Long( parameters.getString( "ItemId", "" ) 
);
                }catch( NumberFormatException nex ){
                        throw new 
RestartResponseAtInterceptPageException(Base.class);
                }
                
                item = getItemDao().getItem( itemId );
                if( item == null )throw new
RestartResponseAtInterceptPageException(Base.class);
        
                IModel cartItemsModel = new LoadableDetachableModel(){
                        private static final long serialVersionUID = 1L;

                        @Override
                        protected Object load() {
                                List<SubItem> subItems = 
getItemDao().getSubItems(item);
                                List<CartItem> cartItems = new 
LinkedList<CartItem>();
                                
                                for( SubItem subItem : subItems ){
                                        if( subItem.getBalance() > 0 ){
                                                StringBuffer buf = new 
StringBuffer();
                                                for( Attribute attribute : 
subItem.getAttributes() ){
                                                        buf.append( 
attribute.getData() + " : " );
                                                }
                                                
                                                if( buf.length() > 0 ){
                                                        buf.delete(buf.length() 
- 3, buf.length() );
                                                }
                                                
                                                CartItem item = new CartItem();
                                                item.setAmount( 1 );
                                                item.setSubItem(subItem);
                                                item.setAttributes(  
buf.toString() );
                                                cartItems.add( item );
                                                
                                        }
                                }
                                return cartItems;
                        }
                        
                };
                
                
                final DropDownChoice choice = new DropDownChoice( "subItems", 
new Model(),
cartItemsModel, new ChoiceRenderer( "attributes", "subItem.id" ) );
                choice.setNullValid( true );
                Form itemForm = new Form( "itemForm" );
                
                AjaxButton addToCart = new AjaxButton( "addToCart" , itemForm ){
                        private static final long serialVersionUID = 1L;

                        @Override
                        protected void onSubmit(AjaxRequestTarget target, Form 
form ) {
                                target.addComponent( this );
                                if( choice.getModelObject() instanceof CartItem 
){
                                        System.out.println( 
choice.getModelObject() );
                                        Cart cart = getCart();
                                        
                                        CartItem item = (CartItem) getModel();
                                        System.out.println( 
item.getAttributes() );
                                        
                                        //cart.addCartItem( (CartItem) 
getModelObject() );
                                        //updateCart();
                                }
                        }
                        
                };
                addToCart.setOutputMarkupId( true );
                itemForm.add( addToCart );
                itemForm.add( choice );
                 add( itemForm );
                 
                 
                 Link back = new Link( "backLink" ){
                        private static final long serialVersionUID = 1L;

                        @Override
                        public void onClick() {
                                setResponsePage( getBackPage() );
                        }
                         
                 };
                 
                 if( getBackPage() == null ) back.setVisible( false );
                 add( back );
                 
        }

        public WebPage getBackPage() {
                return backPage;
        }
        
        
}

public class CartItem implements Serializable{
        
        private static final long serialVersionUID = 1L;
        private int amount;
        private SubItem subItem;
        private String attributes;
        
        public int getAmount() {
                return amount;
        }
        public void setAmount(int amount) {
                this.amount = amount;
        }
        public SubItem getSubItem() {
                return subItem;
        }
        public void setSubItem(SubItem subItem) {
                this.subItem = subItem;
        }
        public String getAttributes() {
                return attributes;
        }
        public void setAttributes(String attributes) {
                this.attributes = attributes;
        }
        
        
}
-- 
View this message in context: 
http://www.nabble.com/Null-pointer-I-don%27t-understand-tp17269836p17269836.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]

Reply via email to