|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
|
|
|
Re: Netbeans/Hidden field questionRick Fincher wrote:
> Hi Neil, > > No problem on the help. Figuring this stuff out cost me many handfuls > of hair! Rick, That's great - I don't have much hair left to pull out, so my wife says thank you! :) I missed the hidden field in the palette yesterday (no pun intended...) - I will give that a try and see what happens... And I'm just getting started with javascript - I've been writing java code for 10 years (and C/C++ for more than 30...) but I've only been doing web related java for a couple of years now - so this is fairly new for me. As I said yesterday, I had to return to Netbeans 6.0.1 because it seems that 6.1 was not actually creating java code for ANY of the palette items I created - buttons, text fields - nothing. My project was originally created in 6.0.1 and seemed to compile fine with 6.1, and I could add new items to the screen in 6.1 but I was unable to modify them in the code because they were not defined - very strange. So for now, I'm back to 6.0.1 and once I get this javascript stuff figured out, I'll try 6.1 again and see what happens there - maybe I did something dumb.... Thanks for the help - If I get stuck again I'll let you know... nbc > > A hidden field is a special type of text field in HTML. The component > palette has it in there below the password field. It acts just like a > text field, but it is always invisible on the screen. JSF saves the > contents of all the screen controls and restores them if the page is > redrawn (as happens when a submit button action returns a null). > > If you use a regular text field and make it invisible, its contents > don't get sent forward when the page redraws. > > To access a hidden field called hiddenFieldWeight in Java use: > hiddenFieldWeight.getValue() > > To access it in Javascript in your onClick() or onLoad() (only in the > body component) use: > > document.getElementById("form1:hiddenFieldWeight_field").value > > Notice there is a "_field" added to the end of the name. JSF does > that internally to help keep things straight. > > You won't see that on the JSP page, you have to look for it in the > browser. When your page gets drawn, use the "view source" of the > browser to see the actual HTML code that JSF generates for the page. > If you are unsure of what the components name gets set to, just search > for the name you gave it in the visual editor. The component will > always start with that name followed by an underscore and some > description like "_field" or "_dropdown". > > Another thing that is handy to know is the "isPostBack()" method. You > can call it with or without the "this" as in "this.isPostBack()". I > always forget the name of it so typing this with a dot brings up all > the page stuff. > > The isPostBack() method returns false the first time a page is drawn > and true each time a submit call re-renders it after that. > > The preprocess() method on the page only gets called on a postback, > never on the initial rendering of the page, so it is handy too. > > The neat thing about using Javascript for this is the speed. You > don't get the 3-5 second delay while the page gets submitted. Ajax > would work for this too but there is still going to be some time lag. > > Basically, you just put a Javascript in the onChange() Javascriptof > each component that you want to be sure is saved. The Javascript > stuff a value in the hidden field to flag a change. > > The Javascript will show up in the JSP page automatically. > > I tend to think in terms of Java, so sometimes the Javascript stuff > confuses me because I don't see it in the Java code. I guess its part > of the "View" in the "Model-View-Controller" design pattern, but it > actually affects the logic of the program, not just how it looks. > > So, if you like you can set the script from Java. You do this with > the "setValueBinding()" method of the component. With that you can > set any of a components properties that show up in the parameters > window when you click on a component. > > Say you want to change the text in a button, called button1, under > program control. You would use: > > button1.setValueBinding("text", > getApplication().createValueBinding("New Button Text")); > > To set the onLoad() Javascript of the body it would be something like: > > String confirmScript = "confirm(\"Are you sure? Unsaved changes!\"); > body1.setValueBinding("onLoad", > getApplication().createValueBinding(confirmScript)); > > I'm not actually sure about escaping the quoting in the string, you > may have to use """ instead of \". > > You can also use page parameters with their script language > identifiers. This is nice if you want to use stuff looked up from a > database to set the values. Some examples with a hyperlink are: > > hyperlinkCert.setValueBinding("visible", > getApplication().createValueBinding("#{page1.certIconVisible}")); > hyperlinkCert.setValueBinding("target", > getApplication().createValueBinding("#{page1.blankValueBinding}")); > hyperlinkCert.setValueBinding("url", > getApplication().createValueBinding("#{page1.viewCertURL}")); > hyperlinkCert.setValueBinding("style", > getApplication().createValueBinding("#{page1.certUrlStyle}")); > > Hope this helps! > > Rick > > > Neil B. Cohen wrote: >> Morning Rick, >> >> I had asked about using AJAX with Netbeans and you sent me a >> suggestion (at home - nbc@...) regarding using a hidden >> field and javascript to decide whether or not to put up a >> confirmation dialog. I was looking at how to implement that this >> morning, and I'm a bit confused... >> >> I can create a static text field and make it 'hidden' on my web page. >> But in my java code, it doesn't show up as a member variable anywhere >> - it is only an element in the jsp code itself. How do I access that >> element from within my java code to change the text from 'clean' to >> 'dirty' or whatever... I feel like I'm missing something simple here >> but I'm not sure what it is... >> >> If I figure it out I'll let you know... Sorry to bother you with >> this, but I like your suggestion - I think it will work if I can put >> all the pieces together, >> >> Question - is this a problem with Netbeans 6.1?? (I just installed >> 6.1 yesterday). I just created a text field and it doesn't seem to >> create a corresponding object in the java code... There is nothing in >> the init() routine.... Should I be switching back to 6.0.1?? >> >> >> thanks, >> >> nbc >> >> NAME: Neil B. Cohen (Verisign Inc.) >> PHONE: 703-948-4471 >> DOMAIN: ncohen@... >> ************************************************************* >> * Murphy's Philosophy: Smile - tomorrow will be worse... >> * >> * O'Tooles Commentary: Murphy was an optimist! >> ************************************************************* > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
|
|
|
Re: Netbeans/Hidden field questionNeil B. Cohen wrote:
> Rick Fincher wrote: >> Hi Neil, >> >> No problem on the help. Figuring this stuff out cost me many >> handfuls of hair! > Rick, > > That's great - I don't have much hair left to pull out, so my wife > says thank you! :) > I missed the hidden field in the palette yesterday (no pun > intended...) - I will give that a try and see what happens... And I'm > just getting started with javascript - I've been writing java code for > 10 years (and C/C++ for more than 30...) but I've only been doing web > related java for a couple of years now - so this is fairly new for me. > > As I said yesterday, I had to return to Netbeans 6.0.1 because it > seems that 6.1 was not actually creating java code for ANY of the > palette items I created - buttons, text fields - nothing. My project > was originally created in 6.0.1 and seemed to compile fine with 6.1, > and I could add new items to the screen in 6.1 but I was unable to > modify them in the code because they were not defined - very strange. > So for now, I'm back to 6.0.1 and once I get this javascript stuff > figured out, I'll try 6.1 again and see what happens there - maybe I > did something dumb.... popular demand). Right click on the component and select "Add binding attribute" Read here for more details http://wiki.netbeans.org/VW_binding_removal http://wiki.netbeans.org/OnDemandBindingAttribute http://wiki.netbeans.org/OnDemandBindingAttributePreliminaryResults - Winston > > Thanks for the help - If I get stuck again I'll let you know... > > nbc > >> >> A hidden field is a special type of text field in HTML. The component >> palette has it in there below the password field. It acts just like >> a text field, but it is always invisible on the screen. JSF saves >> the contents of all the screen controls and restores them if the page >> is redrawn (as happens when a submit button action returns a null). >> >> If you use a regular text field and make it invisible, its contents >> don't get sent forward when the page redraws. >> >> To access a hidden field called hiddenFieldWeight in Java use: >> hiddenFieldWeight.getValue() >> >> To access it in Javascript in your onClick() or onLoad() (only in the >> body component) use: >> >> document.getElementById("form1:hiddenFieldWeight_field").value >> >> Notice there is a "_field" added to the end of the name. JSF does >> that internally to help keep things straight. >> >> You won't see that on the JSP page, you have to look for it in the >> browser. When your page gets drawn, use the "view source" of the >> browser to see the actual HTML code that JSF generates for the page. >> If you are unsure of what the components name gets set to, just >> search for the name you gave it in the visual editor. The component >> will always start with that name followed by an underscore and some >> description like "_field" or "_dropdown". >> >> Another thing that is handy to know is the "isPostBack()" method. >> You can call it with or without the "this" as in >> "this.isPostBack()". I always forget the name of it so typing this >> with a dot brings up all the page stuff. >> >> The isPostBack() method returns false the first time a page is drawn >> and true each time a submit call re-renders it after that. >> >> The preprocess() method on the page only gets called on a postback, >> never on the initial rendering of the page, so it is handy too. >> >> The neat thing about using Javascript for this is the speed. You >> don't get the 3-5 second delay while the page gets submitted. Ajax >> would work for this too but there is still going to be some time lag. >> >> Basically, you just put a Javascript in the onChange() Javascriptof >> each component that you want to be sure is saved. The Javascript >> stuff a value in the hidden field to flag a change. >> >> The Javascript will show up in the JSP page automatically. >> >> I tend to think in terms of Java, so sometimes the Javascript stuff >> confuses me because I don't see it in the Java code. I guess its >> part of the "View" in the "Model-View-Controller" design pattern, >> but it actually affects the logic of the program, not just how it looks. >> >> So, if you like you can set the script from Java. You do this with >> the "setValueBinding()" method of the component. With that you can >> set any of a components properties that show up in the parameters >> window when you click on a component. >> >> Say you want to change the text in a button, called button1, under >> program control. You would use: >> >> button1.setValueBinding("text", >> getApplication().createValueBinding("New Button Text")); >> >> To set the onLoad() Javascript of the body it would be something like: >> >> String confirmScript = "confirm(\"Are you sure? Unsaved changes!\"); >> body1.setValueBinding("onLoad", >> getApplication().createValueBinding(confirmScript)); >> >> I'm not actually sure about escaping the quoting in the string, you >> may have to use """ instead of \". >> >> You can also use page parameters with their script language >> identifiers. This is nice if you want to use stuff looked up from a >> database to set the values. Some examples with a hyperlink are: >> >> hyperlinkCert.setValueBinding("visible", >> getApplication().createValueBinding("#{page1.certIconVisible}")); >> hyperlinkCert.setValueBinding("target", >> getApplication().createValueBinding("#{page1.blankValueBinding}")); >> hyperlinkCert.setValueBinding("url", >> getApplication().createValueBinding("#{page1.viewCertURL}")); >> hyperlinkCert.setValueBinding("style", >> getApplication().createValueBinding("#{page1.certUrlStyle}")); >> >> Hope this helps! >> >> Rick >> >> >> Neil B. Cohen wrote: >>> Morning Rick, >>> >>> I had asked about using AJAX with Netbeans and you sent me a >>> suggestion (at home - nbc@...) regarding using a hidden >>> field and javascript to decide whether or not to put up a >>> confirmation dialog. I was looking at how to implement that this >>> morning, and I'm a bit confused... >>> >>> I can create a static text field and make it 'hidden' on my web >>> page. But in my java code, it doesn't show up as a member variable >>> anywhere - it is only an element in the jsp code itself. How do I >>> access that element from within my java code to change the text from >>> 'clean' to 'dirty' or whatever... I feel like I'm missing something >>> simple here but I'm not sure what it is... >>> >>> If I figure it out I'll let you know... Sorry to bother you with >>> this, but I like your suggestion - I think it will work if I can put >>> all the pieces together, >>> >>> Question - is this a problem with Netbeans 6.1?? (I just installed >>> 6.1 yesterday). I just created a text field and it doesn't seem to >>> create a corresponding object in the java code... There is nothing >>> in the init() routine.... Should I be switching back to 6.0.1?? >>> >>> >>> thanks, >>> >>> nbc >>> >>> NAME: Neil B. Cohen (Verisign Inc.) >>> PHONE: 703-948-4471 >>> DOMAIN: ncohen@... >>> ************************************************************* >>> * Murphy's Philosophy: Smile - tomorrow will be worse... >>> * >>> * O'Tooles Commentary: Murphy was an optimist! >>> ************************************************************* >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: Netbeans/Hidden field questionRick Fincher wrote:
> Hi Neil, Morning Rick - I followed the steps you laid out below and it worked for me as well. I have switched back to NB6.1 and now that I know about having to add the binding routines, that seems to be working too. Not sure what was causing the problem yesterday - I must have missed a step somewhere - but I think I'm on the right track now. Thanks again for all the help! nbc > > Below is an OnClick() script that I just tried that worked. One thing > I found out was that in 6.1 you have to right-click on the hidden > field and select "add binding attribute". Otherwise it never assigns > the value to the field that you set in the "text" parameter of the > visual editor. > > I put a hidden field on the page named hiddenField1. After I added > the binding attribute I set the text of the field to "alert" in the > parameter window for the field. The field can have text even though > you can't see it. To stuff a value in it in Java use > hiddenField1.setText("your text"); > > WARNING- Do Not put a value in for "text" for your textField or > hiddenField in the visual editor if you set the value in your > program. If you do it will override whatever you set programatically > for the initial load of the page. I went nuts trying to figure that > one out. > > I set the value of the hiddenField in the visual editor just for this > test. It's OK to do this if you always want the page to do its first > load with a fixed value. > > The Javascript for onClick is: > > var hiddenText=document.getElementById("form1:hiddenField1").value; > > if (hiddenText=="alert"){ > alert("Hidden Field is alert"); > } else { > alert("Hidden field is not alert"); > } > > You can look in HTTP Monitor in Netbeans and click on the last POST > for Page1.jsp to see what is in the fields before and after the page > is submitted. Clear the entrie in HTTP Monitor if you have too much > stuff in there (right-click the "All Records" or "Current Records" > folder icon and select "Delete All"). > > The component names are all there too. Only textField components have > the "_field" added to the name. It is hard to see the underscore in > the HTTP Monitor but it is there. > > To set "clean/dirty" initialize it in the init() method with something > like: > > if (!this.isPostBack()) { > hiddenField1.setText("clean"); > } > > This will only set "clean" on the first load (not a postBack). > > Then for each component that can "dirty" it up, put this in the > onChange() Javascript: > > document.getElementById("form1:hiddenField1").value="dirty"; > > You can change a visible textField like: > > document.getElementById("form1:textField1_field").value="changed in > Javascript"; > > You can open the error console on your browser to see if there are any > errors in your Javascript when it executes. > > Hope this helps! > > Rick > ------------------- > > Neil B. Cohen wrote: >> Hi Rick - Sorry to bother you again, but I need another nudge... >> >> I've attached a screen shot which shows the page I'm building and the >> javascript I'm trying to use. >> >> A few notes: >> >> 1) I created a hidden field called 'hidePageStatus' and initialized >> it to 'dirty'. Obviously that is not correct for the long run, but >> for now it lets me bring up the page and just hit the return button >> for testing.... >> >> 2) When I tried 'dflag = >> document.getElementById("form1.hidePageStatus") or >> "form1.hidePageStatus_field" (or "form1:hidePageStatus_field" or... I >> think I tried them all) it never even printed the 'alert' message - >> it simply executed the return button event handler. Not sure why that >> would be... >> >> 3) I looked at the html for the page and found a 'hidden field' named >> 'form1_hidden'. As you can see, it has a value of 'form1_hidden'. >> When I set the javascript to look for that (as in the screen dump), >> then the alert displays and the confirm dialog executes properly - so >> the javascript is ok, but my attempts to use it within Netbeans is >> wrong somehow... >> >> So my questions are: >> >> 1) How do I get the mapping from form1_hidden to hideStatusPage? >> >> 2) How do I get the value set correctly to clean/dirty? >> >> I think if I can get over this hump, I should be mostly ok... >> >> Much obliged, >> >> nbc >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
| Free Forum Powered by Nabble | Forum Help |