Eelco Hillenius,

        Of course. This is a page:

=======================================================================
package eshop.wicket.page;

import wicket.IFeedback;
import wicket.markup.html.form.RequiredTextField;
import wicket.markup.html.form.TextArea;
import wicket.markup.html.form.TextField;
import wicket.markup.html.form.upload.FileUpload;
import wicket.markup.html.form.upload.FileUploadField;
import wicket.markup.html.form.upload.UploadForm;
import wicket.markup.html.form.validation.EmailAddressPatternValidator;
import wicket.markup.html.form.validation.RequiredValidator;
import wicket.markup.html.panel.FeedbackPanel;
import wicket.model.CompoundPropertyModel;
import eshop.domain.Shop;
import eshop.service.ShopService;
import eshop.wicket.CustomWebPage;
import eshop.wicket.bean.FileUploadBean;
import eshop.wicket.component.Border;
import eshop.wicket.component.MenuBasic;
import eshop.wicket.validation.PhoneValidator;
import eshop.wicket.validation.PostcodeValidator;

public class BasicShop extends CustomWebPage
{
        private ShopService shopService;
        private FileUploadBean uploadBean;
        private Shop shop;

        public BasicShop()
        {
                shopService = (ShopService)locateBean("shopService");
                uploadBean = (FileUploadBean)locateBean("uploadBean");
                Long shopId = getCustomWebSession().getShopId();
                shop = shopService.fetch(shopId);

                FeedbackPanel feedback = new FeedbackPanel("feedback");
                Border border = new Border("border");
                border.add(feedback);
                border.add(new FormInput("form", feedback));
                border.add(new MenuBasic("menu"));
                add(border);
        }

        private class FormInput extends UploadForm
        {
                private IFeedback feedback;
                private FileUploadField logo;

                public FormInput(String id, IFeedback feedback)
                {
                        super(id, new CompoundPropertyModel(shop), feedback);

                        add(new RequiredTextField("id", Long.class));
                        add(new RequiredTextField("domain"));
                        add(new RequiredTextField("name"));
                        add(new 
TextArea("description").add(RequiredValidator.getInstance()));
                        add(new RequiredTextField("email").add(new 
EmailAddressPatternValidator()));
                        add(new RequiredTextField("address"));
                        add(new RequiredTextField("postcode").add(new 
PostcodeValidator()));
                        add(new RequiredTextField("phone").add(new 
PhoneValidator()));
                        add(new TextField("fax").add(new PhoneValidator()));
                        add(new RequiredTextField("title"));
                        add(new TextField("keywords"));
                        add(logo = new FileUploadField("logo"));
                }

                protected void onSubmit()
                {
                        FileUpload logoUpload = logo.getFileUpload();
                        uploadBean.upload(logo.getFileUpload(), shop.getLogo());

                        shopService.update(shop);

                        info(getLocalizer().getString("success", this));
                }

        }
}

=======================================================================


and this is my base WebPage

public class CustomWebPage extends WebPage
{
        public Object locateBean(String beanName)
        {
                CustomWebApplication application = 
(CustomWebApplication)getApplication();
                return application.locateBean(beanName);
        }

        public CustomWebSession getCustomWebSession()
        {
                return (CustomWebSession)getSession();
        }
}

=======================================================================

and this is my WebApplication

public class CustomWebApplication extends WebApplication
{
        private WebApplicationContext context;

        public void init()
        {
                getPages().setHomePage(Home.class);
                getSettings().setResourcePollFrequency(Duration.ONE_SECOND);
                getSettings().setThrowExceptionOnMissingResource(false);
                
getSettings().setRenderStrategy(ApplicationSettings.REDIRECT_TO_BUFFER);
                getSettings().setStripComments(true);
                getSettings().setStripWicketTags(true);
                getSettings().setDefaultBeforeDisabledLink("<span 
class=\"disabled_link\">");
                getSettings().setDefaultAfterDisabledLink("</span>");
                getSettings().setCompressWhitespace(false);
                getSettings().setAutomaticLinking(false);
        }

        public ISessionFactory getSessionFactory()
        {
                return new ISessionFactory()
                {
                        public Session newSession()
                        {
                                return new 
CustomWebSession(CustomWebApplication.this);
                        }
                };
        }

        public Object locateBean(String beanName)
        {
                if (context == null)
                        context = 
WebApplicationContextUtils.getWebApplicationContext(getWicketServlet()
                                        .getServletContext());

                return context.getBean(beanName);
        }
}



======= 2005-06-17 22:50:47 :=======

>Ah, ok... Hmmm... that's something to investigate, though I can't think
>of something off the top of my head. Could you send some code to this list?
>
>Eelco
>
>
>
>叶卫国 wrote:
>
>>Eelco Hillenius,
>>
>>      But another problem occurs ... When I submit a form, it works, but when 
>> i upload a file, the annoying LazyInitializationException  jump out
>>
>>======= 2005-06-17 22:42:47 :=======
>>
>>  
>>
>
>
>
>-------------------------------------------------------
>SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
>from IBM. Find simple to follow Roadmaps, straightforward articles,
>informative Webcasts and more! Get everything you need to get up to
>speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
>_______________________________________________
>Wicket-user mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/wicket-user

= = = = = = = = = = = = = = = = = = = =
                        
                                 
        叶卫国
[EMAIL PROTECTED]
          2005-06-17

Reply via email to