我目前正在寻找使用Java Server Faces上传的文件.我发现使用RichFaces对它进行了很好的介绍.但是,我在这里理解这个过程有些麻烦.
首先,用户选择一个文件,如果立即上传设置为true,则使用ajax处理文件,到目前为止一直很好.然而,当谈到下一步时,Bean端的监听器会让我困惑:
public void listener(UploadEvent event) throws Exception{
UploadItem item = event.getUploadItem();
File f = item.getFile();
System.out.println(f.getAbsolutePath());
}
Run Code Online (Sandbox Code Playgroud)
绝对路径是我计算机上的临时目录,确定我理解,但是如何使该文件可用于webbapplication?我的应用程序部署为WAR文件.是否可以将其上传到WAR?可能听起来很愚蠢,但它实际上可能很方便.
我完全知道我可以重命名该文件以将其复制到新位置,但这是要走的路吗?
我已经使用RichFaces和JSF进行了一段时间的编程,并且像Facelets提供的功能(特别是作为JSF 2的一部分),但尚未使用它.RichFaces和Facelets之间是否存在任何需要注意或不兼容的问题?我作为RichFaces的一部分使用A4J ajax功能,所以我也很关心.
提前致谢.
我强烈需要覆盖JSF 2.0 Content-Type标头.默认是
Content-Type:application/xhtml+xml; charset=UTF-8
Run Code Online (Sandbox Code Playgroud)
但是我需要
Content-Type:text/html; charset=UTF-8
Run Code Online (Sandbox Code Playgroud)
谢谢.
我在我的Web应用程序上有这个配置.2豆:
1°Bean - 它检查登录;
@ManagedBean(name="login")
@SessionScoped
public class Login {
private String nickname;
private String password;
private boolean isLogged;
public String getNickname() { return nickname; }
public void setNickname(String newValue) { nickname=newValue; }
public String getPassword() { return password; }
public void setPassword(String newValue) { password=newValue; }
public void checkLogin() {
... i check on db the nickname and the password ...
if(USER EXIST) {
isLogged=true;
} else {
isLogged=false;
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
2°Bean - 管理用户参数:
@ManagedBean(name="user")
@SessionScoped …Run Code Online (Sandbox Code Playgroud) 到目前为止,我在书或教程中看到的每个项目示例都将XHTML(Facelets)页面与WEB-INF目录放在同一级别上.我还读过,为了让服务器上的页面无法直接访问,你需要将它们隐藏在WEB-INF目录下,这意味着需要某种视图解析器.我的问题是,我该怎么做?
我有一个简单的Facelet标签:
<ui:composition>
<ui:insert />
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
这是为了避免声明多个c:set标签.
假设我在facelets taglib库中使用名称注册它view,并像这样使用它:
<my:view bean="#{myController}">
<p:inputText value="#{bean.value}>
<p:ajax event="blur" process="@this" listener="#{bean.handleValueChanged}" />
</p:inputText>
</my:view>
Run Code Online (Sandbox Code Playgroud)
该属性value完全由你解决p:inputText,但p:ajax抛出这个:
Target Unreachable, identifier 'bean' resolved to null
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'bean' resolved to null
at com.sun.el.parser.AstValue.getTarget(AstValue.java:153)
at com.sun.el.parser.AstValue.invoke(AstValue.java:237)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:47)
Run Code Online (Sandbox Code Playgroud)
这是一个错误或预期的行为?
更新:我刚用f:ajax尝试了同样的工作!
顺便说一句,环境如下:
Glassfish 3.1.2
PF 3.0,3.2,3.3
Update2:
这个问题RichFaces完全相同.似乎就像PrimeFaces的bug(我今天会在PF bug跟踪器上发布一个问题).
如何定义facelet模板参数的默认值?使用模板参数考虑以下元素:
<h:outputText value="#{templParam}"></h:outputText>
Run Code Online (Sandbox Code Playgroud)
上面的行将打印模板参数templParam ,该参数由使用模板的ui:param标签传递ui:composition:
<ui:param name="templParam" value="Hello world"></ui:param>
Run Code Online (Sandbox Code Playgroud)
但如果ui:param缺少标签,则不会打印任何内容.虽然,在这种情况下如何打印例如"默认值"?
我需要在我的JSF应用程序error.xhtml页面中显示异常堆栈跟踪.我知道用JSP页面做这件事有多简单.但是使用JSF 2.0我有一个问题.
在我的web.xml我已经定义了一个JSF 2.0 Facelets页面作为错误页面:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/faces/views/error.xhtml</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
当错误发生时,我被重定向到此页面.我需要的是在此Facelets页面中显示异常的堆栈跟踪.
我试过用:
<pre>
<h:outputText value="${exception}"/>
</pre>
Run Code Online (Sandbox Code Playgroud)
但我没有得到任何输出.我一直在网上搜索,但我找不到解决方案.如何在Facelets页面中显示异常堆栈跟踪?
编辑:
我刚尝试过:
<c:forEach var="exeption" items="${exception.stackTrace}">
<div>${exeption}</div>
</c:forEach>
<h:dataTable value="#{exception.stackTrace}"
var="exception">
<h:column>
<h:outputText value="#{exception}"/>
</h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)
JSTL无法正常工作并通过数据表进行交互也无法正常工作.我确定发生异常,我在日志文件中看到它.
现在,我用jsf,spring和ibatis编写示例应用程序.我使用facelets并编写template.xhtml,header.xhtml,menu.xml,login.xhtml和主页.登录后,我发现了这个错误.
在浏览器中,
Setter not found for property class
+ Stack Trace
+ Component Tree
+ Scoped Variables
Run Code Online (Sandbox Code Playgroud)
在控制台中,
21:01:20,890 SEVERE [viewhandler] Error Rendering View[/view/SPAR02.xhtml]
java.lang.IllegalArgumentException: Setter not found for property class
at javax.faces.component.UIComponentBase$AttributesMap.put(UIComponentBase.java:1645)
at javax.faces.component.UIComponentBase$AttributesMap.put(UIComponentBase.java:1526)
at com.sun.facelets.tag.jsf.ComponentRule$LiteralAttributeMetadata.applyMetadata(ComponentRule.java:49)
at com.sun.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:36)
at com.sun.facelets.tag.MetaTagHandler.setAttributes(MetaTagHandler.java:62)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:144)
at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
at com.sun.facelets.tag.jstl.core.ForEachHandler.apply(ForEachHandler.java:175)
at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
at com.sun.facelets.tag.UserTagHandler.apply(UserTagHandler.java:122)
at com.sun.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:337)
at com.sun.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:307)
at com.sun.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:68)
at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
at com.sun.facelets.tag.jstl.core.ChooseWhenHandler.apply(ChooseWhenHandler.java:45)
at com.sun.facelets.tag.jstl.core.ChooseHandler.apply(ChooseHandler.java:68)
at com.sun.facelets.tag.jstl.core.ChooseOtherwiseHandler.apply(ChooseOtherwiseHandler.java:41)
at com.sun.facelets.tag.jstl.core.ChooseHandler.apply(ChooseHandler.java:73)
at …Run Code Online (Sandbox Code Playgroud) 我已将我的应用程序从JSF 1.2迁移到2.2.
它在java.sun.com域 上使用XML命名空间xmlns:f="http://java.sun.com/jsf/core".但是,Oracle的Java EE 7教程正在使用xmlns.jcp.org域名
上的XML命名空间xmlns:f="http://xmlns.jcp.org/jsf/core".
推荐哪一个,为什么会改变?