• Post Reply Bookmark Topic Watch Topic
  • New Topic

transfer a value from javascript to a backingbean java  RSS feed

 
Voicu Liviu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

I have a js code that finds out the timezone and then I am trying to "send" a value to a java backingbean.
This code must be execute during the load of the xhtml page because in the process I use the "localTimeZone" bean.



Can you please tell me how is the correct way to do this in order to have the setters of backingbean called ?

Thanks

PS:

JSF ver: Implementation-Version: 1.2_12-b01-FCS
RICHFACES: Implementation-Version: 3.3.3.Final
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that what you coded was essentially correct as a means of transmitting the client's timezone settings to the server. Just make sure that the following things are also done:

1. You need public get and set methods for the properties named timeZoneID and offset in your "localTimeZone" backing bean. Which will probably need to be View or Session scoped.

2. The inputHidden controls do need to be in a form (requestWizardForm), since JSF controls not enclosed within a Form are ignored. And in JSF1, I believe also an f:view. The usual stuff, in other words.

3. Like any other form control, if ANY form control has an invalid value (whether hidden or not) ALL form control values will be suppressed from updating their corresponding backing bean properties, whether the control is invisible or not. JSF requires all incoming data to be 100% valid.

4. I am assuming that there's something here that will actually submit requestWizardForm, either via a formal form submit or AJAX request. Since until the client submits the form, the server can do nothing.
 
Voicu Liviu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, it has to do with your point nr 4 :-)

I have fixed it, I should write the form as described in page1.xhtml and not <h:form...

page1.xhtml:

<a4j:form id="requestWizardForm" ajaxSubmit="true"> <-----THIS DID THE TRICK

...

...
<include page1> <---the page that holds the js script
...

...

</a4j:form>
page2.xhtml:

<script type="text/javascript">
var userTimeZone = userTimeZone();
var hiddenElementTimeZoneID = document.getElementById("requestWizardForm:clientSelectedTimeZoneID");
hiddenElementTimeZoneID.value = userTimeZone.timeZoneID;

var hiddenElementOffset = document.getElementById("requestWizardForm:clientSelectedOffset");
hiddenElementOffset.value = userTimeZone.offset;
document.getElementById("requestWizardForm").submit(); <-----ALSO THIS DID THE TRICK

</script>
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably didn't need to convert from a h:form to an a4j:form. The a4j:form was a hack for stuff so old that even JSF 1.1 may not require it.

The form submit, on the other hand... :)

 
Voicu Liviu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see, I didn't know that.

Thanks mate
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!