java - Wizard Component PrimeFaces Updating other variables -
i have 2 tabs. wizard component, when press 'next' button (from first tab), need populate list(with selectitem objects) , show these selectitems in selectonemenu tag in second tab. have finished entering data on first tab , press 'next' button, selectonemenu tag(on second tab) not have in it.
basically, need update next tab along processing of current tab. anyway this?
thanks in advance.
here code:
<p:wizard widgetvar="wiz" shownavbar="true" flowlistener="#{detentionform.onflowprocess}"> <p:tab id="typeofleader" title="leader selection"> <p:panel header="leader selection"> <p:messages showsummary="true" showdetail="false"/> <p:panelgrid columns="2"> #{msgs.typeofleaderpunishment} <p:selectonemenu value="#{detentionform.typeofleaderselectedid}" style="width:400px" panelstyle="width:150px" effect="fade"> <f:selectitems value="#{detentionform.teachertypes}" var="type" itemlabel="#{type.label}" itemvalue="#{type.value}" /> </p:selectonemenu> </p:panelgrid> </p:panel> </p:tab> <p:tab id="typeofpunishment" title="punishment type"> <p:panel header="type of punishment"> <p:panelgrid columns="2"> #{msgs.typeofdetention} <p:selectonemenu value="#{detentionform.typeofpunishment}" style="width:400px" panelstyle="width:150px" effect="fade" > <f:selectitems value="#{detentionform.detentiontypes}" var="type" itemlabel="#{type.label}" itemvalue="#{type.value}" /> </p:selectonemenu> </p:panelgrid> </p:panel> </p:tab> </p:wizard>
#{detentionform.detentiontypes}
arraylist needs populated once press 'next' button second tab.
here backing bean:
@viewscoped @named("detentionform") public class detentionformbean implements serializable{ @resource(name="jdbc/detentioncentre") private datasource ds; private details details = (details) facescontext.getcurrentinstance().getexternalcontext().getsessionmap().get("userdetails"); private string typeofpunishment; private string typeofleader = details.gettypeofleader(); //can change if user house leader. eg. can become teacher when making punishment private int typeofleaderid; //id in database of teacher's type of leadership private int typeofleaderselectedid = 1; //set default teacher house leader can teacher , normal teacher teacher! private arraylist<selectitem> detentiontypes = new arraylist<selectitem>(); //selectitem objects shows punishments each teacher can private arraylist<selectitem> teachertypes = new arraylist<selectitem>(); //selectitem objects shows type of leadership teacher can (teacher or house leader) //gets data necessary database show on page @postconstruct public void initialize(){ this.settypeofleaderid(details.getusername()); //gets id database find out default type of leadership this.findteachertypes(this.typeofleader); } public string onflowprocess(flowevent event) { //change later backing >>>>>>>>>>>>>> string steptogo = event.getnewstep(); if(steptogo.equals("typeofpunishment")){ this.finddetentiontypes(); } return steptogo; } //populates teachertype arraylist depending user's teacher type. house leader can teacher or house leader. private void findteachertypes(string type) { if(type.equals("house leadership team")){ this.teachertypes.add(new selectitem(integer.tostring(this.typeofleaderid), type)); //house leader 2 this.teachertypes.add(new selectitem(integer.tostring(this.typeofleaderid - 1), "teacher" )); //teacher 1 }else{ //type teacher this.teachertypes.add(new selectitem(integer.tostring(this.typeofleaderid), type)); //teacher 1 } } //populates detentiontypes depending on type of leader private void finddetentiontypes() { system.out.println(">>>>inside finddetentiontypes()!!!"); preparedstatement ps; connection con; string sqlinitialdata = "select r.punishment_type, p.type detentioncentredb.tbl_teacher_roles_allowed_punishments r, detentioncentredb.tbl_punishment_types p r.teacher_roles = ? , p.id = r.punishment_type"; resultset rs; try { con = ds.getconnection(); ps = con.preparestatement(sqlinitialdata); ps.setstring(1, integer.tostring(this.typeofleaderselectedid)); rs = ps.executequery(); while(rs.next()){ selectitem s = new selectitem(rs.getstring("punishment_type"), rs.getstring("type")); this.detentiontypes.add(s); } rs.close(); ps.close(); con.close(); } catch (sqlexception ex) { logger.getlogger(detentionformbean.class.getname()).log(level.severe, null, ex); } } //getter , setter methods public string gettypeofpunishment() { return typeofpunishment; } public void settypeofpunishment(string typeofpunishment) { this.typeofpunishment = typeofpunishment; } public string gettypeofleader() { return typeofleader; } public arraylist<selectitem> getdetentiontypes() { return detentiontypes; } public arraylist<selectitem> getteachertypes() { return teachertypes; } public int gettypeofleaderid() { return typeofleaderid; } //gets typeofleader current user database. retrieves id of teacher's type of leadership. not teacher selected. private void settypeofleaderid(int username){ preparedstatement ps; connection con; string sqltypeofleaderid = "select typeofleader detentioncentredb.tbl_teachers regnumber = ?"; resultset rs; try { con = ds.getconnection(); ps = con.preparestatement(sqltypeofleaderid); ps.setint(1, username); rs = ps.executequery(); while(rs.next()){ this.typeofleaderid = rs.getint("typeofleader"); } rs.close(); ps.close(); con.close(); } catch (sqlexception ex) { logger.getlogger(detentionformbean.class.getname()).log(level.severe, null, ex); } } public int gettypeofleaderselectedid() { return typeofleaderselectedid; } public void settypeofleaderselectedid(int typeofleaderselectedid) { this.typeofleaderselectedid = typeofleaderselectedid; } }
you can use ajax notify server side stepping wizard. pf documentation:
if you’d notified on server side when wizard attempts go or forward, define flowlistener.
<p:wizard flowlistener="#{userwizard.handleflow}"> ... </p:wizard> public string handleflow(flowevent event) { string currentstepid = event.getcurrentstep(); string steptogo = event.getnextstep(); if(skip) return "confirm"; else return event.getnextstep(); }
in case, need load detentiontypes
array when steptogo
reaches typeofpunishment
, based on user has selected on first step of wizard:
public string handleflow(flowevent event) { string steptogo = event.getnextstep(); if(steptogo.equals("typeofpunishment")){ detentiontypes = service.loaddetentiontypes(this.typeofleaderselectedid); } }
Comments
Post a Comment