Question

This is a continuation of a previous question that I asked last week.

I have an XPage. On this XPage I have a repeater. In this repeater, I have a custom control that I am using to display the contents of its own datasource - a NotesXspDocument. This control is repeated 5 to 10 times, maybe up to 15 times. I do not want to make the user press on save for each and every repeated control, so I am using the submit button feature as described in the above linked question.

When the user presses the submit button, I am using the querySaveDocument and the postSaveDocument actions on the events tab (I also tried the properties with the same name in the Data tab with the same result). My issue is the following:

The validation is executed one control instance after another until the validation fails immediately saving the datasource before moving on to the next instance. When a NEW document is saved, it seems like the XspDocument is gone and the fields are emptied. I have checked, and I have set the datasource scope to view, as this behavior somehow resembles requestScope. As soon as I reload the page, the information is correctly presented.

I could use "context.reloadPage()" to just get the updated information, but this has the nasty side effect of removing all unsaved information (for example if validation failed on the xth line). How might I best go about solving/troubleshooting this issue? What should I be paying attention to? Has anyone else seen such a behavior?

I would love to call a validate function on all rows from the Containing XPage and then if all rows succeeded, then call the saveDataSources function. Any help is greatly appreciated!

Was it helpful?

Solution

A simple button outside your repeat control will do. I created this example:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:repeat id="repeat1" rows="30" value="#{javascript:4}">
        <xp:panel id="dataPanel" disableOutputTag="true">
            <xp:this.data>
                <xp:dominoDocument var="document1" formName="Demo2">
                </xp:dominoDocument>
            </xp:this.data>
            <xp:table>
                <xp:tr>
                    <xp:td>
                        <xp:label value="Subject!" id="subject_Label1" for="subject1">
                        </xp:label>
                    </xp:td>
                    <xp:td>
                        <xp:inputText value="#{document1.Subject}"
                            id="subject1" required="true">
                            <xp:this.validators>
                                <xp:validateRequired
                                    message="Say something">
                                </xp:validateRequired>
                                <xp:validateLength minimum="5"
                                    message="Say 5 characters or more">
                                </xp:validateLength>
                            </xp:this.validators>
                        </xp:inputText>
                    </xp:td>
                </xp:tr>
                <xp:tr>
                    <xp:td>
                        <xp:label value="Color!" id="color_Label1" for="color1">
                        </xp:label>
                    </xp:td>
                    <xp:td>
                        <xp:comboBox value="#{document1.Color}"
                            id="color1" defaultValue="red">
                            <xp:this.validators>
                                <xp:validateExpression
                                    message="We don't like red">
                                    <xp:this.expression><![CDATA[#{javascript:value != "red"}]]></xp:this.expression>
                                </xp:validateExpression>
                            </xp:this.validators>
                            <xp:selectItem itemLabel="red"></xp:selectItem>
                            <xp:selectItem itemLabel="yellow"></xp:selectItem>
                            <xp:selectItem itemLabel="green"></xp:selectItem>
                            <xp:selectItem itemLabel="blue"></xp:selectItem>
                            <xp:selectItem itemLabel="white"></xp:selectItem>
                            <xp:selectItem itemLabel="black"></xp:selectItem>
                        </xp:comboBox>
                    </xp:td>
                </xp:tr>
            </xp:table>
        </xp:panel>
    </xp:repeat>

    <xp:messages layout="table" style="color:red" id="messages1">
    </xp:messages>

    <xp:button value="Save?" id="button1">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="complete" immediate="false" save="true"></xp:eventHandler>
    </xp:button>

</xp:view>

It will not save any of the data unless all validations are satisfied and it will not remove any entered data either. Don't get into the way what XPages does automatically (you also don't brush a cat against her fur). Your validation should happen in the validator and let the data source be saved by the button. As you see: no Query/Post event code is needed here.

OTHER TIPS

I really don't get what you're trying to do so I'll just comment on a piece. If you want data to survive a context.reloadPage() I think you would need to bind your controls to sessionScope. ViewScope is probably wiped out during the reload but sessionScope should still be available.

Good Luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top