什么时候应该使用f:viewActionor preRenderView事件来初始化页面的数据而不是使用@PostConstruct注释?基于支持bean的范围类型使用一个或另一个的基本原理例如,如果支持bean是@RequestScoped,那么在呈现视图之前选择使用f:viewAction或preRenderView覆盖@PostConstruct初始化支持bean是不相关的,因为两者会结果是一样的吗?
f:viewAction或preRenderView
<f:metadata>
<f:viewAction action="#{myBean.initialize}" />
</f:metadata>
Run Code Online (Sandbox Code Playgroud)
<f:metadata>
<f:event type="preRenderView" listener="#{myBean.initialize}"/>
</f:metadata>
Run Code Online (Sandbox Code Playgroud)
要么
@PostConstruct
public class MyBean
{
@PostConstruct
public void initialize()
{
}
}
Run Code Online (Sandbox Code Playgroud) 在JSF 2对注释的大力支持之后,我想知道我将使用它faces-config.xml.它现在的重要性是什么?
换句话说,只能faces-config.xml通过注释而不是通过注释完成哪些配置?
现在我用它的所有东西都是声明Spring的EL解析器.
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
</faces-config>
Run Code Online (Sandbox Code Playgroud) 有没有办法从JSF支持bean动作方法提供文件下载?我尝试过很多东西.主要问题是我无法弄清楚如何获取OutputStream响应以便将文件内容写入.我知道如何使用a Servlet,但这不能从JSF表单调用,需要新的请求.
如何OutputStream从当前获得响应FacesContext?
以下两段代码之间有什么区别 - 关于listener放置?
<h:selectOneMenu ...>
<f:selectItems ... />
<f:ajax listener="#{bean.listener}" />
</h:selectOneMenu>
Run Code Online (Sandbox Code Playgroud)
和
<h:selectOneMenu ... valueChangeListener="#{bean.listener}">
<f:selectItems ... />
</h:selectOneMenu>
Run Code Online (Sandbox Code Playgroud) 我想在我的JSF页面中使用非中断空格.我知道,在纯HTML中,我可以使用 这个,这很好.但是,当我将它们 放在Facelets页面中时,它会出现如下错误:
错误解析/page.xhtml:错误跟踪[第42行]引用了实体"nbsp",但未声明.
这是怎么造成的,我该如何解决?
我在JSF2中编程,netbeans创建了许多#{}包含表达式的页面.
但有时在网上我发现${}同样的事情!
有什么不同吗?这些是什么?
Google会忽略这些字符#{},${}因此难以搜索.
在JSF中有很多材料区分value属性和binding属性.
我对这两种方法如何彼此不同感兴趣.鉴于:
public class User {
private String name;
private UICommand link;
// Getters and setters omitted.
}
Run Code Online (Sandbox Code Playgroud)
<h:form>
<h:commandLink binding="#{user.link}" value="#{user.name}" />
</h:form>
Run Code Online (Sandbox Code Playgroud)
value指定属性时会发生什么变化.getter运行以返回bean 的name属性值User.该值将打印到HTML输出.
但我无法理解它是如何binding运作的.生成的HTML如何维护与bean link属性的绑定User?
下面是手动美化和注释后生成的输出的相关部分(注意id j_id_jsp_1847466274_1是自动生成的,并且有两个隐藏的输入小部件).我正在使用Sun的JSF RI 1.2版.
<form action="/TestJSF/main.jsf" enctype="application/x-www-form-urlencoded"
id="j_id_jsp_1847466274_1" method="post" name="j_id_jsp_1847466274_1">
<input name="j_id_jsp_1847466274_1" type="hidden" value="j_id_jsp_1847466274_1">
<a href="#" onclick="...">Name</a>
<input autocomplete="off" id="javax.faces.ViewState" name="javax.faces.ViewState"
type="hidden" value="-908991273579182886:-7278326187282654551">
</form>
Run Code Online (Sandbox Code Playgroud)
在哪里binding存放在这里?
在JSF 2中,h:button和之间有什么区别h:commandButton?
我有这个结构:
WebContent
resources
components
top.xhtml
company
about_us.xhtml
index.xhtml
Run Code Online (Sandbox Code Playgroud)
top.xhtml是一个组件,即在使用index.xthml与about_us.xhtml太.
top.xhtml
<ul>
<li><a href="index.xhtml">Home</a></li>
<li><a href="company/about_us.xhtml">About us</a></li>
...
</ul>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,当当前页面是index.xhtml组件正确生成URL时,但当当前页面时about_us.xhtml,它会生成错误的URL.我不能使用相对路径,因为它也会生成错误的URL.我认为这是因为组件基于*.xhtml页面的当前路径.
我能找到的唯一解决方案是:
<ul>
<li><a href="${pageContext.request.contextPath}/webname/index.xhtml">Home</a></li>
<li><a href="${pageContext.request.contextPath}/webname/about_us.xhtml">About us</a></li>
...
</ul>
Run Code Online (Sandbox Code Playgroud)
但我认为根本不是"优雅".有任何想法吗?
jsf-2 ×10
jsf ×9
ajax ×1
binding ×1
button ×1
components ×1
download ×1
el ×1
facelets ×1
faces-config ×1
java ×1
listener ×1
viewaction ×1