[英]JSF don't find component in view root with the form id
我在:inputFileUpload里面的表单,在显示页面的html中,这个组件的id是form:inputFile但是当我试图从视图根目录中使用“form:inputFile”获取组件时返回为null,但是当删除“form:”返回的是组件。 组件没有在我的托管bean中设置值,有人有这个问题吗?
编辑:
<h:form id="form" enctype="multipart/form-data">
<t:inputFileUpload id="inputFile" size="40" value="#{managedBean.inputFile}"/>
</h:form>
在托管bean中:
private UploadedFile inputFile;
使用Eclipse提供的gets和sets。
//This method scans the view root and returns the component with the id passed as parameter
findComponentInRoot("form:inputFile");
这返回null,但是当我使用时:
//This method scans the view root and returns the component with the id passed as parameter
findComponentInRoot("inputFile");
返回是我正在寻找的组件,但是当我在Internet Explorer中使用View Source时,该组件的id是“form:inputFile”。
我不知道这是否相关,但组件没有在我的托管bean中设置值,并且奇怪的是组件的id与HTML源不同。 我正在使用JSF 1.2 Mojarra。 有人有这个问题吗? 或者知道为什么会这样?
编辑2:好的,我非常愚蠢,显然构建工作不正常,当构建从Ant更改为其他任务时它工作(仍然不知道为什么,但只是工作)。 抱歉,添麻烦了。
您应该使用组件binding
或UIViewRoot#findComponent()
。 但这不能解决上传文件未设置的问题。 要修复它,第一步是确保根据Tomahawk文档正确定义和配置ExtensionsFilter
,因为它是负责解析multipart/form-data
请求并将所有参数放回上传文件的人。请求参数映射,以便FacesServlet
可以应用它们并更新模型值。
我猜findComponentInRoot
就是这个 (你应该共享的一个小细节)。
无论如何,使用findComponent(..)
或getChildren(..)
始终返回页面中定义的组件的id
。 html id是不同的,它由naming container:id
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.