3

I'm trying to download a file by clicking on a button. I have a checkbox that when checked it puts some filters on that file. The problem is that everytime the checkbox value is false even though is checked

I tried using ajax renderer="" without success. Maybe I called it badly.

menu.xhtml (just the part where the form is)



    <div id="mainTools"  style="position: relative;bottom: 0;">
        <h:form id="form1">
         <div>
                <p:selectBooleanCheckbox style="padding-left:18px"
                    value="#{fileDownloadBean.filteringRequired}">
                    <p:ajax update=":notifications:msgs"
                        render=":form2"
                         />
                </p:selectBooleanCheckbox>
                <h:outputText value="Filtering" style="padding-left:4px"/>
        </div> 
         </form>

         <div id="secondTools">
                 <h:form id="form2">
                   <h:panelGrid columns="1" style="margin-left:10px;" cellpadding="5">
                            <p:commandButton value="Download" style="width:170px;">
                                    <p:fileDownload value="#{downloadFile.getFile()}">
                                     </p:fileDownload>
                            </p:commandButton>
                     </h:panelGrid>
                </h:form>

        </div>
</div>

filedownload.java

if(filteringRequired){
  //do something
}
else{
//do other
}

I need to know how to store the checkbox value (true/false) and use it in the form where the button is (the ajax doesn't work) because after checking the "filtering" checkbox I press the "Download button" and in the java file, when running debug, it enters on the else branch. The "isFilteringRequired" is always false.

  • [mcve] please ! – Kukeltje Aug 05 '19 at 14:57
  • I'm sorry but I can't reproduce more. I just want to know how to take the value of the checkbox and send it to the button, who is in a separate form. I think the ajax is refreshing the page so the value is lost (false always). – The Deepest Sleep Aug 05 '19 at 17:27
  • So you mean that if you create a new empty ksf + primeFaces project and copy **only** the code from the question in there, you can reproduce the problem? I tried and I get all sorts of errors... (did you actually read the link I posted?) – Kukeltje Aug 05 '19 at 18:16
  • https://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope – Kukeltje Aug 05 '19 at 19:00
  • Thanks and sorry for being so vague. The problem was that I had '@RequestScope' instead of '@ViewScoped'. I want to approve your anwer. Thanks again. – The Deepest Sleep Aug 06 '19 at 07:49
  • You mean you want to improve the link I posted above your previous comment? That is not 'my' answer. But if you want to improve it, you can always do. Others might revert things though or change it in a different way after your edit. But feel free, that is what the option to edit is for. – Kukeltje Aug 06 '19 at 07:52

0 Answers0