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

2010-03-20 Thread Doug Leeper

Perfect!  Thanks!
-- 
View this message in context: 
http://old.nabble.com/Dynamic-Image-%28aka-Barcode%29-based-on-user-input-not-refreshed-via-Ajax-tp27961609p27972311.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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



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

2010-03-19 Thread David Chang
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  wrote:

> From: Igor Vaynberg 
> Subject: Re: Dynamic Image (aka Barcode) based on user input not refreshed 
> via  Ajax
> To: users@wicket.apache.org, "Doug Leeper" 
> Date: Friday, March 19, 2010, 12:56 PM
> use NonCachingImage
> 
> -igor
> 
> On Fri, Mar 19, 2010 at 9:47 AM, Doug Leeper 
> 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.fin

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

2010-03-19 Thread Igor Vaynberg
use NonCachingImage

-igor

On Fri, Mar 19, 2010 at 9:47 AM, Doug Leeper  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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



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

2010-03-19 Thread Xavier López
Found a similar issue not long ago. There is a class that does just what you
mentioned, appends a timestamp as a request parameter of the  tag's
url. I think the class was NonCachingImage.

Cheers,
Xavier

2010/3/19 Doug Leeper 

> 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;
>}
>
>}
>


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

2010-03-19 Thread Doug Leeper
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;
}

}