gpt4 book ai didi

java - JSF 在 View 根目录中找不到具有表单 ID 的组件

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:35:14 26 4
gpt4 key购买 nike

我在表单中有一个 t:inputFileUpload,在显示页面的 html 中,此组件的 id 是 form:inputFile 但是当我尝试使用“form:inputFile”从 View 根目录获取组件时,返回为 null ,但是当删除“表单:”时,返回的是组件。组件没有在我的托管 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 中使用“查看源代码”时,这个组件的 ID 是“form:inputFile”。

我不知道这是否相关,但是组件没有在我的托管 bean 中设置值,而且组件的 ID 与 HTML 源代码不同这一事实很奇怪。我正在使用 JSF 1.2 Mojarra。其他人有这个问题吗?或者知道为什么会这样吗?

编辑2:好吧,我很愚蠢,显然构建没有正常工作,当构建从 Ant 更改为其他任务时它起作用了(仍然不知道为什么,但只是起作用了)。抱歉给您带来麻烦。

最佳答案

您应该使用组件 bindingUIViewRoot#findComponent() .但这并不能解决上传文件未设置的问题。要修复它,第一步是确保您根据 Tomahawk documentation 正确定义和配置了 ExtensionsFilter ,因为它负责解析 multipart/form-data 请求并将所有参数与上传的文件放回请求参数映射中,因此 FacesServlet 可以应用它们并更新模型值。

关于java - JSF 在 View 根目录中找不到具有表单 ID 的组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2580837/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com