Tuesday, 15 September 2015

java - JSF, registering null value to bound instances -



java - JSF, registering null value to bound instances -

i'm having problem assigning value null bound instance. whenever selection made within selectonemenu works expected (the instance registered cc.attrs.city set selected value, shown in illustration below), when selecting hardcoded null value, i'm examining selection not forwarded bound instance. help appriciated.

usage illustration :

<h:selectonemenu id="city" value="#{cc.attrs.city}" converter="anyselectconverter"> <f:selectitem itemlabel="#{msg['general.choose']}" itemvalue="#{null}"/> <f:selectitems itemlabel="#{city.name}" itemvalue="#{city}" var="city" value="#{locationcomponentcontroller.getallcities()}" /> <p:ajax event="valuechange" update="district subdistrict small town neighbourhood #{cc.attrs.updateonselection}" /> </h:selectonemenu>

any select converter :

@facesconverter("anyselectconverter") public class anyselectconverter implements converter{ private static map<object, string> entities = new concurrenthashmap<object, string>(); @override public string getasstring(facescontext context, uicomponent component, object entity) { // todo : geçici çözüm sebebi araştırılmalı if(entity == null) homecoming ""; synchronized (entities) { if (!entities.containskey(entity)) { string uuid = uuid.randomuuid().tostring(); entities.put(entity, uuid); homecoming uuid; } else { homecoming entities.get(entity); } } } @override public object getasobject(facescontext context, uicomponent component, string uuid) { (entry<object, string> entry : entities.entryset()) { if (entry.getvalue().equals(uuid)) { homecoming entry.getkey(); } } homecoming null; } }

try designating null item noselectionoption, since looks that's intention anyway:

<h:selectonemenu id="city" value="#{cc.attrs.city}" converter="anyselectconverter"> <f:selectitem itemlabel="#{msg['general.choose']}" itemvalue="#{null}" noselectionoption="true"/> <f:selectitems itemlabel="#{city.name}" itemvalue="#{city}" var="city" value="#{locationcomponentcontroller.getallcities()}" /> <p:ajax event="valuechange" update="district subdistrict small town neighbourhood #{cc.attrs.updateonselection}" /> </h:selectonemenu>

java jsf primefaces

No comments:

Post a Comment