我正在做一个 JSF2 项目。我使用 mojarra 2.x、PrimeFaces 2.2RC2、Tomcat 6.x 和 Google Guice。
-
目前我使用命令链接来浏览我的网站,因此每次我想重新加载时,导航器都会要求重新提交值。我在网上看到可以重定向。使用outputlink或commandlink进行导航是否更好?
-
很多时候我使用带有参数的操作,如下所示:
<:commandlink action="#{bean.doSomething(item)}" />
这是好还是坏?
-
JSF 中是否有一些命名操作、属性的约定?或者你的约定是什么?
-
当我编写 xhtml 页面时,是只使用组件更好还是只在必要时使用?
示例
<前><代码>#{bean.foo}
或
使用
这样的 JSTL 标签怎么样?我使用一些是因为在恢复视图期间使用
时遇到了一些问题。
I'm doing a JSF2 project. I use mojarra 2.x, PrimeFaces 2.2RC2, Tomcat 6.x and Google Guice.
-
For the moment I use commandlink to navigate through my site, so everytime I want to reload, the navigator ask for resubmit value. I see on the net that it's possible to redirect. Does it better to use outputlink or commandlink for navigation?
-
Many times I use action with parameter like this:
<:commandlink action="#{bean.doSomething(item)}" />
This is good or bad ?
-
Is there is some conventions in JSF for naming action, properties? Or what's your convention?
-
When I write a xhtml page, does it better to use only components or just when necessary ?
Example
#{bean.foo}
or
<h:outputText value="#{bean.foo}" />
-
What about the use of JSTL tags like <c:if>
? I use some because I had some problems when I use <ui:fragment rendered="">
during restoring view.
发布评论
评论(1)
触发 POST 请求。这对于页面到页面的导航没有意义。它对用户不友好,对 SEO 也不友好。只需使用
、
甚至即可触发普通 HTTP GET 请求。
如果
item
已经存在于#{bean}
后面的实例中,那么这是不必要的。如果不是,那就完全没问题了。您只需要记住,您的代码在这种情况下不再向后兼容 Servlet 2.5 容器,而 JSF 2.0 本身则向后兼容 Servlet 2.5。它是 Servlet 3.0 / EL 2.2 功能(我只是想知道你如何让它在 Tomcat 6 上运行。你不是使用 Tomcat 7 还是使用 JBoss EL?)。我不会太在意,例如
ProductManager
、ProductController
、Products
等,只要尽可能多即可从视图端开始自我记录。即不是#{pc.submit}
或#{pd.column1}
,而是#{products.find}
和#{产品.名称}
.在 Facelets 中,两者同样有效。两者都是 XML 转义的。
的唯一优点是它允许通过UIViewRoot
轻松访问并添加styleClass
、id< 等属性/code>、
渲染
等只要您仅在想要控制视图构建方式而不是视图渲染方式时使用它,那就完全没问题。请注意,这些
http://java.sun.com/jstl/core
标记是由 Facelets 本身提供的,而不是由优秀的 JSP JSTL JAR 提供的(它具有/jsp
在 taglib URI 中)。相关
h:outputLink< /code> 而不是
h:commandLink
?h:dataTable
内的 JSTLc:if
<h:commandLink>
fires a POST request. This makes no sense for page-to-page navigation. It's not user friendly nor SEO friendly. Just use<h:outputLink>
,<h:link>
or even<a>
which fires a plain HTTP GET request.If
item
is already present in the instance behind#{bean}
then this is unnecessary. If it's not, then it's perfectly fine. You only need to keep in mind that your code is this way not backwards compatible on Servlet 2.5 containers anymore while JSF 2.0 itself is backwards compatible on Servlet 2.5. It's namely a Servlet 3.0 / EL 2.2 feature (I only wonder how you get it to run on Tomcat 6. Aren't you using Tomcat 7 or are you using JBoss EL?).I wouldn't care that much, e.g.
ProductManager
,ProductController
,Products
, etc, as long as it is as much as possible self-documenting from the view side on. I.e. not#{pc.submit}
or#{pd.column1}
, but#{products.find}
and#{product.name}
.In Facelets, both are equally valid. Both are XML-escaped. The
<h:outputText>
only has the advantage that it allows easy access byUIViewRoot
and adding attributes likestyleClass
,id
,rendered
, etc.As long as you use it only when you want to control how the view is built, not how view is rendered, then it's perfectly fine. Note that those
http://java.sun.com/jstl/core
tags are provided by Facelets itself, not by good ol' JSP JSTL JAR's (which has/jsp
in taglib URI).Related
h:outputLink
instead ofh:commandLink
?c:if
inside JSFh:dataTable