1

I have a simple button with the eventHandler:

<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
        <xp:this.action>
            <xp:openPage target="newDocument" name="/doc.xsp"></xp:openPage>
        </xp:this.action>
</xp:eventHandler>

In lotusScript I would add a value to a field, before composing the form, using:

Call doc_new.ReplaceItemValue("txt_codformularmain","01")
....
....
Set uidoc = w.EditDocument ( True, doc_new )  

I tried in the postNewDocument event of the doc.xsp

<xp:this.data>
    <xp:dominoDocument var="Contr" formName="(fmFormularCIP)">
        <xp:this.postNewDocument><![CDATA[#{javascript:Contr.replaceItemValue("txt_codformularmain", "01")}]]></xp:this.postNewDocument></xp:dominoDocument>
</xp:this.data>

I don't want every time the doc is created that value to be, let say, 01, BUT only when the doc. is composed by a specific button. Some other button will have the chance to add the 02 value for that field, and so on.

How can I achieve this in xpages development? Thanks for your time.

Florin M.
  • 2,159
  • 4
  • 39
  • 97

1 Answers1

1

This is a little bit tricky in Web application development, because what you did in classical Notes development cannot be applied here. I had a lot of issues in this.

The classical scenario is that you have a Page X with some value (say txt_codformularmain will be 01). How do you decide this value "01"?

In some cases, this value is something you have in the page X. So you want to pass a specific value to the target page. One option could be using a query parameter (doc.xsp?myValue=01) and consume it on doc.xsp with param.myValue. Or, you might put a sessionScope variable before going to the target page and consume it by sessionScope.myValue.

It depends on what you need. Query parameter is somewhat safer, because the user might use the same button twice and sessionScope variable causes inconsistent behaviour. On the other hand, query parameter can be changed by the user, so you might have a breach in your application.

Some cases, you want to populate some values at the second page. Simple values (e.g. creation date, user names, etc.) can be populated with forms (i.e. compute value on load). Sometimes it would be more complicated (e.g. the department of the user where you have to lookup some views). For such cases, you need to use postNewDocument event at the target page.

After you have passed the value to the doc.xsp page, you will consume in the way you need. If it's not going to be edited on the page, you may again use postNewDocument event and set value by dataSourceName.replaceItemValue('itemName', param.myValue). If the value can be edited, you would use it as a default value on your field component.

One problem I have experienced: Once you set a value in postNewDocument, you may have problems to change it later, until the document data source saved. This is happening on specific cases. If you experience such a problem, you might use some editable field with readonly attribute. Just keep in mind :)

Serdar Basegmez
  • 3,355
  • 16
  • 20
  • It can be "0"as well as value. This field should be place on a panel, and it will be hidden. My desire is to use this field value to hide/show other fields based on this value. if this.value = "0" => some fields, after the action="newDocument", will be hidden or not, if this.value = "1" => some other fields will be hidden or not. – Florin M. Sep 04 '14 at 08:07
  • Then you don't have to save this value to any data source, right? – Serdar Basegmez Sep 04 '14 at 08:16
  • Unfortunately, I have to save because I'm using it in the view formula selection that lists some documents. for ex, vw1 lists some documents ( where this.value=0 ) , vw2 lists some documents ( where this.value=1 ) – Florin M. Sep 04 '14 at 08:28
  • It's not big deal, you should save it in 'postNewDocument' event. – Serdar Basegmez Sep 04 '14 at 11:41
  • So, the button code which ''compose'' new doc. should redirect the user to: http://server//myNsf.nsf//doc.xsp?myValue=01&action=newDocument ? And the respective field to have as the default value : param.myValue ? I never used something like this before, in classical lotus notes development, things were quite easier to achieve. – Florin M. Sep 04 '14 at 11:47
  • I updated my question, with my intention to add a value to the field from the XPage via the button which creates new document. – Florin M. Sep 04 '14 at 11:55
  • I saw your update. But that's not the place you can reach the new document. PostNewDocument event is on the doc.xsp page, data source events under the events page. The data source on another page is not accessible in the source page. – Serdar Basegmez Sep 08 '14 at 07:16