When I add the url to the list and then with ajax I try to show the contents of the list in some iframe, the page reloads

I am working on creating a toolbar and its gadgets are some links to different pages that I want to show inside an iframe. I have a button to add a new gadget to the control panel, and after adding a new one, I update the panel. For the first 3 gadgets in the app there is no problem and it works great. However, when I want to add the 4th gadget, the ajax call doesn't work and the page starts reloading again. After reloading the page, I can add a new gadget again and it works, but next time it stops working again and refreshes the page. I do not understand what the problem is. BTW, when I remove the iframe and I print the links themselves, the program runs without any problem. Here is my code:

<h:panelGrid columns="2" >
    <p:outputLabel value="${msg.dashboard_dashboard}" />
    <p:selectOneMenu value="#{dashboardDashletsManager.dashboard}" style="min-width: 200px" converter="#{dashboardConverter}" filter="true" filterMatchMode="contains" >
          <f:selectItems value="#{dashboardDashletsManager.dashboards}" var="item" itemLabel="#{item.description}" itemValue="#{item.value}" />
          <p:ajax update=":form" />
    </p:selectOneMenu>

    <p:outputLabel for="dashlet" value="${msg.dashboard_dashlet}" />
    <p:selectOneMenu id="dashlet"  value="#{dashboardDashletsManager.globalDashletToAdd}" style="min-width: 200px" converter="#{serviceProviderConverter}"  filter="true" filterMatchMode="contains">
          <f:selectItems value="#{dashletsController.globalDashlets}" var="provider" itemLabel="#{provider.description}" itemValue="#{provider}" />
    </p:selectOneMenu>

     <p:commandButton value="${msg.dashboard_add}" icon="ui-icon-plus" ajax="true" update=":form:dashboardPanel" process="dashlet @this"  actionListener="#{dashboardDashletsManager.addToDashboard}" />
</h:panelGrid>

 <p:outputPanel id="dashboardPanel">
        <ui:repeat value="#{dashboardDashletsManager.dashlets}" var="dashlet">
            <object width="400" height="400" type="text/html" data="#{dashlet.restUrl}"></object>
        </ui:repeat>
 </p:outputPanel>

      

+3


source to share


1 answer


There is probably a problem with the content you want to embed in the 4th danlet taking too long to load. Also, in your example, you are updating the whole form (not sure if you intend to do this), so the JSF renders it all again, and also the browser has to restore the content for the first three dashlets plus the fourth one.

Anyway, this little test case works correctly for me with Mojarra JSF 2.2.7 and Primefaces 5:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head />
<h:body>

    <h:form>
        <p:commandButton value="Add dashlet"
            action="#{dashboardManager.addDashlet}" update=":dashboardPanel" />
    </h:form>

    <p:outputPanel id="dashboardPanel">
        <ui:repeat value="#{dashboardManager.dashlets}" var="dashlet">
            <object width="400" height="400" type="text/html"
                data="#{dashlet.restUrl}"></object>
        </ui:repeat>
    </p:outputPanel>
</h:body>
</html>

      



@ManagedBean
@ViewScoped
public class DashboardManager {

    private static final String url = "http://www.w3schools.com";

    public class Dashlet {
        private String restUrl;

        public Dashlet(String url) {
            restUrl = url;
        }

        public String getRestUrl() {
            return restUrl;
        }

    }

    public DashboardManager() {
        dashlets.add(new Dashlet(url));
        dashlets.add(new Dashlet(url));
    }

    public List<Dashlet> dashlets = new ArrayList<Dashlet>();

    public List<Dashlet> getDashlets() {
        return dashlets;
    }

    public void addDashlet() {
        dashlets.add(new Dashlet(url));
    }

}

      

Here you can see that there is no problem displaying a set of dynamic tags on your board object

.

0


source







All Articles