Monday, May 24, 2010

Re: I'm trying out an example I found in a GWT book. In side the .html file, whenever I tried to name a <div> the same name as the class, nothing will be displayed on the screen.

GWT creates a hidden iframe with an id equal to whatever your module is renamed to. In your case, you had a div with id="Hangman", and GWT inserted an iframe with the exact same id. This caused the problem you were facing. Renaming the div got rid of the duplicate id, and that's why the application works.

Its frustrating, I know.

--Sri


On 24 May 2010 20:42, rudolf michael <roudolf@gmail.com> wrote:
The Id of the DIV always matter whenever you are doing RootPanel.get(myDivId) and it is case sensitive also.
this is applicable since GWT beta releases/

best regards,
Rudolf Michael


On Sat, May 22, 2010 at 2:51 PM, googling1000 <googling1000@gmail.com> wrote:
Hi,

This is my first attempt at GWT. Hope it will be a joyful experience.

I'm trying out a hangman example from this one book called Google Web
Toolkit Applications.
And, I spent the last two days trying to figure out why I couldn't see
anything on the screen, rather than the word "Hangman"

Finally, I noticed that the problem was caused by the name of a <div>
inside hangman.html


Right now, I'm displaying two buttons and a label.

/**********************************************
This is what I have under hangman.java:
**********************************************/
public class HangMan implements EntryPoint {
       public void onModuleLoad(){
               final Button button = new Button("Click me");
               final Label label = new Label();

               //to display a button with a letter "A"
               final char letter = 'A';
               final Button alphabutton = new Button(Character.toString(letter));
               RootPanel.get("mydiv").add(alphabutton);  //Please notice that I
named the div "mydiv" and the program works. Had I named the div
"hangman", I would not have seen anything on the screen, except the
word "Hangman"

               button.addClickHandler(new ClickHandler() {
                       @Override
                       public void onClick(ClickEvent event) {
                               if (label.getText().equals(""))
                                       label.setText("Hello World!");
                               else
                                       label.setText("");
                       }
               });
               //to display a button with the word "Click me"
               RootPanel.get("slot1").add(button);
               //to display a label
               RootPanel.get("slot2").add(label);
       }
}


/**********************************************
This is what I have under hangman.html:
**********************************************/
<!doctype html>
<html>
 <head>
   <meta http-equiv="content-type" content="text/html;
charset=UTF-8">
   <link type="text/css" rel="stylesheet" href="HangMan.css">

   <title>Hangman</title>
   <style>
       body,td,a,div, .p{font-family:arial, sans-serif}
       div,td{color:#000000}
       a:link,.w,.w a:linnk{color:#0000cc}
       a:visited{color: #551a8b}
       a:active{color: #ff0000}
   </style>
   <script type="text/javascript" language="javascript" src="hangman/
hangman.nocache.js"></script>
 </head>

 <body>
   <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1'
style="position:absolute;width:0;height:0;border:0"></iframe>
   <h1>Hangman</h1>
   <div id="mydiv"></div>   <!-- NOTE: when I named this div
"hangman", nothing appeared on the screen -->

   <table align="center">
     <tr>
       <td id="slot1"></td><td id="slot2"></td>
     </tr>
   </table>
 </body>
</html>

I would really like someone to help shed some light no this.
What is the explanation behind this?
And, the Google Web Toolkit Applications book named the <div>
"hangman" and I believe that means it must have worked fine for the
author. Does this mean that maybe the name of the <div> didn't matter
in the earlier versions of GWT?

Thank you in advance for any input!
Fran

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


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

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

No comments:

Post a Comment