我很困惑为什么组件p:fileUpload
在fileUploadListener
显示组件后没有调用p:ajax
。如果我把它放在panelGrid
之外,或者甚至将它们删除,那就行了。
什么不起作用:
<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>
什么有效:
<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>
答案 0 :(得分:0)
刚刚找到了解决方案。被调用的bean是RequestScoped
,将其更改为ViewScoped
。我猜是因为加载表单时请求bean而p:fileUpload只能在创建bean之后出现,组件才能到达bean。使用视图范围,bean可用于随后出现的组件。如果某人有更技术性和清晰的解释,我想更好地理解。