Java EE 和 struts 和 JSP:java 表单填充 - 操作 bean 等
大家好。
问题-
在 /member/cvUpload 中填充 nl.strohalm.cyclos.controls.cv.CvUploadForm@317bdd 时出错 javax.servlet.ServletException:BeanUtils.populate
我正在开发一个开源 wep 应用程序,并尝试通过添加新功能来自学一些技能。
现在,该网络应用程序称为 cyclos,并使用 - Java EE、Struts、Hibernate、JSP、Tiles-def(spring、MySql JavaScript)设置:控件、DAO、服务、实体等。
我正在尝试添加新功能,例如 CV数据库供用户保存模板和文件。
我的示例 JSP 表单如下所示:
<ssl:form method="post" action="/member/cvUpload" enctype="multipart/form-data">
<html:hidden property="id" />
<html:hidden property="owner" />
<html:hidden property="uploadDate" />
<table class="defaultTableContent" cellspacing="0" cellpadding="0">
<tr>
<td class="tdHeaderTable">TITLE HERE PLEASE !!!></td>
</tr>
<tr>
<td colspan="2" align="left" class="tdContentTableLists">
<table class="defaultTable">
<tr>
<th class="tdHeaderContents" width="30%"> CV Upload -> needs properties copy / ref !!!</th>
<th class="tdHeaderContents" width="60%"> </th>
</tr>
<tr>
<td>Notes </td>
<td><cyclos:richTextArea name="notes" styleId="descriptionText"/></td>
</tr>
<tr>
<td>Address</td>
<td><html:text value="address" size="25" property="address" /><br>
<html:text value="address" size="25" property="address2" />
<html:text value="address" size="25" property="address3" />
</td>
</tr>
<tr>
<td>Phone Number</td>
<td><html:text value="0791 000 000" size="15" property="phoneNumber"/></td>
</tr>
<tr>
<td>Field of interest / industry</td>
<td><c:forEach var="industry" items="${industries}">
<label>
<html:radio property="industry" value="${industry}" styleClass="radio" /><bean:message key="cv.industries.${industry}" />
</label>
</c:forEach>
</td>
</tr>
<tr>
<td>CV upload</td>
<td><html:file property="cvContent" /></td>
</tr>
<tr>
<td>
<input type="submit" id="saveButton" value="<bean:message key="global.submit"/>" align="center">
</td>
</tr>
</table>
</td>
</tr>
</table>
我的java表单由struts填充,或者看起来如下:
public class CvUploadForm extends BaseBindingForm {
private Long id;
@IndexedEmbedded(depth = 4)
private Member owner;
// private Calendar creationDate;
// private Member memberId;
private FormFile cvContent;
private Calendar uploadDate;
private long memberId;
public CvUploadForm() {
}
public CvUploadForm(Long id, Member owner, FormFile cvContent, Calendar uploadDate) {
this.id = id;
this.owner = owner;
this.cvContent = cvContent;
this.uploadDate = uploadDate;
}
public Map<String, Object> getCv() {
return values;
}
public void setCv(final Map<String, Object> map) {
values = map;
}
public void setCv(final String key, final Object value) {
values.put(key, value);
}
// ++ getters and setters ++
// =========================== ====================
现在我可以显示我的模板,但我的提交不起作用 ->我想了解我的输出窗口中显示的问题/错误! (参见顶部和以下错误)
显示的下一个错误如下:
引起:java.lang.IllegalArgumentException:无法调用nl.strohalm.cyclos.controls.cv.CvUploadForm.setOwner - 参数类型不匹配
加上更多错误。 (所有者 ov cv 将不同的成员表引用为 ID - 使用 java 枚举 - 关系... fetch
我非常感谢您的回复!并且我对设置进行了一些澄清。我以为我只使用表单在 JSP 上显示位,并使用 CV.java 实体文件进行 maaping 等,所以我对获取所有文件和连接以及理解此处的错误感到有点迷失
,如果您需要其他信息,请告诉我。 。 亚历克斯
HI everyone.
ISSUE-
Error populating nl.strohalm.cyclos.controls.cv.CvUploadForm@317bdd in /member/cvUpload
javax.servlet.ServletException: BeanUtils.populate
I am working on a opensource wep app, and trying to teach my self some skills by adding new functionality.
Now The web app is called cyclos and uses - Java EE, Struts, Hibernate, JSP, Tiles-def (spring, MySql JavaScript) SETUP: controls, DAO's, services, entities etc.
I am trying to add new functionality such as a CV database for users to save a template and file.
My sample JSP form looks as follows:
<ssl:form method="post" action="/member/cvUpload" enctype="multipart/form-data">
<html:hidden property="id" />
<html:hidden property="owner" />
<html:hidden property="uploadDate" />
<table class="defaultTableContent" cellspacing="0" cellpadding="0">
<tr>
<td class="tdHeaderTable">TITLE HERE PLEASE !!!></td>
</tr>
<tr>
<td colspan="2" align="left" class="tdContentTableLists">
<table class="defaultTable">
<tr>
<th class="tdHeaderContents" width="30%"> CV Upload -> needs properties copy / ref !!!</th>
<th class="tdHeaderContents" width="60%"> </th>
</tr>
<tr>
<td>Notes </td>
<td><cyclos:richTextArea name="notes" styleId="descriptionText"/></td>
</tr>
<tr>
<td>Address</td>
<td><html:text value="address" size="25" property="address" /><br>
<html:text value="address" size="25" property="address2" />
<html:text value="address" size="25" property="address3" />
</td>
</tr>
<tr>
<td>Phone Number</td>
<td><html:text value="0791 000 000" size="15" property="phoneNumber"/></td>
</tr>
<tr>
<td>Field of interest / industry</td>
<td><c:forEach var="industry" items="${industries}">
<label>
<html:radio property="industry" value="${industry}" styleClass="radio" /><bean:message key="cv.industries.${industry}" />
</label>
</c:forEach>
</td>
</tr>
<tr>
<td>CV upload</td>
<td><html:file property="cvContent" /></td>
</tr>
<tr>
<td>
<input type="submit" id="saveButton" value="<bean:message key="global.submit"/>" align="center">
</td>
</tr>
</table>
</td>
</tr>
</table>
And my java form populated by struts or how ever looks as follows:
public class CvUploadForm extends BaseBindingForm {
private Long id;
@IndexedEmbedded(depth = 4)
private Member owner;
// private Calendar creationDate;
// private Member memberId;
private FormFile cvContent;
private Calendar uploadDate;
private long memberId;
public CvUploadForm() {
}
public CvUploadForm(Long id, Member owner, FormFile cvContent, Calendar uploadDate) {
this.id = id;
this.owner = owner;
this.cvContent = cvContent;
this.uploadDate = uploadDate;
}
public Map<String, Object> getCv() {
return values;
}
public void setCv(final Map<String, Object> map) {
values = map;
}
public void setCv(final String key, final Object value) {
values.put(key, value);
}
// ++ GETTERS AND SETTERS ++
// =============================================
Now I can display my template, but my submit wont work -> and i would like to understand the issue / error shown im my output window !! (see at top and following error )
the next error shown is as follows :
Caused by: java.lang.IllegalArgumentException: Cannot invoke nl.strohalm.cyclos.controls.cv.CvUploadForm.setOwner - argument type mismatch
Plus couple more errors. (owner ov cv refers to different member table as ID - uses java enum - relationships... fetch
I am very grateful for any reply ! And mybe some clarification about the setup. I thought I onlu use the form to display bits on JSP, and the use the CV.java entity file for the maaping etc . . so I am a little lost on getting all files and the connection right as wel las understanding the error here
Thanks for any reply, if you need additional info pls let me know.
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须查看它尝试传递给 setOwner 方法的对象的类型。它不是 Member 类型的对象。
使用调试器并尝试查看正在尝试通过的内容。
You have to see what is the type of object it attempts to pass to the setOwner method. It is not an object of type Member.
Use your debugger and try to see what is trying to pass.
你应该明确它是 Struts 1 还是 Struts 2。
struts 1 将属性映射到 actionForm ,如果是这种情况,您应该在表单操作中使用原始类型(而不是像成员这样的对象)。
Struts 2 使用 OGNL 将复杂对象映射到其特定的 bean。
这是我关于 stack over flow 的第一篇文章,希望对您有所帮助。
you should precise if it's Struts 1 or struts 2.
struts 1 maps proprities to actionForm ,if it's the case you should use primitive types in form action ( not objects like member) .
Struts 2 uses OGNL to map complex object to their specific bean.
this my first post on stack over flow , i hope that it khelps you.