简体   繁体   English

p:ajax渲染后p:fileUpload无法正常工作

[英]p:fileUpload not working after rendered by p:ajax

I´m getting confused why the component p:fileUpload doesn´t call the fileUploadListener once the component is shown by the p:ajax . 我很困惑,为什么一旦p:ajax显示了组件p:fileUpload不调用fileUploadListener If I put it outside the panelGrid s or even remove them, works just fine. 如果我将其放在panelGrid之外,甚至将其删除,则可以正常工作。

What isn´t working: 什么不起作用:

<div class="pure-control-group"> 
    <label for="mostraNoIndex">Slideshow</label>
    <p:selectBooleanCheckbox value="#{destaqueCadastrarBean.d.apareceNoSlide}">
        <p:ajax event="change" update="upload"></p:ajax>
    </p:selectBooleanCheckbox>
</div>                                      

<h:panelGrid id="upload">
    <h:panelGrid rendered="#{destaqueCadastrarBean.d.apareceNoSlide}">
        <div class="pure-control-group"> 
            <label for="mostraNoIndex">Imagem</label>
            <p:fileUpload fileUploadListener="#{destaqueCadastrarBean.handleFileUpload}" mode="advanced" dragDropSupport="true" sizeLimit="100000000000" fileLimit="1" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />                                    
        </div>
   </h:panelGrid>
</h:panelGrid>

What works: 什么有效:

<div class="pure-control-group"> 
    <label for="mostraNoIndex">Slideshow</label>
    <p:selectBooleanCheckbox value="#{destaqueCadastrarBean.d.apareceNoSlide}">
    </p:selectBooleanCheckbox>
</div>  

<div class="pure-control-group"> 
    <label for="mostraNoIndex">Imagem</label>
    <h:fileUpload fileUploadListener="#{destaqueCadastrarBean.handleFileUpload}" mode="advanced" dragDropSupport="true" sizeLimit="100000000000" fileLimit="1" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />                                    
</div>

Just found out a solution for it. 刚刚找到解决方案。 The bean being called was RequestScoped , changed it to ViewScoped . 被调用的bean是RequestScoped ,将其更改为ViewScoped I guess cause the bean was requested when the form loaded and p:fileUpload can only appears after the creation of the bean, the component couldn´t reach the bean. 我想是因为在窗体加载时请求了bean,并且p:fileUpload仅在创建bean之后出现,组件无法到达bean。 With view scope the bean is available for components that comes afterward. 通过视图作用域,bean可用于之后的组件。 If someone has a more technical and clear explanation I would like to understand better. 如果有人对技术有更明确的解释,我想更好地理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM