Friday, May 31, 2013

Re: Dynamically generated HTML and GWT

Now, this has gone from fun to just downright frustrating.  I'm stuck at the point of finding and wrapping the submit button.  I get the ubiquitous, "A widget that has an existing parent widget may not be added to the detach list".  Looked through the dozens of posts regarding that message.  The most common response is "don't use wrap() the way are using it".  There's also, "that's not the use case for wrap()".  Maybe one of these is true in my case.

Code is fairly simple.

uibinder:
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:ScrollPanel width="100%" height="100%" ui:field="mainScrollPanel"/>
</ui:UiBinder> 

The view class's onLoad() (this is an Activites and Places app that uses MVP).  So this view is on the right side of a splitterpanel.  The left side has a stackpanel (think of the mail example).  When the appropriate stack panel item is selected, this view appears on the right of the splitter.

public class ReviewView extends ResizeComposite
{
  ...

  @UiField ScrollPanel mainScrollPanel; 

private String html;  // Set in a separate method and called before onLoad().  This HTML comes from an external source.

  ...
public void onLoad()
{
mainScrollPanel.clear();
HTMLPanel htmlPanel = new HTMLPanel( html );
mainScrollPanel.add( htmlPanel );
Element submitButtonElement = htmlPanel.getElementById( "save" );    // This appears to work, without being deferred.  I tried it defered also.
Button submitButton = Button.wrap( submitButtonElement );                 // This is where the assert exception occurs.
}
}

Of course the HTMLPanel has a parent widget, the ReviewView. And it is nested inside of a ScrollPanel, which is nested in a SplitterLayoutPanel, which is inside a RootLayoutPanel.  There are probably widgets attached to all of those.  So, can this be done? One solution in the posts is to wrap() from the inside out.  With an A&P app this seems nearly impossible as Widgets are always embedded in Widgets.  What is the point of wrap() if it is so finicky()?  

I also tried deferred method, replacing HTMLPanel with MyHtmlPanel:

onLoad() looks like this:

MyHtmlPanel htmlPanel = new MyHtmlPanel( html );
mainScrollPanel.add( htmlPanel );

And MyHtmlPanel looks like this:

private class MyHtmlPanel extends HTMLPanel
{
public MyHtmlPanel( String html )
{
super( html );
}
protected void onAttach()
{
Element submitButtonElement = this.getElementById( "save" );    // Appears to work.
Button submitButton = Button.wrap( submitButtonElement );        // Same error occurs here.
}
protected void onDetach()
{
}
}




--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment