阿贾克斯监听器不工作INPUTFILE监听器、工作、阿贾克斯、INPUTFILE

2023-09-10 22:11:19 作者:埘茪夿涐苁話唠変晟啞夿

首先,我使用JSF 2.2.7和GlassFish 4在NetBeans 8.0。 其次,对不起,如果我留下任何有用的信息了。这是我在这里的第一个问题,所以我可能忘了什么东西。另外,英语不是我的第一语言。对不起,错字/语法。

First of all, I'm using JSF 2.2.7 and GlassFish 4 in NetBeans 8.0. Second, sorry if I left any useful info out. This is my first question in here, so I may forget something. Also, english isn't my first language. Sorry for typos/grammar.

所以,这里是我的问题:我上传与.h文件:INPUTFILE,我需要一个Ajax侦听它 注意到,这是不工作如我所料,我决定做一个打印测试的监听一些测试,但它从来没有发射与H:INPUTFILE。我试着与H:的commandButton和h:commandLink,他们都做工精细。 为了进一步测试,我创建使用相同的测试code一个新的项目,一切工作,包括在H听众:INPUTFILE

So, here's my problem: I'm uploading files with h:inputFile and I need an ajax listener for it. After noticing that it wasn't working as I expected, I decided to do some testing with a listener that prints "Test", but it's never fired with h:inputFile. I've tried with h:commandButton and h:commandLink and they both work fine. For further testing, I created a new project using the same test code and everything works, including the listener in h:inputFile.

我想知道的是,为什么它不能在我的主要项目工作,以及为什么它在测试项目。我在想什么吗?我怎样才能让它在我的主要项目工作?

What I want to know is why it doesn't work in my main project and why it works in the test project. What am I missing here? And how can I make it work in my main project?

下面是一些(但不是全部,因为我失去了跟踪)检查,到目前为止,我已经尝试过的东西/寻找答案后:

Here are some (but not all, since I lost track) things that I've tried/checked so far, after looking for answers:

没有嵌套形式。该XHTML是在UI:成分,但即使考虑到这一点,没有嵌套的表格 在它的形式拥有的 ENCTYPE =的multipart / form-data的的 在我试图改变方法的 uploadTest(AjaxBehaviorEvent事件)的与听众的监听=#{submitFormBean.uploadTest}的[无()] 在我玩过的各种的事件=...和执行=...的(没想到它会解决我的问题,但是,好吧,我不得不尝试) There are no nested forms. The said xhtml is in a ui:composition, but even taking that into account, there are no nested forms. Its form has enctype="multipart/form-data" I've tried changing the method to uploadTest(AjaxBehaviorEvent event) and the listener to listener="#{submitFormBean.uploadTest}" [without the ()] I've played with the various event="..." and execute="..." (didn't think it would solve my problem, but, well, I had to try)

在code如下所示:

XHTML

<h:form>
    <h:commandButton id="btnTest">
        <f:ajax listener="#{submitFormBean.uploadTest()}"/>` --> works in both projects`
    </h:commandButton>
</h:form>
<h:form>
    <h:commandLink id="lnkTest" value="Test">
        <f:ajax listener="#{submitFormBean.uploadTest()}"/>` --> works in both projects`
    </h:commandLink>
</h:form>
<h:form enctype="multipart/form-data">
    <h:inputFile id="fileTest">            
        <f:ajax listener="#{submitFormBean.uploadTest()}"/>` --> works only in test project`
    </h:inputFile>
</h:form>

@ViewScoped
@ManagedBean(name = "submitFormBean")
public class SubmitFormBean{

    public SubmitFormBean() {
    }

    public void uploadTest(){
        System.out.println("Test");
    }
}

在此先感谢!

Thanks in advance!

推荐答案

我正要做什么,我需要在jQuery的,但首先我决定尝试下,它解决了我的问题:

I was about to do what I needed in jQuery, but first I decided to try the following and it solved my problem:

右键单击项目/属性/库 在编译的标签,我删除和重新添加的JSF 2.2.7的.jar

right click project/properties/libraries in the compile tab, I removed and readded the JSF 2.2.7 .jar

这已经在那里了,但由于某种原因不能正常工作。我还是不知道哪里出了问题,但它现在的工作。

It was already there, but for some reason wasn't working. I still don't know what went wrong, but it's working now.