开发者

When should I use JSF components and when should I use html tags? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. 开发者_Go百科

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 4 years ago.

Improve this question

I would like to design a webpage using JSF.

Some parts of the page I can layout using <h:panelGroup> and <h:panelGrid> or, instead, I can use <p>, <div>, etc instead.

Just wondering which is preferable for best practices.

Thanks!


If you don't need the features provided by the JSF tag, I'd prefer to use plain HTML.

For example, <h:panelGroup> has a rendered attribute that allows you bind to a backing bean boolean variable to conditionally display the output, but with a <div> or <span>, you cannot do this.

The <h:panelGroup> will by default generate a <span>. If you prefer a <div>, then you can use <h:panelGroup layout="block">. It will generate a <div>for you .


Just recent case from my practise:

1. for <p> and <div> you can't use rendered attribute

2. make your code more structural and solid - to be easy-readable for other users of your code


There is a recommendation to not mix up jsf with html. Background: Then your jsf page can be rendered as something different than html. But as far as I know up till now there are only renderers for html (although you can write your own).

In practice I found it hard to follow this recommendation and ended up mixing html and jsf, e.g. for headings or line breaks I use html.


As a general rule, I use a mix betweek HTML and Facelets tags in the layout pages. But for the actual content pages I try to only use the JSF tags available with my JSF library of choice (JSF + RichFaces).

That way I can have more control of which elements to show and hide, as well as the contents within each element, but I can still hard-code my main page layout in the facelets template file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜