I have a store of images related to products in a product table. The URL to the image can be constructed using the product ID but not all products have images. If a product image is missing I want to display a placeholder image instead. My question is, how do I determine whether the URL I construct points to an actual image file.
Announcement
Collapse
No announcement yet.
X
-
It took a little trial and error but I finally got it. The only problem is that a warning alert gets displayed when the file doesn't exist. Here's my code. How do I suppress the warning? I would have thought that setWillHandleError(true) would do that.
Code:itemImg.setSrc("../customimages/" + rec.getAttribute("ISKU") + ".jpg"); RPCManager.setActionURL(itemImg.getSrc()); RPCRequest rpcReq = new RPCRequest(); rpcReq.setUseSimpleHttp(true); rpcReq.setWillHandleError(true); RPCManager.sendRequest(rpcReq, new RPCCallback(){ public void execute(RPCResponse response, Object rawData, RPCRequest request) { if (response.getHttpResponseCode()==404) { itemImg.setSrc("../customimages/noImageAvailable.jpg"); } } }); itemImg.redraw();
Comment
-
What's odd is that it is inconsistent. As I move around between different products that do not have an image file, about half the time it works as expected without showing the Warn alert and about half the time the alert shows up.Last edited by jay.l.fisher; 23 Nov 2009, 18:53.
Comment
-
That is the only code that does anything explicitly with RPC requests. It also has a side effect on other RPC operations. I have another grid in the app where I set filter criteria and fetchData based on user actions. The Warn alert about the transport error for the last image I tried to load starts showing up when the grid data is being fetched. Do I need to do something to "reset" the RPCManager?
Comment
Comment