Git Product home page Git Product logo

Comments (4)

akudev avatar akudev commented on July 17, 2024 1

Hi,
defining a Dialog (or other popups) inside a View is indeed problematic because when the popup is opened, it is moved away from the View into a special area for popups. The connection to the View is then removed and the rendering (and data binding!) is independent then.

When one recommendation - using Fragments - cannot be used because Fragments do not have their own controller, you can since 1.20 use the "dependents" aggregation. In Views this is like a special area for defining popups that "belong to" the View and want to use the same controller - like this:

<View>
   <Button...>
   <dependents>
      <Dialog...>
   </dependents>
</View>

This will help avoid issues.

However, onAfterRendering of the controller is only called when the View itself is rendered, which does not happen, as Jiawei explained. When you are interested in the rendering of a control, you can add an event delegate to it.
https://sapui5.hana.ondemand.com/sdk/docs/api/symbols/sap.ui.core.Element.html#addEventDelegate
There should also be examples how this is used with afterRendering.

The validation things could also be caused by the above, so I'd close this ticket for now. If you still encounter issues after fixing the code, a runnable example would be very helpful. Even in jsbin you can declare XMLViews inline (e.g. http://jsbin.com/openui5-customdata-xmlview/1/edit), otherwise you can prepare a Gist. http://scn.sap.com/docs/DOC-50988

Regards
Andreas

from openui5.

hschaefer123 avatar hschaefer123 commented on July 17, 2024 1

Hi guys,
thanks for all the help!

The evil part was having Dialog as part off the view.
Also attaching a controller to the fragments does not really work because controller standalone wll not behave as expected (so controller is more a ViewController only).

For best flexibility my final solution Finally my solution follows Jiawei.

I am using a SelfregistrationDialog.fragment.xml

<core:FragmentDefinition 
    xmlns="sap.m"
    xmlns:core="sap.ui.core" 
    xmlns:mvc="sap.ui.core.mvc" >
    <Dialog title="{i18n>UME_SELFREGISTRATION_TITLE}" icon="sap-icon://activity-individual"
        contentWidth="96%" contentHeight="96%" stretchOnPhone="true">
        <content>
            <mvc:XMLView id="login-selfregistration" viewName="view.login.Selfregistration"></mvc:XMLView>
        </content>
        <beginButton>
            <Button text="{i18n>REGISTER}" icon="sap-icon://accept" press="onDialogSubmitButton" />
        </beginButton>
        <endButton>
            <Button text="{i18n>CANCEL}"  icon="sap-icon://sys-cancel" press="onDialogCancelButton" />
        </endButton>
    </Dialog>
</core:FragmentDefinition>

that references the used view "view.login.Selfregistration".

Now i can user the DialogFragment inside rootView

this._getFragment("SelfregistrationDialog").open();

where fragments are resolved

    _getFragment : function(sName, oController) {   
        var aViewName = this.getView().getViewName().split("."); // view.login.Login
        aViewName.pop();
        var sViewPath = aViewName.join(".") + "."; // view.login.
        if (!this._fragments[sName]) {
            if (oController && typeof oController === "string") {               
                oController = sap.ui.controller(sViewPath + oController);
            } else { 
                oController = this;
            }
            this._fragments[sName] = sap.ui.xmlfragment(
                sViewPath + sName, 
                oController
            );
            // version >= 1.20.x
            this.getView().addDependent(this._fragments[sName]);
        }
        return this._fragments[sName];
    }

Doing it this way, all my needs are fullfilled ;-)

  • i can use the Selfregistration Dialog as a Standalone Page or as a Dialog out-of-the-box
  • the logic is separated inside custom controller
  • the global core models are attached to the view
  • the view specific models are working as expected
  • controller onInit and onAfterRendering are fired as expected
  • ValidationErrors are fired on view input fields

Thanks for the needed background infos to get a deeper understanding of the core behavior especially for the internal dialog handling.

Also thanks to Andreas to forward me how to include xml view content in JSBIN. I will prepare my custom error template for future issues so that you quickly are able to find out if it is a bug or not without addtional overhead. (but i will also documentate such things on my blog to make it easier for others to do something similar).

Cheers Holger

from openui5.

stopcoder avatar stopcoder commented on July 17, 2024

Hi,

I can explain why the onAfterRendering function isn't called. The view is instantiated with sap.ui.xmlview and that's why its init method is called. However, this XMLView is never rendered. The Dialog is fetched from the view instance via id which is rendered when open method is called. But the view itself is only instanciated but never rendered because it doesn't have a parent and also not placed at some dom element by calling placeAt method. This is why the onAfterRendering isn't called.

If you want to attach a separate controller to the content of the dialog, please try to put the content of the dialog into a view and add this view to dialog. This view can have its own controller and dialog can be declared inside a fragment.

I have for now no idea why the input validation handler isn't called. It may be also solved by putting the content of dialog into a separate view and keeping the dialog in a fragment.

Best regards,
Jiawei

from openui5.

akudev avatar akudev commented on July 17, 2024

For future reference: an XMLView cannot have as direct children, as it interprets all child nodes as content of its default aggregation. See the API doc for this hint as well. So ther eneeds to be some content, to which the tag is added.

from openui5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.