XPages and hidden computed fields

This is probably a dumb question, but what’s the best way of re-creating hidden ‘computed’ fields with XPages?

If I add a field and set its ‘rendered’ property to false, the value is not saved when I save the document.

My workaround is to do all the logic in the ‘querysavedocument’ event of the form. Is that the correct method now?

Thanks,

Karl

Subject: Two other ways…

The first way I have found was to create a panel with the hidden fields in it and hide with css. But that has the isue, that a user could switch off css in his browser and the hidden fileds are shown again.

The easiest and best way is to set the fields in “querySaveDocument:”.:

		<xp:this.querySaveDocument>

			<xp:actionGroup>

				<xp:modifyField name="TxtBeschreibung">

					<xp:this.value>

						<![CDATA[#{javascript:@Text(document1.getValue("rtxBeschreibung"));}]]>

					</xp:this.value>

				</xp:modifyField>

				<xp:modifyField name="datValidUntil"

					value="#{javascript:@Adjust(@Now(),0,3,0,0,0,0)}">

				</xp:modifyField>

				<xp:modifyField name="SendTo"

					value="#{javascript:@UserName()}">

				</xp:modifyField>

				<xp:modifyField name="Autor"

					value="#{javascript:@UserName()}">

				</xp:modifyField>

				<xp:modifyField name="rbtYesNo" value="nein">

				</xp:modifyField>

			</xp:actionGroup>

		</xp:this.querySaveDocument>

In that way no field must be made in the XPage and you can fill all hidden fields in the form. It also works with fields which are set to “computed” in the notesform.

Subject: One problem with that…

Thanks Wolfgang. The problem I had with that technique is that I was trying to set a readers field, but the name just gets stored as a regular field. I can change the field type to ‘readers’ after I save the document, but saving the doc twice seemed clumsy. I’ve since discovered the ‘computeWithForm’ data property which worked well.

Karl

Subject: Can you gieve us the code, please ?

Hello Karl,

i do not understand your solution. Can in “computeWithForm” be other values as “onload”, “onsave” or “both” ?

Thank you…

Wolfgang

Subject: Does this help?

Amongst other things, I wanted to set a readers field for a document created using an XPage. The XPage has an equivalent regular form, and when I use the ‘ComputeWithForm’ option, the saved document has picked up the readers field (as specified on the regular form). Here’s the code from the XPage:

xp:this.data

<xp:dominoDocument var=“MyBulletin” formName=“Bulletin” computeWithForm=“onsave” action=“openDocument”>

</xp:dominoDocument>

</xp:this.data>

The problem I was having is that setting the value in the ‘querysavedocument’ event meant the field wasn’t stored as a readers field - just text, and I couldn’t get a handle on the field to change its type until after it was saved (hence saving the field twice).

Karl

Subject: Yes, thank you :slight_smile:

I was not sure, whether there was not some more code to be added.

Subject: This is a good question, and an enhancement to be addressed…

Sometime in the future (not saying when) you’ll be able to have an edit box and be able to assign a hidden tag. Right now we don’t have that in there.

But here’s how you can get around it.

On the ‘afterPageLoad’ event for the XPage put the following…

getComponent(‘inputText1’).rendererType = ‘javax.faces.Hidden’

…with ‘inputText1’ being the edit box name you wish to be hidden.

This will hide the value at runtime.

Here’s an example in full…

<xp:this.afterPageLoad>

<![CDATA[#{javascript:getComponent('inputText1').rendererType = 'javax.faces.Hidden'}]]>

</xp:this.afterPageLoad>

<xp:inputText id="inputText1" value="#{requestScope.val01}"

	defaultValue="#{javascript:@Unique()}">

</xp:inputText>

<xp:br></xp:br>

<xp:button value="Submit" id="button1">

	<xp:eventHandler event="onclick" submit="true"

		refreshMode="complete" immediate="false" save="true"></xp:eventHandler>

</xp:button>

<xp:br></xp:br>

<xp:text escape="true" id="computedField1" value="#{requestScope.val01}"

	style="color:rgb(128,0,255);font-weight:bold"></xp:text>

Subject: ComputeWithForm?

Many thanks for the suggestions. After I wrote my message, I discovered the ‘computeWithForm’ on query save property (under ‘data’), which achieved 90% of what I was wanting to do.

I re-wrote the other 10%, but it was a bit painful, so these techniques will be useful going forward.

Thanks again,

Karl

Subject: hidden input field in 8.5.1

tried this suggestion (in 8.5.1) and the field does not show up in the HTML at all. I’m lookng to a type=hidden field in html. It was pointed out to me that there’s a new hidden input field in 8.5.1 but that doesn’t work for me either in any type of repeat control/datatable/view control.

suggestions/help?