RichFaces组件listShuttle使用注意事项

7 篇文章 0 订阅

RichFaces组件listShuttle使用注意事项

 

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…

   public int hashCode() {

         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;

     }

     public boolean equals(Object obj) {

         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>

 

2、  注意事项:

a)         页面中r:listShuttle组件一定要指定converter属性值,

否则会报javax.faces.el.PropertyNotFoundException异常。

b)         实体组件,例如例子中的ToolBarItem组件一定要实现hashCode()equals() 方法,否则不能通过验证,提示Component XXXX   has invalid value expression XXXX”验证信息。

c)      r:listShuttle组件中sourceValue targetValue List or Array of items,而sourceSelectiontargetSelectioncollection of items

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值