创建了标记库描述符文件:
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>image</short-name>
<uri>/WEB-INF/tlds/image</uri>
<tag>
<name>BsilImage</name>
<tag-class>com.custom.image.ImageTagHandler</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>url</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>style</name>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>type</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
</tag>
</taglib>
ImageTagHandler
public class ImageTagHandler extends UIComponentELTag {
private String url;
private String style;
private String type;
private static final String IMAGE_COMP_TYPE = "IMAGE_COMPONENT";
private static final String IMAGE_RENDERER_TYPE = "IMAGE_RENDERER";
public void setUrl(String url) {
this.url = url;
}
public void setStyle(String style) {
this.style = style;
}
public void setType(String type) {
this.type = type;
}
public String getComponentType() {
return IMAGE_COMP_TYPE;
}
public String getRendererType() {
return IMAGE_RENDERER_TYPE;
}
@Override
protected void setProperties(UIComponent component) {
super.setProperties(component);
ImageComponent imgComponent =
((ImageComponent) component);
if (type != null) {
imgComponent.setType(ImageTranscoder.getImageTypeOf(type));
}
if (url != null) {
imgComponent.setUrl(ImageTranscoder.getImagePath(url));
}
if (style != null) {
imgComponent.setStyle(style);
}
}
}
ImageComponent
public class ImageComponent extends UIOutput {
private String url;
private String style;
private String type;
private static final String IMAGE_COMP_FAMILY = "IMAGE_FAMILY";
@Override
public String getFamily() {
return IMAGE_COMP_FAMILY;
}
/**
* Get the value of type
*
* @return the value of type
*/
public String getType() {
return type;
}
/**
* Set the value of type
*
* @param type new value of type
*/
public void setType(String type) {
this.type = type;
}
/**
* Get the value of style
*
* @return the value of style
*/
public String getStyle() {
return style;
}
/**
* Set the value of style
*
* @param style new value of style
*/
public void setStyle(String style) {
this.style = style;
}
/**
* Get the value of url
*
* @return the value of url
*/
public String getUrl() {
return url;
}
/**
* Set the value of url
*
* @param url new value of url
*/
public void setUrl(String url) {
this.url = url;
}
}
ImageRenderer
public class ImageRenderer extends Renderer {
@Override
public void encodeBegin(FacesContext context, UIComponent component)
throws IOException {
ImageComponent imgComponent = (ImageComponent)component;
ResponseWriter writer = context.getResponseWriter();
writer.startElement("div",component);
writer.startElement("img", imgComponent);
writer.writeAttribute("src",imgComponent.getUrl(), "url");
writer.writeAttribute("class", imgComponent.getStyle(), "style");
writer.endElement("div");
}
}
访问TAG LIB的代码
<h:dataTable var="landing" binding="${LandingBean.tourPackages}" >
<h:column>
<tr:panelGroupLayout layout="vertical" styleClass="landingListing">
<bsil:BsilImage style="listingImage" url="${landing.photoThumbnail}" type="banner"/>
</tr:panelGroupLayout>
</h:column>
</h:dataTable>
bean包含多张照片,在显示页面时必须以列数显示。我面临的问题是它无法向我显示多个图像给出错误说
根据TLD或属性 标签文件中的指令,属性 绑定不接受任何 表达式
如果bean包含单个图像,则显示该代码为
<tr:panelHeader id="panelHeader" styleClass="banner" text="">
<bsil:BsilImage url="${LandingBean.bannerImage}"
style="bannerImage" type="banner"></bsil:BsilImage>
</tr:panelHeader>
我想知道如何使用自定义组件显示多个图像。
答案 0 :(得分:0)
根据您引用的错误消息,似乎问题出现在<h:dataTable ...>
标记中,似乎其属性称为“绑定”显然由于某种原因不接受表达式。
E.g。
<tag>
<name>dataTable</name>
<attribute>
<name>binding</name>
<!-- add this: -->
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
如果您拥有dataTable标记的代码,请在该标记的“绑定”属性旁边添加<rtexprvalue>true</rtexprvalue>
(就像您在图片标记中所做的那样)。如果不这样做,请参阅它的文档并找出它不允许表达式的原因。