简体   繁体   中英

How to do reload a page in SAPUI5?

I want to do reload the page "Menu" after I save data with CRUD.

var sUrl = "/sap/opu/odata/sap/ZGW_VISTORIA_SRV";
        var oModel = new sap.ui.model.odata.ODataModel(sUrl, true);
        var rota = this.getOwnerComponent().getRouter();
        var page = this;

        oModel.create('/vistoria', dados, null,
            function () {
                MessageBox.success('Cadastrado com sucesso!', {
                    onClose: function (sActionClicked) {
                        oStorage.clear();
                        oStorage.removeAll();
                        // oStorage.put("Save", {
                        //  isSave: true
                        // });
                        page.getView().exit();
                        page.getView().destroy();
                        // oStorage.get("Menu").menu.getModel().refresh(true);            
                        rota.navTo("Menu", false);
                        // window.location.reload(window.history.go(-3));
                        // sap.ui.getCore().byId("Menu").getModel().refresh(true);
                    }
                });
            },
            function () {
                MessageBox.error('Erro ao cadastrar o veiculo!');
            }
        );

I tried this in many ways, because I need to delete the information I save in forms. So, can you help me?

First of all it'd be nice if u posted all your relevant code (the form too) next time,
but i think i understand what you want to do.
( resetting the form, NOT reloading the page )
(reloading the entire view would take way longer than just resetting the form )

The way to go is to bind the values of input / checkbox etc. that are inside your form in a model:

<Input
    id="someID"
    value="{urModel>/inputValue}"
    valueState="{vsModel>/vsInput}"
    valueStateText="{i18n>vstInput}"/>

then in your success methode or ur create you reset those values:

urRemoteModel.create("/urSet", oEntry, {
    success: function(oRetrievedResult) {
        this.getView().getModel(urModel).setProperty("/inputValue", "");
        //some other stuff

    }.bind(this),
        error: function(oError) {
        //error handling
     }
});

Sorry about my delay. I'm creating an app for checking trucks. When user to end the survey and saving, he will be redirect to page 'Menu'.

In that page, he can choice to do a new survey, clicking in the tile 'Cadastrar'. Here where there are the form that must clear:

<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:form="sap.ui.layout.form" xmlns:core="sap.ui.core"
controllerName="com.sap.build.standard.formInspecaoDeVeiculos.controller.Identificacao">
<Page showHeader="true" title="Indenificação" showFooter="true" showNavButton="true" navButtonPress="_onPageNavButtonPress">
    <content>
        <Panel height="auto" width="auto" headerText="" expandable="false" expanded="true" expandAnimation="true" backgroundDesign="Solid"
            class="sapUiTinyMargin sapUiContentPadding">
            <content>
                <form:Form width="100%" editable="true" visible="true">
                    <form:title>
                        <core:Title text="Veículo" level="Auto"/>
                    </form:title>
                    <form:formContainers>
                        <form:FormContainer visible="true">
                            <form:formElements>
                                <form:FormElement visible="true">
                                    <form:label>
                                        <Label text="Veículo" design="Standard" width="100%" required="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </form:label>
                                    <form:fields>
                                        <Input id="tratorInput" placeholder="Ex.: ABC1234" type="Text" showValueHelp="true" enabled="true" visible="true" width="auto"
                                            valueHelpOnly="false" maxLength="0" valueHelpRequest="handleValueHelp" suggestionItems="{/Veiculo}"
                                            value="{ path : '/placa', type : '.customPlacaType' }" valueLiveUpdate="{/ValueLiveUpdate}" liveChange="handleLiveChange">
                                            <suggestionItems>
                                                <core:Item text="{Placa}"/>
                                            </suggestionItems>
                                        </Input>
                                    </form:fields>
                                </form:FormElement>
                                <form:FormElement visible="true">
                                    <form:label>
                                        <Label text="Reboque(1)" design="Standard" width="100%" required="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </form:label>
                                    <form:fields>
                                        <Input id="reboque1Input" placeholder="Ex.: ABC1234" type="Text" showValueHelp="true" enabled="true" visible="true" width="auto"
                                            valueHelpOnly="false" maxLength="0" valueHelpRequest="handleValueHelp" suggestionItems="{/Reboque}"
                                            value="{ path : '/placa', type : '.customPlacaType' }" valueLiveUpdate="{/ValueLiveUpdate}" liveChange="handleLiveChange">
                                            <suggestionItems>
                                                <core:Item text="{Placa}"/>
                                            </suggestionItems>
                                        </Input>
                                    </form:fields>
                                </form:FormElement>
                                <form:FormElement visible="true">
                                    <form:label>
                                        <Label text="Reboque(2)" design="Standard" width="100%" required="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </form:label>
                                    <form:fields>
                                        <Input id="reboque2Input" placeholder="Ex.: ABC1234" type="Text" showValueHelp="true" enabled="true" visible="true" width="auto"
                                            valueHelpOnly="false" maxLength="0" valueHelpRequest="handleValueHelp" suggestionItems="{/Reboque}"
                                            value="{ path : '/placa', type : '.customPlacaType' }" valueLiveUpdate="{/ValueLiveUpdate}" liveChange="handleLiveChange">
                                            <suggestionItems>
                                                <core:Item text="{Placa}"/>
                                            </suggestionItems>
                                        </Input>
                                    </form:fields>
                                </form:FormElement>
                                <form:FormElement visible="true">
                                    <form:label>
                                        <Label text="Motorista" design="Standard" width="100%" required="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </form:label>
                                    <form:fields>
                                        <Input id="motoristaInput" placeholder="Ex.: Nome do motorista" type="Text" showValueHelp="true" enabled="true" visible="true" width="auto"
                                            valueHelpOnly="false" maxLength="0" valueHelpRequest="handleValueHelp" suggestionItems="{/Motorista}" valueLiveUpdate="{/ValueLiveUpdate}"
                                            liveChange="handleLiveChange" value="{ path : '/Name1', type: '' }">
                                            <suggestionItems>
                                                <core:Item text="{Name1}"/>
                                            </suggestionItems>
                                        </Input>
                                    </form:fields>
                                </form:FormElement>
                                <form:FormElement visible="true">
                                    <form:label>
                                        <Label text="CPF" design="Standard" width="100%" required="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </form:label>
                                    <form:fields>
                                        <Input id="cpfInput" placeholder="Ex.: 00000000000" type="Text" showValueHelp="true" enabled="true" visible="true" width="auto"
                                            valueHelpOnly="false" maxLength="0" valueHelpRequest="handleValueHelp" suggestionItems="{/Motorista}" valueLiveUpdate="{/ValueLiveUpdate}"
                                            liveChange="handleLiveChange">
                                            <suggestionItems>
                                                <core:Item text="{Stcd2}"/>
                                            </suggestionItems>
                                        </Input>
                                    </form:fields>
                                </form:FormElement>
                            </form:formElements>
                            <form:title/>
                        </form:FormContainer>
                    </form:formContainers>
                    <form:layout>
                        <form:ResponsiveGridLayout adjustLabelSpan="false" columnsL="2" labelSpanL="3" columnsM="1" labelSpanM="2" labelSpanS="12"/>
                    </form:layout>
                </form:Form>
            </content>
        </Panel>
    </content>
    <footer>
        <OverflowToolbar width="100%" height="auto" design="Auto" enabled="true" visible="true">
            <content>
                <ToolbarSpacer width=""/>
                <Button text="" type="Emphasized" icon="sap-icon://navigation-right-arrow" iconFirst="true" width="auto" enabled="true" visible="true"
                    iconDensityAware="false" press="_onContinue"/>
            </content>
        </OverflowToolbar>
    </footer>
    <headerContent/>
    <subHeader/>
    <customHeader/>
</Page>

In my input i'm set de property value with "path: /placa" because I use an assitent for seach. In the next page 'Conclusao', where the user to finalize survey. My question: how I can to acess a Model from a page in onother page?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM