2011-11-23 49 views
0

在wicket中是否有可能使調色板充當自動完成?在wicket中使用自動完成的調色板模型

+0

會是什麼意思一個調色板作爲自動完成? –

+1

我使用wicket框架,並且我的頁面中有一個Palette模型(這是一個交換框,您可以從列表中選擇項目到另一個列表中,http://wicketstuff.org/wicket13/compref/;jsessionid=0C21DAE33AEA747F88B44AC8A44A5F35? wicket:bookmarkablePage =:org.apache.wicket.examples.compref.PalettePage),我希望它是自動完成的,這意味着當用戶輸入「a」時,它提供了所有以a開頭的選項。 –

+0

當用戶輸入「a」在哪裏?在與調色板相關的文本框中?那麼從左邊開始的選項會出現在左邊? –

回答

2

啞了,是的,你可以將其安靜的困難,我做到了幾個月前其沒有完全相同的代碼,但希望幫助:

你需要一個表單提交搜索位置字段,然後修改模型和最後重繪你需要什麼

原始類是寫在西班牙語對不起任何奇怪的事情:S

public SearchPallete() { 

currentMedics = database action 


avaibleMedics = new LoadableDetachableModel<Collection<? extends YourModel>>() { 

    private static final long serialVersionUID = 1L; 
    private List<YourModel> res; 

    @Override 
    protected Collection<? extends YourModel> load() { 
    res = get from database list of avaibles; 



    res.addAll(add current assigned model); 

    return res; 

    } 
}; 
//form for auto submit with ajax (it could be refactor) 
ajaxFormPallet = new AjaxFormSubmitBehavior(palleteForm, "onchange") { 

    private static final long serialVersionUID = -4029493502490267181L; 

    @Override 
    protected void onSubmit(AjaxRequestTarget target) { 


    } 

    @Override 
    protected void onError(AjaxRequestTarget target) { 

    } 
}; 

IChoiceRenderer<YourModel> renderer = new ChoiceRenderer<YourModel>(
    "field", "field"); 
pallete = new Palette<YourModel>("pallete", 
    currentMedics, avaibleMedics, renderer, 10, false) { 

    private static final long serialVersionUID = 1L; 

    protected Recorder<YourModel> newRecorderComponent() { 
    Recorder<YourModel> recorder = super 
     .newRecorderComponent(); 
    recorder.add(ajaxFormPallet); 
    return recorder; 
    } 

    @Override 
    protected ResourceReference getCSS() { 
    return new PackageResourceReference(MedicosTratantesPage.class, 
     "theStyle"); 
    } 

}; 
//for ajax 
pallete.setOutputMarkupId(true); 

    //pallete form 
palleteForm = new Form<FormMedicosTratantesModel>("palleteForm") { 
    private static final long serialVersionUID = 5036201492891006829L; 


    @SuppressWarnings("unchecked") 
    protected void onSubmit() { 
    //search and submit stuff 

    } 
}; 

searchField = new TextField<String>("Buscador", thethingToFind); 

searchForm = new Form<String>("searchForm") { 
    private static final long serialVersionUID = 1L; 

    protected void onSubmit() { 
    pallete.detachModels(); 

    } 
}; 
searchForm.add(searchField); 

searchField.add(new AjaxFormSubmitBehavior(searchForm, "onkeyup") { 
    private static final long serialVersionUID = 7939356732729920901L; 

    @Override 
    protected void onSubmit(AjaxRequestTarget target) { 
    log.debug("searchField cambio"); 
    target.add(pallete); 
    } 

    @Override 
    protected void onError(AjaxRequestTarget target) { 

    } 
}); 
add(palleteForm); 
add(searchForm); 
palleteForm.add(pallete); 

} 
+0

謝謝,不幸的是我不明白你做了什麼!我要問一個關於在wicket內的文本區域中自動完成的可能性的新問題。 –