0
votes

I'm building in Domino Application with the Xpages extension library enabled a mobile page with an xe:singlePageApp and more xe:appPage(s). An xe:appPage is containing a panel having as data source a domino document. Within the same panel is a submit/save buttons I'm using to save the contents edited/changed in fields in document data source.

Due to indications of already posted questions and answers at Xomino , here on StackOverflow as well a on the XPages Wiki (links not provided here because I'm not allowed yet to post more than 2 links) - the submit button is within the panel and the data source is also declared for/within that panel (in the code below "panelDocContent").

The xp:inputText controls on the page have the same id and variable as the fields of the data source. If I set via SSJS in another button some values on the page - they are successfully set and a round rect list item with visibility depending on the set values is appearing as expected showing the fields also changed.

Problem: the Save/Submit button "Submit for approval" does not save the changes to the data source assigned to the panel.

I already tried also "ignoreRequestParams"=true set in the document data but this is in this context not an option. When I try this the corresponding document from the initial appPage with a DataView element supposed to open with the document AppPage is not loaded with its values - they are shown empty.

Any idea what I'm doing wrong here or what I could do different to submit the values in the editable changed fields (visible first when pressing "Request this tool" button ?

Here is the xPages / Custom control code:

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



    <xe:appPage id="docContent" pageName="docContent"
        resetContent="true">

        <xp:panel id="panelDocContent">
            <xp:this.data>
                <xp:dominoDocument var="docTool" formName="Tool"
                    action="editDocument" scope="request">
                </xp:dominoDocument>
            </xp:this.data>

            <xe:djxmHeading id="djxmHeading2" back="Back" style="text-align:center">

                <xe:this.moveTo><![CDATA[#{javascript:viewScope.get("pageToReturn");}]]></xe:this.moveTo>
                <xp:this.facets>
                </xp:this.facets>

                <xe:this.label><![CDATA[#{javascript:"Tool"}]]></xe:this.label>
            </xe:djxmHeading>

<!-- BUTTONS ! -->
<xp:panel id="preButtonPanel" style="font-size:8px;">.</xp:panel>

<xp:panel id="buttonPanel" style="text-align:center">
            <xp:button value="Request this Tool" id="button1" style="font-size:12pt">
                    <xp:this.rendered><![CDATA[#{javascript:_status = docTool.getDocument().getItemValueString("Status");

(_status=="Available")}]]></xp:this.rendered>
                    <xp:eventHandler event="onclick" submit="true"
                        refreshMode="complete">
                        <xp:this.action><![CDATA[#{javascript:docTool.getDocument().replaceItemValue("Status", "Requested");
docTool.getDocument().replaceItemValue("SubmissionStatus", "Not Submitted");}]]></xp:this.action>
                    </xp:eventHandler>
            </xp:button>
                <xp:button value="Submit for Approval" id="button4" style="font-size:12pt">
                    <xp:this.rendered><![CDATA[#{javascript:_status = docTool.getDocument().getItemValueString("Status");
_submissionstatus = docTool.getDocument().getItemValueString("SubmissionStatus");

(_status=="Requested") && (_submissionstatus == "Not Submitted") }]]></xp:this.rendered>

                <xp:eventHandler event="onclick" submit="true" refreshMode="complete">
                    <xp:this.action>

                        <xp:actionGroup>




                            <xp:executeScript>
                                <xp:this.script><![CDATA[#{javascript:if (docTool.isEditable()) {
         docTool.save();
         sessionScope.msg="Data source docTool saved.";
        _dump(sessionScope);
} else {
         sessionScope.msg= "Document not in edit mode";
}
_dump(sessionScope);
context.redirectToPage("#viewPage");


}]]></xp:this.script>
                            </xp:executeScript>
                        </xp:actionGroup>
                    </xp:this.action></xp:eventHandler></xp:button>



                </xp:panel>

                <xp:panel id="panelPostButtons" style="font-size:8px;">.</xp:panel>

    <!-- END OF BUTTONS -->

            <xe:djxmRoundRectList id="djxmRoundRectList2">
                <xp:messages id="errormessages1"></xp:messages>
            </xe:djxmRoundRectList>
            <xe:djxmRoundRectList id="djxmRoundRectList1">

                <xp:table style="width:100.0%">
                    <xp:tr>
                        <xp:td style="font-weight:bold">
                            Tool information
                        </xp:td>
                    </xp:tr>
                </xp:table>

                <xp:table style="width:100.0%">
                    <xp:tr>
                        <xp:td style="width:22.0%">Type</xp:td>
                        <xp:td style="width:69.0%">
                            <xp:label id="dspType">
                                <xp:this.value><![CDATA[#{javascript:docTool.getDocument().getItemValueString("ToolType");}]]></xp:this.value>
                            </xp:label>
                        </xp:td>
                    </xp:tr>
                    <xp:tr>
                        <xp:td style="width:22.0%">Part No.</xp:td>
                        <xp:td style="width:69.0%">
                            <xp:label id="dspPartNo">
                                <xp:this.value><![CDATA[#{javascript:docTool.getDocument().getItemValueString("PartNumber");}]]></xp:this.value>
                            </xp:label>
                        </xp:td>
                    </xp:tr>






                    <xp:tr>
                        <xp:td>Status</xp:td>
                        <xp:td>
                            <xp:label id="dspStatus">
                                <xp:this.value><![CDATA[#{javascript:docTool.getDocument().getItemValueString("Status");}]]></xp:this.value>
                            </xp:label>
                        </xp:td>
                    </xp:tr>
                    <xp:tr>
                        <xp:td>Submission status</xp:td>
                        <xp:td><xp:label id="dspSubmissionStatus">
                                <xp:this.value><![CDATA[#{javascript:docTool.getDocument().getItemValueString("SubmissionStatus");}]]></xp:this.value>
                            </xp:label></xp:td>
                    </xp:tr>
                </xp:table>
            </xe:djxmRoundRectList>


            <xe:djxmRoundRectList id="djxmRoundRectList3">


                <xe:this.rendered><![CDATA[#{javascript:_status = docTool.getDocument().getItemValueString("Status");
_submissionstatus = docTool.getDocument().getItemValueString("SubmissionStatus");

(_status!="Available") && (_submissionstatus != "") }]]></xe:this.rendered><xp:table style="width:100.0%">
                    <xp:tr>
                        <xp:td
                            style="font-weight:bold;color:rgb(255,0,0)">
                            Please enter following mandatory
                            information:
                        </xp:td>
                    </xp:tr>
                    <xp:tr>
                        <xp:td style="font-weight:bold">
                            Shipping Address
                        </xp:td>
                    </xp:tr>
                </xp:table>

                <xp:table style="width:100.0%">
                    <xp:tr>

                        <xp:td style="width:22%">
                            Company data
                            <xp:span
                                style="font-weight:bold;color:rgb(255,0,0)">
                                *
                            </xp:span>
                        </xp:td>
                        <xp:td style="width:69.0%">

                            <xp:inputText id="Company" style="width:99%"
                                value="#{docTool.Company}">
                            </xp:inputText>
                        </xp:td>
                    </xp:tr>
                    <xp:tr>

                        <xp:td style="width:22%">
                            Customer data
                            <xp:span
                                style="font-weight:bold;color:rgb(255,0,0)">
                                *
                            </xp:span>
                        </xp:td>
                        <xp:td style="width:69.0%">

                            <xp:inputText id="CustomerData"
                                style="width:99%" value="#{docTool.CustomerData}">
                            </xp:inputText>
                        </xp:td>
                    </xp:tr>
                    <xp:tr>

                        <xp:td style="width:22%">
                            Demo reason
                            <xp:span
                                style="color:rgb(255,0,0);font-weight:bold">
                                *
                            </xp:span>
                        </xp:td>
                        <xp:td style="width:69.0%">
                            <xp:inputText id="DemoReason"
                                style="width:99%" value="#{docTool.DemoReason}">
                            </xp:inputText>

                        </xp:td>
                    </xp:tr>


                </xp:table>

            </xe:djxmRoundRectList>


        </xp:panel>

        </xe:appPage>


</xp:view>

Here is also a link to ZIP with the entire application for getting the whole and direct idea of dependencies.

https://www.dropbox.com/s/rs1la3m0pfm548a/DemoTools_dev.zip?dl=0

I'll keep it there for the next 2-3 months.

In that code I also tried a simple "save document" action with the same data source indicated.

I've already spent a lot of time to get that solved and I'm stuck at this point. Any help will be much appreciated.

2

2 Answers

1
votes

A colleague in my team shown me how to bring my custom control with that problem to work.

He made the "Request for approval" button to do only a partial refresh of the rounded list where status is set - the one with computed labels only. The same button to use then client side javascript to hide/show buttons and rounded list with editable fields. The submit button can then set the status fields again and save the document behind the data source "docTool". With that trick the page does not refresh fully with the effect that the document handle is then lost for the "Submit for approval" button.

He taken also advantage of the possibilities to execute CSJS in other events than onclick. These events can be found by selecting the eventhandler for the button in the Source view and then look at All properites in the Properties panel. These can be used when a partial refresh is triggered.

Another part of the trick was using Computed value for style in All properties for the different elements client-side, insted of the "Visible" property (in code "rendered" on server-side).

Here is the code of the corrected custom control where the "Submit for approval" button works the way described above:

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

    <xe:appPage id="docContent" pageName="docContent"
        resetContent="true">

        <xp:panel id="panelDocContent">
            <xp:this.data>
                <xp:dominoDocument var="docTool" formName="Tool"
                    action="editDocument" scope="request">
                </xp:dominoDocument>
            </xp:this.data>

            <xe:djxmHeading id="djxmHeading2" back="Back"
                style="text-align:center">

                <xe:this.moveTo><![CDATA[#{javascript:viewScope.get("pageToReturn");}]]></xe:this.moveTo>
                <xp:this.facets>
                </xp:this.facets>

                <xe:this.label><![CDATA[#{javascript:"Tool"}]]></xe:this.label>
            </xe:djxmHeading>

            <!-- BUTTONS ! -->
            <xp:panel id="preButtonPanel" style="font-size:8px;">.</xp:panel>

            <xp:panel id="buttonPanel" style="text-align:center">
                <xp:button value="Request this Tool" id="buttonRequest">
                    <xp:this.rendered><![CDATA[#{javascript:_status = docTool.getDocument().getItemValueString("Status");

(_status=="Available")}]]></xp:this.rendered>
                    <xp:this.style><![CDATA[#{javascript:_status = docTool.getDocument().getItemValueString("Status");

var display = "none";
if(_status=="Available"){
    display = "inline-block";
} 

"font-size:12pt;display:"+display;}]]></xp:this.style>
                    <xp:eventHandler event="onclick" submit="true"
                        refreshMode="partial" refreshId="djxmRoundRectListDisplayFields">
                        <xp:this.action><![CDATA[#{javascript:docTool.getDocument().replaceItemValue("Status", "Requested");
docTool.getDocument().replaceItemValue("SubmissionStatus", "Not Submitted");}]]></xp:this.action>
                        <xp:this.onComplete>
                    <![CDATA[var buttonSubmit = "#{id:buttonSubmit}";
document.getElementById(buttonSubmit).style.display = "inline-block";

var buttonRequest = "#{id:buttonRequest}";
document.getElementById(buttonRequest).style.display = "none";

var editablefields_id = "#{id:djxmRoundRectListEditableFields}";
document.getElementById(editablefields_id).style.display = "block";]]></xp:this.onComplete>
                    </xp:eventHandler>
                </xp:button>

                <xp:button value="Submit for Approval" id="buttonSubmit">

                    <xp:this.style><![CDATA[#{javascript:_status = docTool.getDocument().getItemValueString("Status");
_submissionstatus = docTool.getDocument().getItemValueString("SubmissionStatus");

var display = "none";
if((_status=="Requested") && (_submissionstatus == "Not Submitted")){
    display = "inline-block";
} 

"font-size:12pt;display:"+display;}]]></xp:this.style>


                    <xp:eventHandler event="onclick" submit="true"
                        refreshMode="complete">
                        <xp:this.action><![CDATA[#{javascript:if (docTool.isEditable()) {
         print("Data source docTool saved.");
         docTool.replaceItemValue("SubmissionStatus", "Submitted");
         docTool.replaceItemValue("Status", "Requested");
         docTool.save();
} else {
        print("Document not in edit mode");
}
context.reloadPage();}]]></xp:this.action>


                    </xp:eventHandler>
                </xp:button>

            </xp:panel>

            <xp:panel id="panelPostButtons" style="font-size:8px;">.</xp:panel>

            <!-- END OF BUTTONS -->


            <xe:djxmRoundRectList id="djxmRoundRectListDisplayFields">


                <xp:table style="width:100.0%">
                    <xp:tr>
                        <xp:td style="font-weight:bold">
                            Tool information
                        </xp:td>
                    </xp:tr>
                </xp:table>

                <xp:table style="width:100.0%">
                    <xp:tr>
                        <xp:td style="width:22.0%">Type</xp:td>
                        <xp:td style="width:69.0%">
                            <xp:label id="dspType">
                                <xp:this.value><![CDATA[#{javascript:docTool.getDocument().getItemValueString("ToolType");}]]></xp:this.value>
                            </xp:label>
                        </xp:td>
                    </xp:tr>
                    <xp:tr>
                        <xp:td style="width:22.0%">Part No.</xp:td>
                        <xp:td style="width:69.0%">
                            <xp:label id="dspPartNo">
                                <xp:this.value><![CDATA[#{javascript:docTool.getDocument().getItemValueString("PartNumber");}]]></xp:this.value>
                            </xp:label>
                        </xp:td>
                    </xp:tr>

                    <xp:tr>
                        <xp:td>Status</xp:td>
                        <xp:td>
                            <xp:label id="dspStatus">
                                <xp:this.value><![CDATA[#{javascript:docTool.getDocument().getItemValueString("Status");}]]></xp:this.value>
                            </xp:label>
                        </xp:td>
                    </xp:tr>
                    <xp:tr>
                        <xp:td>Submission status</xp:td>
                        <xp:td>
                            <xp:label id="dspSubmissionStatus">
                                <xp:this.value><![CDATA[#{javascript:docTool.getDocument().getItemValueString("SubmissionStatus");}]]></xp:this.value>
                            </xp:label>
                        </xp:td>
                    </xp:tr>

                </xp:table>
            </xe:djxmRoundRectList>



            <xe:djxmRoundRectList id="djxmRoundRectListEditableFields">



                <xe:this.style><![CDATA[#{javascript:_status = docTool.getDocument().getItemValueString("Status");
_submissionstatus = docTool.getDocument().getItemValueString("SubmissionStatus");

var display = "none";
if((_status!="Available") && (_submissionstatus != "")){
    display = "block"
} 

"display:"+display;}]]></xe:this.style>
                <xp:table style="width:100.0%">
                    <xp:tr>
                        <xp:td
                            style="font-weight:bold;color:rgb(255,0,0)">
                            Please enter following mandatory
                            information:
                        </xp:td>
                    </xp:tr>
                    <xp:tr>
                        <xp:td style="font-weight:bold">
                            Shipping Address
                        </xp:td>
                    </xp:tr>
                </xp:table>

                <xp:table style="width:100.0%">
                    <xp:tr>

                        <xp:td style="width:22%">
                            Company data
                            <xp:span
                                style="font-weight:bold;color:rgb(255,0,0)">
                                *
                            </xp:span>
                        </xp:td>
                        <xp:td style="width:69.0%">

                            <xp:inputText id="Company" style="width:99%"
                                value="#{docTool.Company}">
                            </xp:inputText>
                        </xp:td>
                    </xp:tr>
                    <xp:tr>

                        <xp:td style="width:22%">
                            Customer data
                            <xp:span
                                style="font-weight:bold;color:rgb(255,0,0)">
                                *
                            </xp:span>
                        </xp:td>
                        <xp:td style="width:69.0%">

                            <xp:inputText id="CustomerData"
                                style="width:99%" value="#{docTool.CustomerData}">
                            </xp:inputText>
                        </xp:td>
                    </xp:tr>
                    <xp:tr>

                        <xp:td style="width:22%">
                            Demo reason
                            <xp:span
                                style="color:rgb(255,0,0);font-weight:bold">
                                *
                            </xp:span>
                        </xp:td>
                        <xp:td style="width:69.0%">
                            <xp:inputText id="DemoReason"
                                style="width:99%" value="#{docTool.DemoReason}">
                            </xp:inputText>

                        </xp:td>
                    </xp:tr>


                </xp:table>

            </xe:djxmRoundRectList>


        </xp:panel>

        </xe:appPage>

</xp:view>

Here is also dropbox link with a zipped copy of the entire database with this construct for testing. I think I'll keep it 6 months from now:

https://www.dropbox.com/s/2iy00xc10v3tis4/DemoTools_dev_forforums2.zip?dl=0

0
votes

This is NOT an answer but an attempt to give some information and I needed more room then the comments allowed. I downloaded and played with this for a little but. I'm not sure what's going on here.

You're save button is a little odd. I added a print statement and couldn't get anything to print. It's in an action group for now reason so you might want to get rid of that and just redo the button. Since there was only 1 action I would NOT use the simple action - execute script - I'd just type the code in via the script editor. After doing that I got mu print statements and it LOOKED like it saved but each save caused a replication conflict and the customer data wasn't even there. So there's some fundamental issue I'm not seeing.

One thing that I'm missing... and it might be because I don't work with DataView controls but I'm not seeing how the data document is being linked. You're declaring the "docTool" var in your Panel dataSource... but there's no document ID in there. So I'm not seeing how that's supposed to work. Obviously it is to some extent at least because you're reading data.

I'd be curious to try and rebuild this from scratch to try and replicate but personally I just don't like Mobile controls anymore and don't recommend them but what you're doing here is "simple enough" and should work. But I'm sure stumped at the moment without putting more time in.

Suggest you step back - add more print("") statements... to output info to the console. For instance in your dataSource I could get a message to print on document open but not anything for document save.

Below is the little code for a new save button that I was playing with. Again I got it to save but it only created conflicts.

another note. Everywhere for reading you're doing docTool.getDocument()..... but for save you're just docTool.save(). So the conflicts might be a result of the XSPDocument vs the real document. I'm not sure. I have to think that if you can get into your dataSource the documentID that MIGHT solve your problems. but that's just a guess.

Good Luck!

<xp:button value="New Save" id="button5">
                    <xp:eventHandler event="onclick" submit="true" refreshMode="complete">
                        <xp:this.action><![CDATA[#{javascript:print("CHECKING")
if (docTool.isEditable()) {
print("Editable")
         docTool.save();
         print("Data source docTool saved.");

} else {
    print("NOT EDITABLE")
        print("Document not in edit mode");
}

context.redirectToPage("#viewPage");


}]]></xp:this.action>
                    </xp:eventHandler></xp:button>