2
votes

I'm trying to add a value to an editBox using the PostNewDocument event of the xpage, considering the fact that I want the field to have the respective value when it is opened - using a specific button.

I have tried 2 approaches:

< using Simple Action:

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

( I'm getting: Unable to execute the set value simple action because not allowed to set the value of a read only computed expression. )

< using Script Editor ( server side )

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

( but still the field is "" )

My event handler from the button which opens the xpage:

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

How can I achieve this?

1

1 Answers

2
votes

This is a working example for an XPage which sets the value to an edit field in postNewDocument event. The value is visible in edit field after opening the Xpage.

<?xml version="1.0" encoding="UTF-8"?>
<xp:view
    xmlns:xp="http://www.ibm.com/xsp/core">
    <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>
    <xp:inputText
        id="inputText1"
        value="#{Contr.txt_codformularmain}">
    </xp:inputText>
</xp:view>

The value itself can be set from url with param.codvalue if url has a codvalue parameter like ...&codvalue=01or from a scope variable like sessionScope.codvalue.

Make sure you call this XPages without url parameter ?action=openDocument or ?action=editDocument as then the postNewDocument event doesn't get executed.