将页面中的常见字符串值重构为某些 EL 常量
在 JSF 组件中,将常见常量(例如
标记中的名称/路径“重构”为单个本地临时属性的最佳方法是什么?
<ui:composite>
<h:graphicImage library="mylib" name="/a/b/c/img1.png"/>
<h:graphicImage library="mylib" name="/a/b/c/img2.png"/>
<h:graphicImage library="mylib" name="/a/b/c/img3.png"/>
<!-- ... lots of repetitions -->
</ui:composite>
应该是
<ui:composite>
<-- assign /a/b/c/ to path -->
<h:graphicImage library="mylib" name="#{path}img1.png"/>
<h:graphicImage library="mylib" name="#{path}img2.png"/>
<h:graphicImage library="mylib" name="#{path}img3.png"/>
<!-- ... lots of repetitions -->
</ui:composite>
In a JSF component what is the best way to "refactor" common constants, e.g. names/paths in a <h:graphicImage>
tag to a single local, temporary property?
<ui:composite>
<h:graphicImage library="mylib" name="/a/b/c/img1.png"/>
<h:graphicImage library="mylib" name="/a/b/c/img2.png"/>
<h:graphicImage library="mylib" name="/a/b/c/img3.png"/>
<!-- ... lots of repetitions -->
</ui:composite>
should be
<ui:composite>
<-- assign /a/b/c/ to path -->
<h:graphicImage library="mylib" name="#{path}img1.png"/>
<h:graphicImage library="mylib" name="#{path}img2.png"/>
<h:graphicImage library="mylib" name="#{path}img3.png"/>
<!-- ... lots of repetitions -->
</ui:composite>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
;
关于应用范围。这基本上将变量存储在 应用程序映射中。确保
var="path"
不与现有托管 Bean 名称或隐式 EL 变量等冲突。如有必要,您可以使用约定在其前面添加_
。Use
<c:set>
on application scope. This basically stores the variable in the application map.Make sure that the
var="path"
doesn't conflict with existing managed bean names or implicit EL variables and such. You could if necessary use a convention to prefix it with_
.为什么不使用复合组件。然后,当发生变化时,您不必到处更改 img1.png、img2.png 等。该路径可以作为参数提供。
Why not using a composite component. Then you don't have to change the img1.png, img2.png, ... etc all over the place when that changes. The path can the be supplied as a parameter.