简体   繁体   English

h:form enctype =“ multipart / form-data”不执行任何操作

[英]h:form enctype=“multipart/form-data” not firing any action

Im using JSF and i have this problem that the h:commandButton not firing any action from the side of the managed bean when the form has te attibute enctype="multipart/form-data", when i remove that attribute is work fine. 我正在使用JSF,但我有一个问题:当我删除该属性时,h:commandButton在表单具有atti enctype =“ multipart / form-data”时不从托管bean的一侧触发任何操作。 But that is not what i do, because i use fileupload. 但这不是我要做的,因为我使用fileupload。

Here is my form: 这是我的表格:

    <h:form enctype="multipart/form-data" class="form-horizontal" id="form-catastrofe">
        <p:growl id="messages" showDetail="true" />
        <div class="form-group">
            <div class="col-sm-12">
                <p:fileUpload fileUploadListener="#{catastrofeBean.handleFileUploadImagen}" mode="advanced" dragDropSupport="false"
                        multiple="false" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
                        label="Elegir Icono"
                        cancelLabel="Cancelar"
                        update="messages" />
                    </div>
            </div>
        <div class="form-group">
            <div class="col-sm-12"> 
                <p:inputText id="inputname" value="#{catastrofeBean.catastrofe.nombre}" required="true" label="Name" styleClass="form-control">
                  <f:validateLength minimum="2" />
                </p:inputText>
                <p:watermark for="inputname" value="Nombre de Evento" id="watermarkName" />
            </div>
        </div>
        <div class="form-group">
           <div class="col-sm-12">  
              <p:inputText id="inputdescripcion" value="#{catastrofeBean.catastrofe.descripcion}" required="true" label="Name" styleClass="form-control"/>
              <p:watermark for="inputdescripcion" value="Descripcion" id="watermarkDesc" />
           </div>
        </div>
        <div class="form-group">
           <div class="col-sm-12">                      
              <p:inputText id="inputdireccion" value="#{catastrofeBean.catastrofe.direccion}" required="true" label="Name" styleClass="form-control"/>
              <p:watermark for="inputdireccion" value="Direccion" id="watermarkDireccion" />           
           </div>
        </div>
        <div class="form-group">
           <div class="col-sm-12">
             <p:fileUpload fileUploadListener="#{catastrofes.handleFileUpload}" mode="advanced" dragDropSupport="false"
             multiple="true" allowTypes="/(\.|\/)(pdf)$/"
             label="Elegir Plan"
             cancelLabel="Cancelar"
             update="messages" />
           </div>
        </div>    
        <h:commandButton value="Ingresar Catástrofe" action="#{catastrofeBean.update}" class="pull-right btn btn-success"></h:commandButton>
   </h:form>

And here is my web.xml: 这是我的web.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>catastrophes-system-web</display-name>
<context-param>
  <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
  <param-value>true</param-value>
</context-param>
<context-param>
  <param-name>primefaces.THEME</param-name>
  <param-value>bootstrap</param-value>
</context-param>
<context-param>
  <param-name>primefaces.UPLOADER</param-name>
  <param-value>auto</param-value>
</context-param>
<session-config>
  <session-timeout>30</session-timeout>
</session-config>
<servlet>
  <servlet-name>javax.ws.rs.core.Application</servlet-name>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>javax.ws.rs.core.Application</servlet-name>
  <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<filter>
  <filter-name>PrimeFaces FileUpload Filter</filter-name>
  <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>PrimeFaces FileUpload Filter</filter-name>
  <servlet-name>javax.ws.rs.core.Application</servlet-name>
</filter-mapping>
<error-page>
  <error-code>404</error-code>
  <location>/faces/error.xhtml</location>
</error-page>
<error-page>
  <error-code>500</error-code>
  <location>/faces/error.xhtml</location>
</error-page>
</web-app>

Any ideas? 有任何想法吗? I tried to change the bean to @ViewScoped, to @RequestScoped and nothing. 我试图将bean更改为@ViewScoped,更改为@RequestScoped。

Here is my managed bean: 这是我的托管bean:

@Named
@Stateful
@ConversationScoped
public class CatastrofeBean implements Serializable
{

  private static final long serialVersionUID = 1L;

  /*
   * Support creating and retrieving Catastrofe entities
   */

  private Long id;

  public Long getId()
  {
    return this.id;
  }

  public void setId(Long id)
  {
    this.id = id;
  }

  private Catastrofe catastrofe;

  public Catastrofe getCatastrofe()
  {
   return this.catastrofe;
  }

  @Inject
  private Conversation conversation;

  @Inject
  private CatastrofeDao catastofeDao;


  public String create()
  {
    this.conversation.begin();
    return "create?faces-redirect=true";
  }


  /*
   * Support updating and deleting Catastrofe entities
   */

  public String update()
  {
    this.conversation.end();

    try
    {
       if (this.id == null)
       {
        this.catastofeDao.create(this.catastrofe);
        return "search?faces-redirect=true";
       }
       else
       {
        this.catastofeDao.update(this.catastrofe);
        return "view?faces-redirect=true&id=" + this.catastrofe.getId();
       }
    }
    catch (Exception e)
    {
     FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
     return null;
    }
  }

  public void handleFileUploadImagen(FileUploadEvent event) {       
    FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Succesful", event.getFile().getFileName() + " is uploaded.");
    FacesContext.getCurrentInstance().addMessage(null, message);
  }

  public void handleFileUpload(FileUploadEvent event) {
    FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Succesful", event.getFile().getFileName() + " is uploaded.");
    FacesContext.getCurrentInstance().addMessage(null, message);
  }
} 

Thanks. 谢谢。

I finally get what the problem was, i missed define the Faces Servlet in the web.xml. 我终于明白问题出在哪里了,我错过了在web.xml中定义Faces Servlet的过程。

<servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

You didn't show the packages you imported for JSF annotations. 您没有显示为JSF注释导入的软件包。 You probably are importing wrong ones. 您可能正在导入错误的。 see this 看到这个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 enctype multipart/form-data 在多数据类型表单中的使用 - Usage of enctype multipart/form-data in multi data type form enctype =“ multipart / form-data”破坏了我的应用 - enctype=“multipart/form-data” destroyed my app 使用enctype =“ multipart / form-data”将选定的图像获取到控制器类吗? - Get selected image to Controller Class with enctype=“multipart/form-data”? 了解Spring MVC中的enctype = multipart / form-data的工作 - Understanding working of enctype = multipart/form-data in spring mvc 在 enctype=&quot;multipart/form-data&quot; 请求不起作用之后 - after enctype="multipart/form-data" request not working 当提交的表单具有属性 enctype=&quot;multipart/form-data&quot; 时,如何在控制器中获取表单数据? - How to get form data in controller when the form that was submitted has the attribute enctype="multipart/form-data"? 使用 enctype=multipart/form-data 上传文件时出错,错误是上传的文件不是 multipart - error while file uploading using enctype=multipart/form-data , the error is the file bring uploaded is not multipart 尽管我写了“enctype=&quot;multipart/form-data”,但发生错误“当前请求不是多部分请求” - Although I wrote 'enctype="multipart/form-data', ERROR 'Current request is not a multipart request' happen 使用enctype =“multipart / form-data”的表单会导致访问隐藏字段的问题 - Does form with enctype=“multipart/form-data” cause problems accessing a hidden field 如何在同一个jsp页面中查看jsp表单请求提交? (ENCTYPE =“多部分/格式数据”) - How can i check jsp form request submit in same jsp page? (enctype=“multipart/form-data”)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM