0

Sorry for my english. Does not work <h:commandLink> with <f:ajax>.

test.xhtml:

<h:form enctype="multipart/form-data" prependId="false">

    <h:inputFile id="file" label="file" value="#{testMB.file}" required="true">
        <f:ajax event="blur" render="fileMessage"/>
    </h:inputFile>

    <h:message for="file" id="fileMessage" styleClass="message-error"/>

    <h:outputText value="#{testMB.date}" id="date" />

    <h:commandLink action="#{testMB.upload}">
        <f:ajax execute="file" render="fileMessage date" />
        upload
    </h:commandLink>

</h:form>

Class TestMB:

@ManagedBean(name="testMB")
@ViewScoped
public class TestMB {

    private Part file;

    public String date;

    public void upload() {

        try{
            Thread.sleep(Long.valueOf("5000"));
            this.date = "1111111111111111111";
        }catch(Exception ex){

        }
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public Part getFile() {
        return file;
    }

    public void setFile(Part file) {
        this.file = file;
    }

}

I open test.xhtml and choose a file. If I click on link "upload", then sending is not working. If you click again, the link will not work, need to reload this page.

If I open page test.xhtml and choose a file. And I click on "empty space" to work checking <f:ajax event="blur" render="fileMessage"/>. And if I click on link "upload", then sending is working.

What is the problem? Please help me.

Tiny
  • 27,221
  • 105
  • 339
  • 599
  • You tagged [jsf-2]. File upload using `` requires JSF 2.2 which in turn requires a minimum of Servlet 3.0 (a minimum of JDK 1.6). `` internally uses this Servlet API (3.0 or higher) to upload files without the need to have third party libraries. What versions of JSF and Servlet do you happen to use? – Tiny Jan 18 '15 at 17:31
  • I use servlet 3.1.0 and JSF 2.2.4. – sergey ivanov Jan 18 '15 at 17:48

1 Answers1

0

I updated JSF 2.2.4 to JSF 2.2.6. If I choose a file and click on link "upload", then sending is not working. But if I click again, then sending is working.

I changed <f:ajax event="blur" render="fileMessage"/> to <f:ajax event="change" render="fileMessage"/>. And sending is working with the first click.