Reputation: 11
Hey I duplicate HTML Code and insert this in Runtime to my HTML via JavaScript. The Code I clone is:
<div id="any">
<h:selectOneMenu value="#{browserOSList.browserXP[0]}" id="dropDown-browser-XP-Vista-8-81-1">
<f:selectItems value="#{selectOneMenu.selectBrowserXP}"/>
</h:selectOneMenu>
</div>
At first I create a new div via JavaScript and set the id to "any2". Then I copy the Code of div id="any" into div id="any2". Now I want to change the value of the selectOneMenu value attribute in the new div(at the moment: #{browserOSList.browserXP[0]} ). JavaScriptCode:
$("#any2 select").attr("value","#{browserOSList.browserXP[1]}");
If I look the HTML Code, the new Value is set to "#{browserOSList.browserXP[1]}" correctly. But if I submit the form only the "any" selectOneMenu sets his value in the Bean. The "any2" selectOneMenu sets nothing.
Where is the problem?
I hope you understand my meaning. If not, I will post the complete Source Code (too much and complicated). You can answer in german too. Much thanks!
Upvotes: 1
Views: 739
Reputation: 1
It seems to me that you are mixing jsf and javascript in a wrong way. You should generate the second select on server side, as the first. If for any reason you cannot, than:
The #{browserOSList.browserXP[1]} is an EL (expression language) expression that is used by jsf to identify the bean variable used for setting the value of the select. In javascript (client side) you wont get the value from the bean but just a string containing the expression. So you need to write a javascript variable initialized server side with this value: var secondSelectValue = "#{browserOSList.browserXP[1]}"; That's one problem...
In order to set a second value in the bean you need to identify this variable in the bean via the name of the second select (look at the first select name attribute). It should have a name attribute with dropDown-browser-XP-Vista-8-81-1 at the end. So JSF is setting this variable in the bean. In order to set another variable in the bean with the second select you need to identify properly the second bean variable via the name attribute of the second select as for the first select...
Good luck :-)
Upvotes: 0
Reputation: 2797
Check the JSF lifecycle: http://docs.oracle.com/javaee/6/tutorial/doc/bnaqq.html
The server is not aware of the changes in the HTML that you are doing on the client side. Thus in Apply Request Values Phase your client-side generated components are not part of the component tree on the server side and therefor JSF will not update the values of those components.
After this step is done (and maybe after some additional validations) JSF will update the server side data modell.
What you trying to do will provide the possibility to do nearly everything on the server just by changing the HTML outcome on the client, thus, for security reasons, it is just not possible at all.
Upvotes: 1