I have a button that saves a document, and creates response documents for users that are added to it. I have a #Unique function to generate a random number for my Form Number.
The problem I am having is that when I go in and edit the document and Save & Send the response documents, it treats it as a different document, so the Form Number is also changing. The form number needs to remain the same for the parent document.
Is there an easy to way to check to see if there is already a form number, and if so, to leave it the same? If not, go ahead and give it a random number.
Here is the code on my Save & Send button:
// get handle to names list
var item = new Array(document1.getItemValue("assignedassociates"));
var attach:String;
// loop through the list to create a review doc for each person listed
for(var i = 0; i <= (#Elements(item)-1); i++){
var newdoc:NotesDocument = database.createDocument()
newdoc.replaceItemValue("Form", "Review");
newdoc.replaceItemValue("datecreated", document1.getItemValueString("datecreated"));
newdoc.replaceItemValue("formnumber", document1.getItemValueString("formnumber"));
newdoc.replaceItemValue("title", document1.getItemValueString("title"));
newdoc.replaceItemValue("department", document1.getItemValueString("department"));
newdoc.replaceItemValue("description", document1.getItemValueString("description"));
newdoc.replaceItemValue("assignedassociates", item[i]);
newdoc.replaceItemValue("Status", "Sent");
// attachment URL
// calculate file path
// check for multiple attachments, create multiple URLs
attach = "http://domtest01.hendricks.org/chad/bloodhound.nsf/0/" + document1.getDocument().getUniversalID() +
"/$file/" + #AttachmentNames() + "?openElement";
newdoc.replaceItemValue("AttachmentURL", attach);
// set the security fields on the new doc we created
setSecurityFields(newdoc, item[i]);
newdoc.save();
}
// update document history
var cuser:NotesName=session.createName(#UserName()); // gets user name in name field
updateHistoryField(document1.getDocument(),cuser.getCommon(),"EditHistory","form_create"); // call function
// show assigned docs
requestScope.put("showContainer", true);
Here is my code from the page:
<xp:view
xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex"
styleClass="forms"
xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:this.data>
<xp:dominoDocument
var="document1"
formName="Create">
</xp:dominoDocument>
</xp:this.data>
<xp:table>
<xp:tr>
<xp:td style="font-weight:bold">Created By:</xp:td>
<xp:td>
<xp:text
escape="true"
id="computedField1">
<xp:this.value><![CDATA[#{javascript:var userName:NotesName = session.createName(#UserName());
return(userName.getCommon());}]]></xp:this.value>
</xp:text>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold">Date: </xp:td>
<xp:td>
<xp:inputText
id="inputText2"
value="#{document1.datecreated}" defaultValue="#{javascript:{javascript:#Today()}}">
<xp:this.validators>
<xp:validateRequired message="You must select a Date."></xp:validateRequired>
</xp:this.validators>
<xp:dateTimeHelper id="dateTimeHelper1"></xp:dateTimeHelper>
<xp:this.converter>
<xp:convertDateTime
type="date"
dateStyle="short">
</xp:convertDateTime>
</xp:this.converter>
</xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold">Form Number:</xp:td>
<xp:td>
<xp:inputText
id="inputText3"
value="#{document1.formnumber}"
required="true" disabled="true">
<xp:this.validators>
<xp:validateRequired message="You must enter a Form Number."></xp:validateRequired>
<xp:validateLength message="Form Number must be 8 characters in length."></xp:validateLength>
</xp:this.validators>
<xp:this.defaultValue><![CDATA[#{javascript:session.evaluate("#Unique")}]]></xp:this.defaultValue></xp:inputText>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold">Title: </xp:td><xp:td>
<xp:inputText
id="inputText1"
value="#{document1.title}"
maxlength="60"
required="true">
<xp:this.validators>
<xp:validateLength maximum="60"></xp:validateLength>
<xp:validateRequired message="You must enter a Title."></xp:validateRequired>
</xp:this.validators>
</xp:inputText> </xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold">Department:</xp:td>
<xp:td>
<xp:comboBox
id="department"
value="#{document1.department}"
rendered="#{javascript:document1.isEditable()}">
<xp:this.validators>
<xp:validateExpression message="You must select a Department">
<xp:this.expression><![CDATA[#{javascript:value != "Select One"}]]></xp:this.expression>
</xp:validateExpression>
</xp:this.validators>
<xp:selectItem
itemLabel="Select One"
itemValue="Select One"
id="selectItem1">
</xp:selectItem>
<xp:selectItems id="selectItems1">
<xp:this.value><![CDATA[#{javascript:var dbName = ["", "aApplications\\HCHPhoneBk.nsf"];
#DbColumn( dbName , "DeptNameLookUp", 1);}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
<xp:text
escape="true"
id="computedField2"
value="#{document1.department}"
rendered="#{javascript:!document1.isEditable()}">
</xp:text>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold">Description:</xp:td>
<xp:td>
<xp:inputTextarea
id="inputTextarea1"
value="#{document1.description}"
style="width:300.0px;height:96px"
required="true">
<xp:this.validators>
<xp:validateRequired message="You must enter a Description."></xp:validateRequired>
</xp:this.validators>
</xp:inputTextarea>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold">Attachments:</xp:td>
<xp:td>
<xp:fileUpload
id="attachments"
value="#{document1.attachments}">
</xp:fileUpload>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td style="font-weight:bold"></xp:td>
<xp:td>
<xp:fileDownload
rows="30"
id="fileDownload1"
displayLastModified="false"
hideWhen="true"
displaySize="true"
displayCreated="false"
value="#{document1.attachments}"
displayType="false" allowDelete="true">
</xp:fileDownload>
</xp:td>
</xp:tr>
<xp:tr>
<xp:td
rowspan="2"
style="font-weight:bold">
Associates to
<xp:br id="br1"></xp:br>
review document:
</xp:td>
<xp:td rowspan="2">
<xe:djextNameTextBox
id="djextNameTextBox1"
multipleSeparator=","
multipleTrim="true"
value="#{document1.assignedassociates}"
rendered="#{javascript:document1.isEditable()}">
</xe:djextNameTextBox>
<xe:namePicker
id="namePicker1"
for="djextNameTextBox1"
pickerIcon="/Symbol+Add.gif">
<xe:this.dataProvider>
<xe:namePickerAggregator>
<xe:this.dataProviders>
<xe:dominoNABNamePicker
addressBookDb="HCHPhoneBk"
nameList="people">
</xe:dominoNABNamePicker>
</xe:this.dataProviders>
</xe:namePickerAggregator>
</xe:this.dataProvider>
</xe:namePicker>
</xp:td>
</xp:tr>
<xp:tr></xp:tr>
</xp:table>
<xp:messages id="messages1"></xp:messages>
<xp:br></xp:br>
<xp:button
id="button4"
rendered="#{javascript:document1.isEditable()}">
<xp:this.value><![CDATA[Save & Assign Response Documents]]></xp:this.value>
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="document1"></xp:saveDocument>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:// get handle to names list
var item = new Array(document1.getItemValue("assignedassociates"));
var attach:String;
// loop through the list to create a review doc for each person listed
for(var i = 0; i <= (#Elements(item)-1); i++){
var newdoc:NotesDocument = database.createDocument()
newdoc.replaceItemValue("Form", "Review");
newdoc.replaceItemValue("datecreated", document1.getItemValueString("datecreated"));
newdoc.replaceItemValue("formnumber", document1.getItemValueString("formnumber"));
newdoc.replaceItemValue("title", document1.getItemValueString("title"));
newdoc.replaceItemValue("department", document1.getItemValueString("department"));
newdoc.replaceItemValue("description", document1.getItemValueString("description"));
newdoc.replaceItemValue("assignedassociates", item[i]);
newdoc.replaceItemValue("Status", "Sent");
// attachment URL
// TO DO - check for server name and put in appropriate server name and format
// calculate file path
// check for multiple attachments, create multiple URLs
attach = "http://domtest01.hendricks.org/chad/bloodhound.nsf/0/" + document1.getDocument().getUniversalID() +
"/$file/" + #AttachmentNames() + "?openElement";
newdoc.replaceItemValue("AttachmentURL", attach);
// set the security fields on the new doc we created
setSecurityFields(newdoc, item[i]);
newdoc.save();
}
// update document history
var cuser:NotesName=session.createName(#UserName()); // gets user name in name field
updateHistoryField(document1.getDocument(),cuser.getCommon(),"EditHistory","form_create"); // call function
// show assigned docs
requestScope.put("showContainer", true);}]]></xp:this.script>
</xp:executeScript>
<xp:changeDocumentMode
mode="readOnly"
var="document1">
</xp:changeDocumentMode>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button> <xp:button id="button1" value="Edit" rendered="#{javascript:!document1.isEditable()}">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action>
<xp:actionGroup>
<xp:changeDocumentMode mode="edit" var="document1">
</xp:changeDocumentMode>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:// update document history
var cuser:NotesName=session.createName(#UserName()); // gets user name in name field
updateHistoryField(document1.getDocument(),cuser.getCommon(),"EditHistory","form_create"); // call function}]]></xp:this.script>
</xp:executeScript>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:button id="button5">
<xp:this.value><![CDATA[#{javascript:if (document1.isEditable()){
return "Cancel";
}else{
return "Close";
}}]]></xp:this.value>
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete" immediate="true">
<xp:this.action>
<xp:openPage name="$$PreviousPage"></xp:openPage>
</xp:this.action></xp:eventHandler></xp:button>
<xp:this.beforePageLoad><![CDATA[#{javascript:requestScope.put("showContainer", false)}]]></xp:this.beforePageLoad><xp:br></xp:br>
<xp:br></xp:br>
<xp:panel id="outerContainer">
<xp:panel id="innerContainer">
<xp:viewPanel
rows="30"
id="viewPanel1"
var="rowData">
<xp:this.facets>
<xp:pager
partialRefresh="true"
layout="Previous Group Next"
xp:key="headerPager"
id="pager1">
</xp:pager>
<xp:viewTitle
xp:key="viewTitle"
id="viewTitle1" value="Sent To">
</xp:viewTitle>
</xp:this.facets>
<xp:this.data>
<xp:dominoView
var="view1"
viewName="Children">
<xp:this.categoryFilter><![CDATA[#{javascript:document1.getItemValueString("Title");}]]></xp:this.categoryFilter>
</xp:dominoView>
</xp:this.data>
<xp:viewColumn
columnName="$6"
id="viewColumn1">
<xp:this.converter>
<xp:convertDateTime
type="date"
dateStyle="short">
</xp:convertDateTime>
</xp:this.converter>
<xp:viewColumnHeader
value="Date"
id="viewColumnHeader1">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="department"
id="viewColumn2">
<xp:viewColumnHeader
value="Department"
id="viewColumnHeader2">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="formnumber"
id="viewColumn3">
<xp:viewColumnHeader
value="Form #"
id="viewColumnHeader3">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="assignedassociates"
id="viewColumn4"
displayAs="link"
openDocAsReadonly="#{javascript:rowData.getColumnValue('Status') === 'Responded'}">
<xp:viewColumnHeader
value="Reviewer"
id="viewColumnHeader4">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn
columnName="Status"
id="viewColumn5">
<xp:viewColumnHeader
value="Status"
id="viewColumnHeader5">
</xp:viewColumnHeader>
</xp:viewColumn>
</xp:viewPanel>
</xp:panel>
</xp:panel>
<xp:text escape="true" id="computedField3"><xp:this.value><![CDATA[#{javascript:"requestScope.showContainer=" + requestScope.get("showContainer")}]]></xp:this.value></xp:text>
<xp:br></xp:br>
<xc:layout_EditHistory></xc:layout_EditHistory></xp:view>
Try this (includes recycle):
var item:java.util.Vector = document1.getItemValue("assignedassociates");
if (!document1.hasItem("formnumber")) {
document1.replaceItemValue("formnumber",session.evaluate("#Unique"));
}
for(var curItem in item) {
try {
var newdoc:NotesDocument = database.createDocument();
newdoc.replaceItemValue("Form", "Review");
newdoc.replaceItemValue("datecreated", document1.getItemValueString("datecreated"));
newdoc.replaceItemValue("formnumber", document1.getItemValueString("formnumber"));
newdoc.replaceItemValue("title", document1.getItemValueString("title"));
newdoc.replaceItemValue("department", document1.getItemValueString("department"));
newdoc.replaceItemValue("description", document1.getItemValueString("description"));
newdoc.replaceItemValue("assignedassociates", curItem);
newdoc.replaceItemValue("Status", "Sent");
// attachment URL
var attach = "http://domtest01.hendricks.org/chad/bloodhound.nsf/0/" + document1.getDocument().getUniversalID() +
"/$file/" + #AttachmentNames() + "?openElement";
newdoc.replaceItemValue("AttachmentURL", attach);
// set the security fields on the new doc we created
setSecurityFields(newdoc, curItem);
newdoc.save();
// Cleanup!
newdow.recycle();
} catch (e) {
// Some clever error handling here
}
}
// update document history
var cuser:NotesName=session.createName(#UserName()); // gets user name in name field
updateHistoryField(document1.getDocument(),cuser.getCommon(),"EditHistory","form_create");
// show assigned docs
requestScope.put("showContainer", true);
Let us know how it goes!
Update
Use this for the row - if the form number shouldn't be changed after creation
<xp:tr>
<xp:td style="font-weight:bold">Form Number:</xp:td>
<xp:td>
<xp:inputText
id="inputText3"
value="#{document1.formnumber}" disabled="true"
required="true" rendered="#{javascript:document1.isNewNote()}">
<xp:this.validators>
<xp:validateRequired message="You must enter a Form Number."></xp:validateRequired>
<xp:validateLength message="Form Number must be 8 characters in length."></xp:validateLength>
</xp:this.validators>
<xp:this.defaultValue><![CDATA[#{javascript:session.evaluate("#Unique")}]]></xp:this.defaultValue>
</xp:inputText>
<xp:text escape="true" id="displayText3"
value="#{document1.formnumber}"
rendered=""#{javascript:!document1.isNewNote()}"></xp:text>
</xp:td>
</xp:tr>
This is close to what your current approach. However I actually would only use the display field and add the value in the NewDocument event of the document1 data source. So your row would look like this:
<xp:tr>
<xp:td style="font-weight:bold">Form Number:</xp:td>
<xp:td>
<xp:text escape="true" id="displayText3"
value="#{document1.formnumber}"></xp:text>
</xp:td>
</xp:tr>
In the events tab under Data - document1 - queryNewDocument you add as JavaScript:
document1.replaceItemValue("formnumber",session.evaluate("#Unique"));
That should do the trick. Another remark: Use LABELS for your labels and use CSS for the formatting. Bold labels are kind out of fashion, so having a single definition in CSS makes adoption easier. Also you need labels if you ever plan to make it multi lingual (there's Chinese and Spanish even in the US - or Hindi if your work for 7/11)
Related
This question already has answers here:
Showing Hibernate/JPA results in JSF datatable causes: java.lang.NumberFormatException: For input string: "[propertyname]"
(2 answers)
Closed 6 years ago.
I'm trying to replicate this guide but with jsf 2.2:
http://www.mkyong.com/jsf2/jsf-2-datatable-example/
My current setup: a class called Message holds a date, string, and an account object called "name" (its owner). A MessageBean class has a List object messageSet, that gets initialized in the MessageBean constructor. A JSF page fills a table with the messageList. However, the table doesn't get filled. When looking at the list object in the debugger, it does get filled with valid message objects. My classes:
#Named(value = "messageBean")
#SessionScoped
public class MessageBean implements Serializable
{
private List messageSet;
public MessageBean()
{
this.messageSet = Controller.Controller.getLatestKweks();
}
public List<Message> getMessageSet()
{
return messageSet;
}
public void setMessageSet(List<Message> messageSet)
{
this.messageSet = messageSet;
}
}
The JSF page:
<h:dataTable value="#{messageBean.messageSet}" var="mes">
<h:column>
<f:facet name="header">Date</f:facet>
#{mes.mesDate}
</h:column>
<h:column>
<f:facet name="header">Naam</f:facet>
#{mes.name.accountName}
</h:column>
<h:column>
<f:facet name="header">Content</f:facet>
#{mes.Content}
</h:column>
</h:dataTable>
There's a second Message object that is a Hibernate object, only having getters and setters in it.
Here's the stacktrace when I try to access this page:
java.lang.NumberFormatException: For input string: "mesDate"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at javax.el.ArrayELResolver.toInteger(ArrayELResolver.java:378)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:198)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:140)
at com.sun.el.parser.AstValue.getValue(AstValue.java:204)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302)
at com.sun.faces.renderkit.html_basic.TableRenderer.renderRow(TableRenderer.java:385)
at com.sun.faces.renderkit.html_basic.TableRenderer.encodeChildren(TableRenderer.java:162)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:724)
THe component tree:
<UIViewRoot id="j_id1" inView="true" locale="en_GB" renderKitId="HTML_BASIC" rendered="true" transient="false" viewId="/hoofdpagina.xhtml">
<html xmlns="http://www.w3.org/1999/xhtml">
<UIOutput id="j_idt2" inView="true" rendered="true" transient="false">
<title>Main page</title>
</UIOutput>
<UIOutput id="j_idt4" inView="true" rendered="true" transient="false">
<div id="menu">top</div> <div id="currentMessages">
<HtmlDataTable border="-2147483648" first="0" id="j_idt6" inView="true" rendered="true" rowIndex="0" rowStatePreserved="false" rows="0" transient="false" var="mes">
<UIColumn header="Datum" id="j_idt7" inView="true" rendered="true" transient="false">
header
Date
#{mes.mesDate}
</UIColumn>
<UIColumn header="Name" id="j_idt10" inView="true" rendered="true" transient="false">
header
Name
#{mes.name.accountName}
</UIColumn>
<UIColumn header="Inhoud" id="j_idt13" inView="true" rendered="true" transient="false">
header
Content
#{mes.mesContent}
</UIColumn>
</HtmlDataTable>
</div>
</UIOutput>
</html>
</UIViewRoot>
And the scoped variables:
Name Value
j_idt6 j_idt6
j_idt6:j_idt10 bread
j_idt6:j_idt12 Log in
j_idt6:j_idt8 Donald
AttributesName Value
None
Request AttributesName Value
kwek [Ljava.lang.Object;#a5c775c
Flash AttributesName Value
None
Session AttributesName Value
None
Application AttributesName Value
csfcff [ ]
Anyone have any idea why the table won't fill?
Your Hibernate/JPA query is broken. The code behind getLatestKweks() is actually returning a List<Object[]>, not List<Message>.
Evidence is in the stack trace:
java.lang.NumberFormatException: For input string: "mesDate"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at javax.el.ArrayELResolver.toInteger(ArrayELResolver.java:378)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:198)
...
The ArrayELResolver is only involved when the base of mesDate (thus, the #{mes}) represents an array like Object[] not a javabean like Message. EL is attempting to use the mesDate to obtain the array item by index, which can only be an integer like so #{mes[0]} for the 1st item. However, the string value "mesDate" is not parseable as an integer and hence this exception.
You have 2 options to solve this problem:
Alter the code to expect a List<Object[]>. Use e.g. #{mes[0]}, #{mes[1]}, etc.
Fix the Hibernate/JPA query to return a real List<Message>. Specify Message.class as type.
See also:
NumberFormatException for input String
I am trying to figure out a way to load the text from an XML document I have created using TinyXML2. Here is the entire document.
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="15" height="13" tilewidth="32" tileheight="32">
<tileset firstgid="1" name="Background" tilewidth="32" tileheight="32">
<image source="background.png" width="64" height="32"/>
</tileset>
<tileset firstgid="3" name="Block" tilewidth="32" tileheight="32">
<image source="block.png" width="32" height="32"/>
</tileset>
<layer name="Background" width="15" height="13">
<data encoding="base64">
AgAAAAIAAAACAAAA...
</data>
</layer>
<layer name="Block" width="15" height="13">
<data encoding="base64">
AwAAAAMAAAADAAAAAwAAAAM...
</data>
</layer>
</map>
Basically, I want to copy the text from <data> into a string called background only if the layer name is "Background".
I have gotten the other variables like so:
// Get the basic information about the level
version = doc.FirstChildElement("map")->FloatAttribute("version");
orientation = doc.FirstChildElement("map")->Attribute("orientation");
mapWidth = doc.FirstChildElement("map")->IntAttribute("width");
mapHeight = doc.FirstChildElement("map")->IntAttribute("height");
That works great because I know the element name and the attribute name. Is there a way to say get the doc.FirstChildElement("map")->FirstChildElement("layer") and if it == "Background", get the text.
How would I accomplish this?
I know this thread is quite old, but just in case someone perusing the internet might stumble upon this question as I have, I wish to point out that Xanx's answer can be simplified slightly.
In tinyxml2.h it says that for the function const char* Attribute( const char* name, const char* value=0 ) const, if the value parameter is not null, then the function only returns if value and name match. According to the comments in the file this:
if ( ele->Attribute( "foo", "bar" ) ) callFooIsBar();
can be written like this:
if ( ele->Attribute( "foo" ) ) {
if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar();
}
So the code Xanx provided can be rewritten like this:
XMLElement * node = doc.FirstChildElement("map")->FirstChildElement("layer");
std::string value;
if (node->Attribute("name", "Background")) // no need for strcmp()
{
value = node->FirtChildElement("data")->GetText();
}
A minor change, yes, but something I wanted to add.
I advice you to do something like this:
XMLElement * node = doc.FirstChildElement("map")->FirstChildElement("layer");
std::string value;
// Get the Data element's text, if its a background:
if (strcmp(node->Attribute("name"), "Background") == 0)
{
value = node->FirtChildElement("data")->GetText();
}
auto bgData = text (find_element (doc, "map/layer[#name='Background']/data"));
Using tinyxml2 extension (#include <tixml2ex.h>).
N.B. should really be wrapped in a try/catch block.
Work in progress and documentation is incomplete (can deduce from the test example until it's ready).
I'll mention in passing that the other two answers only work properly when the desired <layer> element appears first.
I have a users.xml
<?xml version="1.0"?>
<Data>
<Users>
<User name="xyz" email="xyz#xyz.com">
<Tasks/>
</User>
</Users>
</Data>
I have got a reference to Users element using the following code
IXMLDOMDocumentPtr pXMLDom;
// code to load the xml dox
IXMLDOMElementPtr pXMLDocElement = NULL;
IXMLDOMNodeListPtr pXMLUsers = NULL;
//gets <Data>
pXMLDocElement = pXMLDom->GetdocumentElement();
//gets <Users>
pXMLUsers = pXMLDocElement->childNodes;
Now how do I create a child element User in Users element.
I have tried using createElement() on pXMLUsers, but it says IXMLDOMNodeListPtr has no member appendChild.
I don't know how to create a new element.
Thanks.
You cannot use the IXMLDOMNodeListPtr to append a child - it's just for iterating existing children.
You can use the IXMLDOMElementPtr directly to call pXMLDocElement->appendChild() to add a child element in your Document.
Ok, I've found a solution, thanks to TERACytE
IXMLDOMDocumentPtr pXMLDom;
// code to load the xml dox
//Creating <User>
MSXML2::IXMLDOMElementPtr pUser = pXMLDom->createNode(NODE_ELEMENT, "User", "");
//Creating <User name="">
MSXML2::IXMLDOMAttributePtr pName = pXMLDom->createAttribute("name");
pName->value = name;
//Creating <User email="">
MSXML2::IXMLDOMAttributePtr pEmail = pXMLDom->createAttribute("email");
pEmail->value = email;
//Adding name attrib to <User>
pUser->setAttributeNode(pName);
//Adding email attrib to <User>
pUser->setAttributeNode(pEmail);
//Creating <Tasks>
MSXML2::IXMLDOMElementPtr pTasks = pXMLDom->createNode(NODE_ELEMENT, "Tasks", "");
//Creating <Task>
MSXML2::IXMLDOMElementPtr pTask = pXMLDom->createNode(NODE_ELEMENT, "Task", "");
//Creating <Task name="">
MSXML2::IXMLDOMAttributePtr pTName = pXMLDom->createAttribute("name");
pTName->value = task;
//Creating <User status="">
MSXML2::IXMLDOMAttributePtr pStatus = pXMLDom->createAttribute("status");
pStatus->value = status;
//Adding name attrib to <User>
pTask->setAttributeNode(pTName);
//Adding status attrib to <User>
pTask->setAttributeNode(pStatus);
//Adding <Task> to <Tasks>
pTasks->appendChild(pTask);
//Adding <Tasks> to <User>
pUser->appendChild(pTasks);
//Selecting <Users>
MSXML2::IXMLDOMNodePtr pUsers = pXMLDom->selectSingleNode("/Data/Users");
//Adding <User> to <Users>
pUsers->appendChild(pUser);
EDIT: I added in the hf from the first reply that was pointed out. This helped with a few other issues, but still did not fix the problem.
I am trying to bind a list to a gridview with a LOT of hidden fields (I'll only use 2 of the 50) for temporary holding so the user can create and delete multiple items without going back and forth to the database multiple times during creation. I'm fine with binding to and recalling from the BoundFields; however, when I try to recall the hidden field values it comes back as null. I may be having problems with the binding to the hidden fields. Here's my code
ASP:
<asp:GridView ID="grdOtherCarrier" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="Sequence" DataField="Sequence"></asp:BoundField>
<asp:BoundField HeaderText="Pay ID" DataField="PayID"></asp:BoundField>
<asp:BoundField HeaderText="Provider" DataField="Provider"></asp:BoundField>
<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<asp:HiddenField ID="hfInsuredLastName" Value="<%#Eval("InsuredLastName")%>" runat="server" />
<asp:HiddenField ID="hfInsuredFirstName" Value="<%#Eval("InsuredFirstName")%>" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C# / code behind:
protected void lblSubmitOtherCarrier_Click(object sender, EventArgs e)
{
List<OtherCarrier> OCList = new List<OtherCarrier>();
OtherCarrier OC;
foreach (GridViewRow row in grdOtherCarrier.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
OC = new OtherCarrier();
String Sequence = row.Cells[0].Text.ToString() ; // primary value
String PayID = row.Cells[1].Text.ToString(); // primary value
String Provider = row.Cells[2].Text.ToString(); // primary value
HiddenField InsuredLastName = (HiddenField)row.FindControl("hfInsuredLastName");
HiddenField InsuredFirstName = (HiddenField)row.FindControl("hfInsuredFirstName");
OC.Sequence = Sequence;
OC.PayID = PayID;
OC.Provider = Provider;
OC.InsuredLastname = InsuredLastName.Value.ToString();
OC.InsuredFirstName = InsuredFirstName.Value.ToString();
OCList.Add(OC);
}
}
OC = new OtherCarrier();
OC.Sequence = txtSequence.Text;
OC.PayID = txtPayID.Text;
OC.Provider = txtProvider.Text;
OC.InsuredLastname = txtInsuredLastname.Text;
OC.InsuredFirstName = txtInsuredFirstName.Text;
OCList.Add(OC);
TD.OtherCarrierList = OCList;
grdOtherCarrier.DataSource = OCList;
grdOtherCarrier.DataBind();
mpeAddOtherCarrier.Hide();
txtSequenceNo.Text = (grdOtherCarrier.Rows.Count + 1).ToString();
}
When it gets to assigning the OC.InsuredLastname from the hidden field the hidden field is coming up as null value. Either I'm not reading it correctly or it's not being written correctly.
so...
you are trying to find a control as
(HiddenField)row.FindControl("InsuredLastName");
as you can see, named InsuredLastName when you explicit say in the HTML that your control name is:
<asp:HiddenField
ID="hfInsuredLastName"
Value="<%#Eval("InsuredLastName")%>"
runat="server" />
named hfInsuredLastName
all you need to do is change the call to
(HiddenField)row.FindControl("hfInsuredLastName")
I have ig:TemplateDataField that contains label.
In InitializeRow event handler I try to find that label with e.Row.FindControl but I get null.
I was not able to find another way to find my label.
How to look for controls in WebDataGrid rows during InitializeRow event?
You have to specify the column that you want to search in like e.Row.Items[0].FindControl("ControlID") where 0 the column index.
Below is a solution that should work.
note: Code is for an Infragistics UltraWebGrid control. The WebDataGrid control is the UltraWebGrid's successor.
C#:
protected void UltraWebGridCustomers_InitializeRow(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e)
{
TemplatedColumn col = (TemplatedColumn)e.Row.Cells.FromKey("HyperLinkEmailColumn").Column;
CellItem cellItem = (CellItem)col.CellItems(e.Row.Index);
HyperLink hyperLinkEmail = (HyperLink)cellItem.FindControl("HyperLinkSendEmail");
hyperLinkShowDetails.Attributes.Add("onclick", "alert('This is the email link');");
}
VB.NET:
Private Sub UltraWebGridCustomers_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.RowEventArgs) Handles UltraWebGridCustomers.InitializeRow
Dim col As TemplatedColumn = CType(e.Row.Cells.FromKey("HyperLinkEmailColumn").Column, TemplatedColumn)
Dim cellItem As CellItem = CType(col.CellItems(e.Row.Index), CellItem)
Dim hyperLinkEmail As HyperLink = CType(cellItem.FindControl("HyperLinkSendEmail"), HyperLink)
hyperLinkShowDetails.Attributes.Add("onclick", "alert('This is the email link');")
End Sub
Aspx code:
<infragistics:UltraWebGrid ID="UltraWebGridCustomers" runat="server">
<Bands>
<infragistics:UltraGridBand BaseTableName="Customers" Key="BandCustomers">
<Columns>
...
<infragistics:UltraGridColumn Key="NameColumn" BaseColumnName="Name" IsBound="True">
<Header Caption="Name">
</Header>
</infragistics:UltraGridColumn>
<infragistics:UltraGridColumn Key="EmailColumn" BaseColumnName="Email" IsBound="True">
<Header Caption="Email Address">
</Header>
</infragistics:UltraGridColumn>
<infragistics:TemplatedColumn Key="HyperLinkEmailColumn">
<CellTemplate>
<asp:HyperLink ID="HyperLinkSendEmail" NavigateUrl='<%# "~/EmailForm.aspx?email=" & DataBinder.Eval(Container.DataItem,"Email")%>' ToolTip="Send Email" runat="server" />
</CellTemplate>
</infragistics:TemplatedColumn>
...
</Columns>
<AddNewRow View="NotSet" Visible="NotSet">
</AddNewRow>
</infragistics:UltraGridBand>
</Bands>
...
</infragistics:UltraWebGrid>