当用户单击图像时,我尝试了各种将鼠标坐标放入支持 bean 的方法。我可以在 javascript 中获取坐标,然后调用 ajax 侦听器,但参数不在请求中。
我的js:
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"
}
}
}
我的 jsf 页面元素:
<h:graphicImage id="imagePan2" library="images" styleClass="wind_map" name="testImage.jpg" style="#{SarWindsImagesBean.imageStyle('testImage.jpg')}">
<f:ajax event="click" onevent="cis.sarwinds.updateZoomValues(this, event)" listener="#{SarWindsImagesBean.zoomInClick}" render="imagePan2 message"/>
</h:graphicImage>
我的支持豆:
public void zoomInClick(AjaxBehaviorEvent event) {
double width;
double height;
double top;
double left;
double mouseX;
double mouseY;
String fileName = "testImage";
Map<String, String> 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<String> it = imageItems.keySet().iterator();
while (it.hasNext()) {
String key = (String)it.next();
imageItems.put(key, new SarWindImageItem(width, height, top, left));
}
}
}
reqParams 为空。
担