hi friends,i prefered your uploadexample there simply we can upload a file with given the action address on the form submitition.
but here i want to upload documents with comments in my project but my i have some logical problem there,
i have two models patient and document, and i am given the relation to patient have many documents,
so is it possible to iterate the document if yes then pls can you show me the logic here,
i am using this coding in my view show.jsp of patients folder like here comment field is brifly description about the document
<h2>Documents</h2>
<div id="Documents">
<%for (Iterator it = O.iteratorOf(O.allAssociatedRecordsOf("patient.documents")); it.hasNext();)
{
Object document = it.next();%>
<p>
<p><b>Name of the uploaded file</b>: <%=W.get("document")%> </p> <!-- here i am getting the null value on server -->
<p>Click <%=W.labelLink("here", "/static/docs/" + W.get("document"))%> to view the uploaded document.</p> <!--here i am gettig an error like The server has not found anything matching the URI given. -->
<b>posted on </b><%=O.property(document, "uploaded_at")%>
</p>
<p>
<b>Comment:</b>
<%=O.property(document, "comment")%>
</p>
<hr/>
<%}%>
</div>
<h2>Add Documents</h2>
<%=W.errorMessage("document")%>
<%=F.formForOpen("patients", patient, "documents", "document")%>
<p>
<%=F.label("document")%><br />
<input type="file" id="document_document" name="document" />
</p>
<p>
<%=F.label("comment")%><br />
<input type="text" id="document_comment" name="comment" value="<%=O.hv("document.comment")%>" size="40" />
</p>
<input id="document_submit" name="commit" type="submit" value="Create" /> <input type="reset"/>
<%=F.formForClose("documents")%>
nd this code i am using in documentsController.java like
public String create() {
ActiveRecord patient = Patient.findById(p("patient_id"));
setViewData("patient", patient);
try {
UploadFile uf1 = pFile("document");
uf1.writeTo(applicationPath() + "/static/docs");
flash("notice", "You have successfully uploaded a file.");
setViewData("document", uf1.getFileName());
} catch (Exception ex) {
flash("error", "There is a problem with upload.");
}
ActiveRecord newDocument = null;
try {
UploadFile uf1 = pFile("document");
newDocument = Document.newRecord();
newDocument.setData("document", p("document")); // here it stores full path of the uploaded file from the directry
//newDocument.setData("document", p(uf1.getFileName()));
/*nd when i am using this line after commenting on //newDocument.setData("document", p("document")); then it is given an error on the server like There was a problem creating the comment record.
Error in "/patients/1/documents": org.apache.jasper.JasperException: java.lang.IllegalArgumentException: The object which maps to key "document" for resource "documents" must be of RESTified type, but instead it is of "java.lang.String" type. */
newDocument.setData("comment", p("comment"));
newDocument.setData("patient_id", p("patient_id"));
newDocument.save();
flash("notice", "Comment was successfully created.");
return redirectTo(R.resourceRecordPath("patients", patient));
}
catch(Exception ex) {
log.error("Error in create() caused by " + ex.getMessage());
flash("error", "There was a problem creating the comment record.");
}
setViewData("document", newDocument);
return forwardTo(viewPath("patients", "show"));
}
here i want whatever document we uploaded document's name stores in database nd shown on server
so pls can you tell me what mistake i did nd pls show me what logic might be there