1 官方例子源代码:
package a2;
public class ToolBarItem {
private String icon;
private String label;
private String iconURI;
public ToolBarItem() {
// TODO Auto-generated constructor stub
}
public ToolBarItem(String label, String icon) {
setLabel(label);
setIcon(icon);
}
//getter and setter…
<span style="color:#ff0000;">public int hashCode() {
</span>
final int prime = 31;
int result = 1;
result = prime * result + ((icon == null) ? 0 : icon.hashCode());
result = prime * result + ((label == null) ? 0 : label.hashCode());
return result;
}
<span style="color:#ff0000;"> public boolean equals(Object obj) {
</span>
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
final ToolBarItem other = (ToolBarItem) obj;
if (icon == null) {
if (other.icon != null) return false;
} else if (!icon.equals(other.icon)) return false;
if (label == null) {
if (other.label != null) return false;
} else if (!label.equals(other.label)) return false;
return true;
}
}
package a2;
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.annotations.Name;
@Name("toolBar")
public class ToolBar {
private List items = new ArrayList();
private List freeItems = new ArrayList();
public ToolBar() {
ToolBarItem item = new ToolBarItem();
item.setIcon("create_folder");
item.setLabel("Create Folder");
items.add(item);
item = new ToolBarItem();
item.setIcon("create_doc");
item.setLabel("Create Doc");
items.add(item);
item = new ToolBarItem();
item.setIcon("find");
item.setLabel("Find");
items.add(item);
item = new ToolBarItem();
item.setIcon("open");
item.setLabel("Open");
freeItems.add(item);
item = new ToolBarItem();
item.setIcon("save");
item.setLabel("Save");
freeItems.add(item);
item = new ToolBarItem();
item.setIcon("save_all");
item.setLabel("Save All");
freeItems.add(item);
item = new ToolBarItem();
item.setIcon("delete");
item.setLabel("Delete");
freeItems.add(item);
}
public String do1() {
System.out.println(items);
System.out.println(freeItems);
return null;
}
// getter and setter
}
package a2;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
@BypassInterceptors
@org.jboss.seam.annotations.faces.Converter(id = "listShuttleconverter")
@Name("listShuttleconverter")
public class Converter implements javax.faces.convert.Converter {
public Object getAsObject(FacesContext context, UIComponent component, String value) {
int index = value.indexOf(':');
return new ToolBarItem(value.substring(0, index), value.substring(index + 1));
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
ToolBarItem optionItem = (ToolBarItem) value;
return optionItem.getLabel() + ":" + optionItem.getIcon();
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view contentType="text/html" xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:a="http://richfaces.org/a4j"
xmlns:s="http://jboss.com/products/seam/taglib" xmlns:c="http://java.sun.com/jstl/core"
xmlns:r="http://richfaces.org/rich">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>seam</title>
<link rel="shortcut icon" href="#{request.contextPath}/favicon.ico" />
</head>
<body>
<h:form id="form1">
<r:toolBar id="toolBar" itemSeparator="line" height="28px">
<c:forEach items="#{toolBar.items}" var="item">
<h:panelGroup>
<h:graphicImage value="#{item.iconURI}" styleClass="pic" />
<h:outputLink value="#">
<h:outputText value="#{item.label}"></h:outputText>
</h:outputLink>
</h:panelGroup>
</c:forEach>
</r:toolBar>
<r:spacer height="20"></r:spacer>
<r:listShuttle sourceValue="#{toolBar.freeItems}" targetValue="#{toolBar.items}" var="items" listHeight="300"
listWidth="300" sourceCaptionLabel="Available Items" targetCaptionLabel="Currently Active Items"
converter="listShuttleconverter">
<r:column width="18">
<h:graphicImage value="#{items.iconURI}"></h:graphicImage>
</r:column>
<r:column>
<h:outputText value="#{items.label}"></h:outputText>
</r:column>
<a:support event="onlistchanged" reRender="toolBar" />
</r:listShuttle>
<r:messages></r:messages>
<h:commandButton action="#{toolBar.do1}" value=" 测试 " />
<a:log popup="false" level="ALL" style="width: 800px; height: 300px;">
</a:log>
</h:form>
</body>
</html>
</f:view>