Monday, 15 February 2010

jquery - Disable validation on dynamically filled JSF OneMenu -



jquery - Disable validation on dynamically filled JSF OneMenu -

first off, i'm using primefaces 5.1 , jsf 2.2.2.

problem

i'm creating website 200+ onemenus (this not decision...). there 1 list options , every onemenu using it.

using "static" way causes explorers hang or crash.

<h:selectonemenu value="#{day.movieevaluatorname}" styleclass="comboboxmitarbeiter"> <f:selectitems value="#{combolistsbean.staffmembers}" var="member" itemvalue="#{member.name}" itemlabel="#{member.fullname}" /> <p:ajax listener="#{...save()}" /> </h:selectonemenu>

now because options list same thought "lets utilize jquery , fill selects clicks on one.

<h:selectonemenu value="#{day.movietechnicanname}" styleclass="comboboxmitarbeiter"> <f:selectitem itemvalue="#{day.movietechnicanname}" itemlabel="#{day.movietechnican}" /> <p:ajax listener="#{...save()}" /> </h:selectonemenu>

js

var comboboxoption = { <c:foreach items="#{combolistsbean.staffmembers}" var="member"> '#{member.name}' : '#{member.fullname}', </c:foreach> }; var _select = $('<select>'); $.each(comboboxoption, function(val, text) { _select.append($('<option></option>').val(val).html(text)); }); $(document).ready(function() { $( ".comboboxmitarbeiter" ).focus(function() { $(this).append(_select.html()); }); });

now "filling" works fine when seek alter value of 1 of onemenus jsf validation on onemenu, telling me value invalid , "...save()" function never called.

question

how can disable validation on onemenu? tried "required=false" didn't work. or there other way increment performance?

btw posted in primefaces forum because jsf question don't think reply there. http://forum.primefaces.org/viewtopic.php?f=3&t=40288&e=0

the problem is, not going work way jsf designed. during apply request values phase, jsf restore component tree in order update values of each component. time, listsource of selectonemenu empty. hence jsf cannot bind (javascript generated) value component, because it's not within listsource requirement selectonemenu.

this not typical validation can disable. contract of selectonemenu is every valid selection needs within collection of elements.

if want populate selectonemenus javascript, should utilize jsf'ish way accomplish this. corresponding component on backend aware of select-options , value wihtin selectonemenu can valid.

render selectonemenus empty lists , noselectionoption option. add together ajax listener calls method on backing bean, whenever user hovers selectonemenu. method should add together desired elements listsource , update selectonemenu displays populated values.

a simple illustration of this:

@named @viewscoped public class testcontroller implements serializable { private list<string> options = new linkedlist<string>(); private string selectedoption; public void populatelist(ajaxbehaviorevent event) { this.options.add("foo"); this.options.add("bar"); this.options.add("baz"); } public void save() { system.out.println(this.selectedoption); } //+getter , setter }

on ui part need take care not calling listener on , over. next illustration load elements, when user hovers select , ajax event becomes disabled. selectonemenu can used if have been filled beginning.

<h:form> <h:selectonemenu value="#{testcontroller.selectedoption}" id="mylist"> <f:selectitem itemvalue="" noselectionoption="true" itemlabel="please select something."/> <f:selectitems value="#{testcontroller.options}" var="item" itemlabel="#{item}" /> <p:ajax event="mouseover" listener="#{testcontroller.populatelist}" update="@this" disabled="#{not empty testcontroller.options}" /> </h:selectonemenu> <p:commandbutton action="#{testcontroller.save()}"></p:commandbutton> </h:form>

jquery jsf jsf-2 primefaces xhtml

No comments:

Post a Comment