Unable to maintain JSF ViewState within a dataTable component -


i'm working inherited jsf app. still quite new it.

here's screenshot of page i'm working with: http://goo.gl/gidpcd. exam software , you're looking @ question administration. on screen user can write question, cite question source, write answers, associate category , associate images.

where i'm getting stuck when add/delete answers down toward bottom.

i'm suspicious issue viewstate.

when click add or delete answers. page reloads , lose file associations within jsf datatable component. viewstate maintained in of other form elements on page, it's files within datatable can't seem head wrapped around. here's jsf datatable component (i'll list code in it's entirety below):

<h:datatable id="table0" value="#{adminquestions.fileslist}" var="file" columnclasses="id,title,selected last" rendered="true" >     <h:column>         <f:facet name="header">file</f:facet>         <h:graphicimage value="#{file.path2}" alt="" />     </h:column>      <h:column>         <f:facet name="header">title</f:facet>         <h:outputtext value="#{file.title}" />     </h:column>     <h:column>         <f:facet name="header">select files</f:facet>         <h:selectbooleancheckbox value="#{file.selected}" />     </h:column> </h:datatable> 

here's jsf button compnent fire add add answer method:

<h:commandbutton value="#{msgs.addbutton}" action="#{adminquestions.addquestiontoanswerrow}" /> 

and here's add answer method:

public string addquestiontoanswerrow() {     if(this.questiontoanswerlist.size() < 8) {         // set scroll         if(facescontext.getcurrentinstance().getmessagelist().size() > 0) {             this.scroll = false;         }         else {             this.scroll = true;         }         //create new answer, set current question, , add collection         answers answer_local = new answers();         questiontoanswer qta_local = new questiontoanswer();         answer_local.settitle(this.inputtextanswer);         answer_local.setdescription(this.inputtextanswer);         answer_local.setcorrect(this.correctanswer);         qta_local.setanswers(answer_local);         qta_local.setanswer(this.questiontoanswerlist.size() + 1);         qta_local.setquestions(this.question);         this.questiontoanswerlist.add(qta_local);         // reset input fields         this.inputtextanswer = "";         this.correctanswer = false;          list<file1> thisfileslist = getfileslist();          questionstofiles qtf;         list<questionstofiles> qtfc = new arraylist<questionstofiles>();         if(this.fileslist != null) {             for(iterator<file1> entries = this.fileslist.iterator(); entries.hasnext();) {                 file1 file_temp = entries.next();                 if(file_temp.isselected()) {                     qtf = new questionstofiles();                     qtf.setquestions(this.question);                     qtf.setfile1(file_temp);                     qtfc.add(qtf);                 }             }         }          return null;     }     else {         jsfutils.adderrormessage("no more 8 answers allowed: ", "the question cannot have more 8 answers");         return null;     } } 

here's jsf button component fire delete method

<h:commandbutton value="#{msgs.deletebutton}" action="#{adminquestions.deletequestiontoanswerrow(a)}" /> 

and delete method:

public string deletequestiontoanswerrow(questiontoanswer qta_local) {     // set scroll     if(facescontext.getcurrentinstance().getmessagelist().size() > 0) {         this.scroll = false;     }     else {         this.scroll = true;     }     //iterate through category exam collection , delete associated category it's reflected on page     (iterator<questiontoanswer> itr = this.questiontoanswerlist.iterator(); itr.hasnext();) {         questiontoanswer qta_temp = itr.next();         if(qta_temp == qta_local) {             qta_temp.setquestions(null);             qta_temp.setanswers(null);             itr.remove();             return null;         }     }     return null; } 

thanks taking look.


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -