Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass mouse coordinates to backing bean when clicking on an image
    primarykey
    data
    text
    <p>I have tried various methods of getting the mouse coordinates into the backing bean when a user clicks on an image. I can get the coordinates in the javascript, it then calls the ajax listener, but the parameters are not in the request.</p> <p>my js:</p> <pre><code>if (!cis) var cis = {} if (!cis.sarwinds) { var focusLostTimeout cis.sarwinds = { errorHandler: function(data) { alert("Error occurred during Ajax call: " + data.description) }, updateZoomValues: function(input, event) { jsf.ajax.addOnError(cis.sarwinds.errorHandler) var offset = jQuery(input).offset(); jsf.ajax.request(input, event, { render: "imagePan2 message", x: event.pageX - offset.left, y: event.pageY - offset.top }) }, getGraphicImageId: function(input) { var clientId = new String(input.name) var lastIndex = clientId.lastIndexOf(":") return clientId.substring(0, lastIndex) + ":imagePan2" } } } </code></pre> <p>My jsf page element:</p> <pre><code> &lt;h:graphicImage id="imagePan2" library="images" styleClass="wind_map" name="testImage.jpg" style="#{SarWindsImagesBean.imageStyle('testImage.jpg')}"&gt; &lt;f:ajax event="click" onevent="cis.sarwinds.updateZoomValues(this, event)" listener="#{SarWindsImagesBean.zoomInClick}" render="imagePan2 message"/&gt; &lt;/h:graphicImage&gt; </code></pre> <p>My Backing bean:</p> <pre><code> public void zoomInClick(AjaxBehaviorEvent event) { double width; double height; double top; double left; double mouseX; double mouseY; String fileName = "testImage"; Map&lt;String, String&gt; reqParams = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); mouseX = Double.parseDouble(reqParams.get("x")); mouseY = Double.parseDouble(reqParams.get("y")); width = imageItems.get(fileName).getImageWidth() * 1.1; height = imageItems.get(fileName).getImageHeight() * 1.1; // We need the mouse position on the image here, and we need to calculate top = mouseY - ((mouseY - imageItems.get(fileName).getImageTop()) * 1.1); left = mouseX - ((mouseX - imageItems.get(fileName).getImageLeft()) * 1.1); if (this.imageLock == false){ imageItems.put(fileName, new SarWindImageItem(width, height, top, left)); } else { Iterator&lt;String&gt; it = imageItems.keySet().iterator(); while (it.hasNext()) { String key = (String)it.next(); imageItems.put(key, new SarWindImageItem(width, height, top, left)); } } } </code></pre> <p>The reqParams are empty. </p> <p>Dan</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload