You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by David Chang <da...@yahoo.com> on 2010/03/19 18:04:24 UTC

Re: Dynamic Image (aka Barcode) based on user input not refreshed via Ajax

Exactly. That is what eventually I found out after quite some time fruitless research and test in other areas.

--- On Fri, 3/19/10, Igor Vaynberg <ig...@gmail.com> wrote:

> From: Igor Vaynberg <ig...@gmail.com>
> Subject: Re: Dynamic Image (aka Barcode) based on user input not refreshed via  Ajax
> To: users@wicket.apache.org, "Doug Leeper" <do...@yahoo.com>
> Date: Friday, March 19, 2010, 12:56 PM
> use NonCachingImage
> 
> -igor
> 
> On Fri, Mar 19, 2010 at 9:47 AM, Doug Leeper <do...@yahoo.com>
> wrote:
> > I am trying to create a barcode image from a user
> entered value.  The image is to be updated while the user
> types.  Hence I am using Ajax (onChange event) on the text
> field to regenerate the image.  However, the image is not
> getting refreshed.  It appears that the browser is not
> recognizing that the image has been updated.  Is there a
> way to append a "timestamp" on the image url just for this
> image?
> >
> > or should I use a different type of resource?
> >
> > Note: the value entered has not be persisted so I
> don't believe I can a ResourceReference.  Please correct me
> if I am wrong.
> >
> >
> > Thanks
> > - Doug
> >
> >
> >
> > BTW...Here is my code that I am using to generate the
> bar code:
> >
> > barCodeValueContainer = new
> WebMarkupContainer("barCodeValueContainer") {
> >            @Override
> >            public void onBeforeRender() {
> >                if
> (coupon.getObject().getBarCodeType() == null) {
> >                    codeContainer.replace(new
> WebMarkupContainer("barCode"));
> >                } else if (barCodeErrorMessage
> == null) {
> >                    codeContainer.replace(new
> BarCodeFragment("barCode", this));
> >                } else {
> >                    codeContainer.replace(new
> ErrorFragment("barCode", this,
> >                          
>  barCodeErrorMessage));
> >                }
> >                super.onBeforeRender();
> >            }
> >
> >            public boolean isVisible() {
> >                return
> coupon.getObject().getBarCodeType() != null;
> >            }
> >        };
> >
> > private class BarCodeFragment extends Fragment {
> >        public BarCodeFragment(String id,
> MarkupContainer markupProvider) {
> >            super(id, "barCodeFragment",
> markupProvider);
> >            setRenderBodyOnly(true);
> >
> >            // Create the barcode bean
> >
> >            String barCodeType =
> coupon.getObject().getBarCodeType();
> >            String barCodeValue =
> coupon.getObject().getBarCodeValue();
> >
> >            AbstractBarcodeBean bean = null;
> >
> >            if
> (barCodeType.equals(BarCodeType.CODE_39.id())) {
> >                bean = new Code39Bean();
> >                // bar width exactly one pixel
> >                ((Code39Bean)
> bean).setWideFactor(3);
> >            } else if
> (barCodeType.equals(BarCodeType.CODE_128.id())) {
> >                bean = new Code128Bean();
> >            } else if
> (barCodeType.equals(BarCodeType.UPC_A.id())) {
> >                bean = new UPCABean();
> >            }
> >
> >            if (bean == null || barCodeValue ==
> null) {
> >                add(new
> ErrorFragment("barCode", CouponDetailEditPanel.this,
> >                        "Bar code value not
> set"));
> >            } else {
> >                final int dpi = 150;
> >
> >                // Configure the barcode
> generator
> >              
>  bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); // makes
> the
> >                // narrow
> >
> >                bean.doQuietZone(false);
> >
> >                // Open output file
> >                ByteArrayOutputStream out = new
> ByteArrayOutputStream();
> >
> >                try {
> >                    // Set up the canvas
> provider for monochrome PNG output
> >                    BitmapCanvasProvider
> canvas = new BitmapCanvasProvider(out,
> >                            "image/png",
> dpi, BufferedImage.TYPE_BYTE_BINARY,
> >                            false, 0);
> >
> >                    // Generate the barcode
> >                  
>  bean.generateBarcode(canvas, barCodeValue);
> >
> >                  
>  System.out.println("VALUE: " + barCodeValue);
> >
> >                    // Signal end of
> generation
> >                    canvas.finish();
> >                    out.close();
> >                    final byte[] content =
> out.toByteArray();
> >                    Image img = new
> Image("barCode", new BarCodeImageResource(
> >                            content));
> >                    add(img);
> >                } catch (Exception e) {
> >                    add(new
> ErrorFragment("barCode",
> >                          
>  CouponDetailEditPanel.this, e.getMessage()));
> >                }
> >            }
> >
> >        }
> >    }
> >
> >
> > private class BarCodeImageResource extends
> DynamicImageResource {
> >        private byte[] content;
> >
> >        public BarCodeImageResource(byte[] content)
> {
> >            super("image/png");
> >            this.content = content;
> >          
>  this.setLastModifiedTime(Time.now());
> >        }
> >
> >        @Override
> >        protected byte[] getImageData() {
> >            return content;
> >        }
> >
> >    }
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 


      

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org