开发者

AutoSuggest component in standard JSF 2.0 component set

Is 开发者_如何学JAVAthere a Google-like autosuggest input component in standard JSF 2.0 component set?


The standard JSF <h:xxx> component set doesn't have such a component. All it offers are just basic HTML elements. An autosuggest field is basically a combination of an <input type="text"> and an <ul><li> of items which is created and positioned by JavaScript and filled by Ajax and styled by a good shot by CSS. This is not a single basic HTML element.

Implementing your own isn't exactly trivial if you're new to JSF. Simplest would be to create a composite component with a <h:inputText> and add the necessary JS/CSS code yourself. Fortunately, there exist JSF component libraries which adds just that extra on top of the standard JSF components and often already provides such a component out the box. For example:

  • RichFaces: <rich:autocomplete>
  • PrimeFaces: <p:autoComplete>
  • OpenFaces: <o:suggestionField>
  • IceFaces: <ice:selectInputText>

(note: all tags above are clickable and show you the online demo)


If you don't wish to add a component library to your JSF project, you could instead integrate the jQuery autocomplete widget. This is a client-side JavaScript solution which is agnostic to the server-side technology. Adding this widget will therefore have little on no impact on your server-side code.

http://jqueryui.com/demos/autocomplete/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜