接缝 s:fileupload 始终为空
seam s:fileupload is always null
我正在尝试使用 s:fileUpload 组件,这会导致设置 bean 变量时出现问题。它始终 returns 为空。这是 xhtml:
<h:form enctype="multipart/form-data">
<s:fileUpload id="pictureproc" data="#{uploader.file}" />
<h:commandButton id="doanything"
action="#{uploader.filehash(pictureproc)}"
value="Show file hash" />
</h:form>
还有豆子:
@Name("uploader")
@Scope(ScopeType.SESSION)
public class Uploader {
byte[] file;
public byte[] getFile() {
return file;
}
public void setFile(byte[] file) {
this.file = file;
System.out.println("uploaded");
}
public void filehash(byte[] file) {
System.out.println(file.hashCode()); // here goes the NPE
}
}
我已经在 web.xml 和 components.xml 中包含了所有内容:
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
和组件:
<web:multipart-filter create-temp-files="true"
max-request-size="10485760" url-pattern="*.seam" />
<component class="org.jboss.seam.web.MultipartFilter">
<property name="createTempFiles">true</property>
<property name="maxRequestSize">1000000</property>
</component>
并记录:
Caused by: javax.faces.el.EvaluationException:
java.lang.NullPointerException at
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 54 more
Caused by: java.lang.NullPointerException
at com.example.Uploader.filehash(Filter.java:57)
我也尝试在 setter 中记录它,但它也是 returns NULL。
接缝 2.2,JSF 1.0
您正在向您的 filehash 方法发送空值 h:commandButton(pictureproc)
从您的操作方法中删除参数到
<h:form enctype="multipart/form-data">
<s:fileUpload id="pictureproc" data="#{uploader.file}" />
<h:commandButton id="doanything"
action="#{uploader.filehash()}"
value="Show file hash" />
</h:form>
然后在您的 class 中从 filehash 方法中删除参数 byte[],而是使用
引用 class 属性
@Name("uploader")
@Scope(ScopeType.SESSION)
public class Uploader {
byte[] file;
public byte[] getFile() {
return file;
}
public void setFile(byte[] file) {
this.file = file;
System.out.println("uploaded");
}
public void filehash() {
System.out.println(this.file.hashCode()); // here goes the NPE
}
}
请记住,文件正在传输并存储在您的 s:fileUpload 数据组件引用的 属性 中,而不是通过在您的 h:commandButton 操作中传递其 ID
我正在尝试使用 s:fileUpload 组件,这会导致设置 bean 变量时出现问题。它始终 returns 为空。这是 xhtml:
<h:form enctype="multipart/form-data">
<s:fileUpload id="pictureproc" data="#{uploader.file}" />
<h:commandButton id="doanything"
action="#{uploader.filehash(pictureproc)}"
value="Show file hash" />
</h:form>
还有豆子:
@Name("uploader")
@Scope(ScopeType.SESSION)
public class Uploader {
byte[] file;
public byte[] getFile() {
return file;
}
public void setFile(byte[] file) {
this.file = file;
System.out.println("uploaded");
}
public void filehash(byte[] file) {
System.out.println(file.hashCode()); // here goes the NPE
}
}
我已经在 web.xml 和 components.xml 中包含了所有内容:
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
和组件:
<web:multipart-filter create-temp-files="true"
max-request-size="10485760" url-pattern="*.seam" />
<component class="org.jboss.seam.web.MultipartFilter">
<property name="createTempFiles">true</property>
<property name="maxRequestSize">1000000</property>
</component>
并记录:
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) ... 54 more Caused by: java.lang.NullPointerException at com.example.Uploader.filehash(Filter.java:57)
我也尝试在 setter 中记录它,但它也是 returns NULL。 接缝 2.2,JSF 1.0
您正在向您的 filehash 方法发送空值 h:commandButton(pictureproc)
从您的操作方法中删除参数到
<h:form enctype="multipart/form-data">
<s:fileUpload id="pictureproc" data="#{uploader.file}" />
<h:commandButton id="doanything"
action="#{uploader.filehash()}"
value="Show file hash" />
</h:form>
然后在您的 class 中从 filehash 方法中删除参数 byte[],而是使用
引用 class 属性@Name("uploader")
@Scope(ScopeType.SESSION)
public class Uploader {
byte[] file;
public byte[] getFile() {
return file;
}
public void setFile(byte[] file) {
this.file = file;
System.out.println("uploaded");
}
public void filehash() {
System.out.println(this.file.hashCode()); // here goes the NPE
}
}
请记住,文件正在传输并存储在您的 s:fileUpload 数据组件引用的 属性 中,而不是通过在您的 h:commandButton 操作中传递其 ID