论坛首页 Java企业应用论坛

请教:tapestry4.1中的Autocompleter的用法

浏览 4268 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-02-12  
用tapestry4.1中的dojo的Autocompleter组件时,
HTML代码:
  1. <html jwcid="@Shell" title="test" debugEnabled="true">
  2. <head>
  3. <!---->head>
  4. <body jwcid="@Body">
  5. <span jwcid="@Autocompleter" model="ognl:model" value="ognl:select"/>
  6. <!---->body>
  7. <!---->html>
页面类如下,
java 代码
  1. package autoCompleter.test;
  2. import java.util.Arrays;
  3. import org.apache.tapestry.dojo.form.DefaultAutocompleteModel;
  4. import org.apache.tapestry.dojo.form.IAutocompleteModel;
  5. import org.apache.tapestry.event.PageBeginRenderListener;
  6. import org.apache.tapestry.event.PageEvent;
  7. import org.apache.tapestry.html.BasePage;
  8. public abstract class AutoCompleter extends BasePage
  9. {
  10. public IAutocompleteModel model = null;
  11. public IAutocompleteModel getModel() {
  12. if (model == null) {
  13. model = new DefaultAutocompleteModel(Arrays.asList("aaaa","bbbb","dddd"), "id", "name");
  14. }
  15. return model;
  16. }
  17. public abstract String getSelect();
  18. public abstract String getId();
  19. public abstract String getName();
  20. }
但显示不了列表内容,郁闷了好几天都解决不了,有谁可以告诉我IAutocompleteModel的用法
   发表时间:2007-02-12  
终于知道怎么用了,现分享一下;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.apache.tapestry.dojo.form.DefaultAutocompleteModel;
import org.apache.tapestry.dojo.form.IAutocompleteModel;
import org.apache.tapestry.event.PageBeginRenderListener;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.html.BasePage;

public abstract class AutoCompleter extends BasePage implements PageBeginRenderListener
{
	public Date date = null;
	public IAutocompleteModel model = null;
	public void pageBeginRender(PageEvent arg0) {
		setText("TEXT");
		setDate(new Date());
	}	
	public IAutocompleteModel getModel() {
	    if (model == null) {
	    	List values = new ArrayList();
	        
	        SimpleBean s1 = new SimpleBean(new Integer(1), "Simple 1", 100);
	        SimpleBean s2 = new SimpleBean(new Integer(2), "Simple 2", 200);
	        SimpleBean s3 = new SimpleBean(new Integer(3), "Simple 3", 300);
	        
	        values.add(s1);
	        values.add(s2);
	        values.add(s3);
	        
	        model = new DefaultAutocompleteModel(values, "id", "label");
	    }
	    return model;
	  }
	public abstract void setText(String text);
	public abstract String getText();
	public abstract SimpleBean getSelect();
	public void formSubmit()
	{
		System.out.println(getDate());
		System.out.println(getSelect().getValue());		
	}
	public void setDate(Date d)
	{
		if(date == null)
		{
			this.date = new java.util.Date(); 
		}
		else
		{
			this.date = d;
		}
	}
	public abstract Date getDate();
	
}

package autoCompleter.test;


public class SimpleBean
{

    private Integer _id;
    
    private String _label;
    
    private int _value;
    
    public SimpleBean(Integer id, String label, int value)
    {
        _id = id;
        _label = label;
        _value = value;
    }
    
    /**
     * @return the id
     */
    public Integer getId()
    {
        return _id;
    }
    
    /**
     * @return the label
     */
    public String getLabel()
    {
        return _label;
    }
    
    /**
     * Returns the value stored.
     * 
     * @return The value stored.
     */
    public int getValue()
    {
        return _value;
    }

    /** 
     * {@inheritDoc}
     */
    @Override
    public int hashCode()
    {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result + ((_id == null) ? 0 : _id.hashCode());
        return result;
    }
    
    /** 
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj)
    {
        if (this == obj) return true;
        if (obj == null) return false;
        if (getClass() != obj.getClass()) return false;
        final SimpleBean other = (SimpleBean) obj;
        if (_id == null) {
            if (other._id != null) return false;
        } else if (!_id.equals(other._id)) return false;
        return true;
    }
}

0 请登录后投票
   发表时间:2007-02-12  
发觉这个autocomplete的显示速度超慢
0 请登录后投票
   发表时间:2007-09-07  
请问楼主,为什么我复制你的代码,运行后并没有看到列表显示的内容,而且一输入就会在列表框下面显示以下信息:

DEBUG:  please consider using a mimetype of text/json-comment-filtered to avoid potential security issues with JSON endpoints

楼主能不能告诉我是哪里出问题了,可以的话,autocomplete的用法原理也一并解释一下,看了源码,理解了一点点...谢谢!
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics