Neil B. Cohen wrote:
popular demand). Right click on the component and select "Add binding
>
> 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@...
>