在此代码中,
<p:galleria value="#{Bean.images}" var="image" panelWidth="500" panelHeight="313" showCaption="true"
<p:graphicImage value="/images/galleria/#{image}" alt="Image Description for #{image}" title="#{image}"/
</p:galleria>
你如何得到selectedImage
?如表达的那样
<p:carousel id="carousel" value="#{tableBean.carsSmall}" var="car" itemStyleClass="carItem" headerText="Cars">
<p:graphicImage id="image" value="/images/cars/#{car.manufacturer}.jpg"/>
<h:panelGrid columns="2" style="width:100%" cellpadding="5">
<h:outputText value="Model: " /><h:outputText id="model" value="#{car.model}" />
</h:panelGrid>
<p:commandLink id="view" update=":form:carDetail" oncomplete="carDialog.show()" title="View Detail">
<h:outputText styleClass="ui-icon ui-icon-search" style="margin:0 auto;" />
<f:setPropertyActionListener value="#{car}"
target="#{tableBean.selectedCar}" />
</p:commandLink>
</p:carousel>
答案 0 :(得分:3)
假设您在每个当前显示的图片上都有详细信息按钮 (将alt属性设置为图像文件名)
<p:galleria value="#{Bean.images}" var="image">
<p:graphicImage value="/images/galleria/#{image}"/>
<f:facet name="content">
<p:graphicImage value="/images/galleria/#{image}" alt="#{image}" />
<span style="position:absolute;right:0;top:0;">
<p:commandButton styleClass="ui-icon ui-icon-search" onclick="jsCallRemote(this);" />
</span>
</f:facet>
</p:galleria>
搜索按钮可以调用js函数传递按钮本身作为提示找到当前图像文件名,然后调用远程命令将文件名作为请求参数传递给它:
<script>
function jsCallRemote(btn) {
var imageFileName = btn.parentNode.parentNode.getElementsByTagName('img')[0].alt;
selectImage([{name:'imageFileName', value:imageFileName}]);
}
</script>
<p:remoteCommand name="selectImage" actionListener="#{tableBean.selectImage}" />
bean的方法通过请求参数imageFileName:
进行实际选择public void selectImage() {
String fileName = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("imageFileName");
// find image by filename...
}
答案 1 :(得分:0)
如果您不想打算为每个图像设置一个按钮,则可以利用图库标题来捕获所选的图像标题。此解决方案基于andreea m的答案。
from django import forms
from wagtail.admin.edit_handlers import FieldPanel
class ScheduleCell(models.Model):
# ... field definitions here ...
panels = [
# ...
FieldPanel('start_time', widget=forms.TextInput),
FieldPanel('end_time', widget=forms.TextInput),
# ...
]
JS函数
<p:commandButton action="#{controller.preview}" value="Preview" onclick="checkSelectedImage();" oncomplete="PF('previewDialog').show();"/>
远程命令
function checkSelectedImage() {
var caption = document.getElementsByClassName("ui-galleria-caption");
selectImage([{name:'imageFileName', value:caption[0].getElementsByTagName("h4")[0].innerHTML}]);
}