java - JSF 2: Create a custom component with CommandButton and get attribute to ActionListener -
java - JSF 2: Create a custom component with CommandButton and get attribute to ActionListener -
i new stack overflow , have question jsf 2.0 , custom components (i utilize primefaces 3 too, buts not of import think). here situation: have nested info object of type advancedcriterion
, contains list of advancedcriterion
or criterion
(via interface criteria
). these criterions used create complex filter object this:
i created 2 new components in java: advancedcriterion.java
, simplecriterion.java
recursion, because first effort composite fails. , recursive phone call of composite in composite creates stack overflow :-(
until know can display static filter object , looks fine, user should add together or delete criterions. addes buttons (here came primefaces it). here code, started first criterion, advancedcriterion
.
<mytag:advancedcriteriacomponent criteria="#{managefiltersbean.filterbuilder.criteria}" />
i create know button , want give parent object actionlistener:
commandbutton addbutton = new commandbutton(); addbutton.setid("btnadd" + uuid.randomuuid()); addbutton.setajax(true); addbutton.setvalue(" + "); addbutton.addactionlistener(new criteriaactionlistener()); addbutton.getattributes().put("criteria", this.currentcriteria);
well, , here comes criteriaactionlistener:
@override public void processaction(actionevent event) throws abortprocessingexception { advancedcriteria criteria = (advancedcriteria) event.getcomponent().getattributes().get("criteria"); criteria.addcriteria(new criterion()); system.out.println("number of children: " + criteria.getchildren().size()); }
in component currentcriteria known , can see child-elements. in criteriaactionlistener
object empty (it has right type, looks fresh initalized object of type) question now: how currentcriteria
object criteriaactionlistener
?
i tried attribute in actionlistener , set component, whole object null. although tried create elexpression , right bean (#{managefiltersbean.addcriterion(criteria}) object null. have no more ideas , unfortunatly new jsf (about few weeks).
maybe id of buttons? random, because number of buttons dynamic. read, every button must have unique id work properly. or attributes/params?
thank help,
felix
this problem solved, others occur. well, commented above, problem more problem implementation of 'advancedcriteria' object. there no connection or hint 'commandbutton', miss-named getter.
probably added line implements serialiable
helps although, don't know exactly, because tried lot of things (save , restore states, enumeration propkeys setters , getters , stuff this), overall these weren't solution.
java jsf recursion custom-component
Comments
Post a Comment