Hi all,

I want to use an InlineFrame with a custom pagemap.
I created some simple demo code to illustrate, but I have some problems 
with it ...

To create an InlineFrame with custom pagemap, there was the possibility to 
choose from three different constructors on InlineFrame ...

1.  --> public InlineFrame(final String id, final IPageMap pageMap, final 
Class c) 
This one is unusable to me as I cannot pass any constructor parameters for 
page creation.

2. --> public InlineFrame(final String id, final IPageMap pageMap, final 
Page page)
I tried this one, by first creating my page as follows ...

Page iframePage=Session.get().getPageFactory().newPage(IframePage.class, 
pageParameters);
final InlineFrame iFrame =new 
InlineFrame("iframePage",PageMap.forName(IFRAME_PAGEMAP), iframePage); 

If I use this, the pagemap is not initialized correctly in the subframe 
(it's null, same as my main pagemap)

3. --> public InlineFrame(final String id, final IPageMap pageMap, 
IPageLink pageLink)
This one works, but is not very practical to code ...

final InlineFrame iFrame = new InlineFrame("iframePage",
              PageMap.forName(IFRAME_PAGEMAP),
              new IPageLink() {
            public Page getPage() {
              return 
Session.get().getPageFactory().newPage(iframePageClass,
                  pageParameters);
            }

            public Class getPageIdentity() {
              return iframePageClass;
            }
          });

So the question for you guys is the following ...
Am I doing something totally wrong here,
or if this is a correct way to deal with iframes?

Is the second constructor supposed to work?
Is this an issue or am I trying to create the page at the wrong time in 
program flow?

Is it possible to add a constructor to InlineFrame that takes following 
parameters ...
InlineFrame, PageMap, PageClass, PageParameters

Is this an option to have such a constructor?
I'm fairly new to wicket, so please do not hesitate to point out my 
mistakes.
Thank you in advance for taking the time to look at this.


Code included ...


===== mainpage.java =====

package com.tvh.test;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitButton;
import org.apache.wicket.ajax.AjaxRequestTarget;
import java.util.Map;
import java.util.HashMap;
import org.apache.wicket.markup.html.link.InlineFrame;
import org.apache.wicket.PageMap;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.IPageLink;
import org.apache.wicket.Session;
import org.apache.wicket.Page;
import org.apache.wicket.model.Model;
import com.tvh.test.MainPage.InputForm;
import org.apache.wicket.markup.html.basic.Label;

public class MainPage
    extends WebPage {
  private static final String IFRAME_PAGEMAP = "iframePageMap";
  public MainPage() {
    TestBean testBean = new TestBean("initValOne", "initValTwo");
    add(new InputForm("inputForm", new CompoundPropertyModel(testBean)));
    add(new Label("pageMap", new Model(getPageMap())));
    final InlineFrame iFrame = new InlineFrame("iframePage",
 PageMap.forName(IFRAME_PAGEMAP),
                                               IframePage.class);
    iFrame.setOutputMarkupId(true);
    add(iFrame);
  }

  public class InputForm
      extends Form {
    public InputForm(String id, IModel model) {
      super(id, model);
      final TestBean testBean = (TestBean) getModel().getObject();
      add(new TextField("valueOne"));
      add(new TextField("valueTwo"));
      add(new AjaxSubmitButton("ajaxSubmitButton", this) {
        protected void onSubmit(AjaxRequestTarget ajaxRequestTarget, Form 
form) {
          Map pageParameterMap = new HashMap();
          pageParameterMap.put("passthrValOne", testBean.getValueOne());
          pageParameterMap.put("passthrValTwo", testBean.getValueTwo());

          final PageParameters pageParameters = new PageParameters(
              pageParameterMap);
          final Class iframePageClass = IframePage.class;

          final InlineFrame iFrame = new InlineFrame("iframePage",
              PageMap.forName(IFRAME_PAGEMAP),
              new IPageLink() {
            public Page getPage() {
              return 
Session.get().getPageFactory().newPage(iframePageClass,
                  pageParameters);
            }

            public Class getPageIdentity() {
              return iframePageClass;
            }
          });
          iFrame.setOutputMarkupId(true);
          MainPage.this.replace(iFrame);

          ajaxRequestTarget.addComponent(form);
          ajaxRequestTarget.addComponent(iFrame);
        }
      });
    }
  }
}

===== mainpage.html =====

<html>
  <head>Main Page</head>
  <body>
    <h1>Main Page</h1>
    PageMap: <span wicket:id="pageMap"></span><br/>
    <form wicket:id="inputForm">
    Value one: <input type="text" wicket:id="valueOne"/><br/>
    Value two: <input type="text" wicket:id="valueTwo"/><br/>
    <input type="button" wicket:id="ajaxSubmitButton"/>
    </form>
    <iframe wicket:id="iframePage" style="width:100%; 
height:100%"></iframe>
  </body>
</html>

===== IframePage.java =====

package com.tvh.test;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.Model;
import org.apache.wicket.PageParameters;
import org.apache.wicket.model.PropertyModel;

public class IframePage extends WebPage {
  public IframePage() {
    this(null);
  }
  public IframePage(PageParameters pageParameters) {
 
    TestBean testBean = new TestBean();
 
    // Fill testBean with passed page parameters
    if(pageParameters != null) {
      testBean.setValueOne((String)pageParameters.get("passthrValOne"));
      testBean.setValueTwo((String)pageParameters.get("passthrValTwo"));
    }
 
    add(new Label("pageMap", new Model(getPageMap())));
    add(new Label("passthrValOne", new PropertyModel(testBean, 
"valueOne")));
    add(new Label("passthrValTwo", new PropertyModel(testBean, 
"valueTwo"))); 
  }
}

===== IframePage.html =====

<html>
  <head>IFrame Page</head>
  <body>
    <h1>IFrame Page</h1>
    PageMap: <span wicket:id="pageMap"></span><br/>
    Passed value one: <span wicket:id="passthrValOne"></span><br/>
    Passed value two: <span wicket:id="passthrValTwo"></span><br/>
  </body>
</html>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to