I'm trying to conditionally hide or show a p:dataGrid based on a session bean property. My p:dataGrid is wrapped in a p:dialog and I thought I could use the p:dialog's closeListener and onCloseUpdate attributes to control the hide/show of the p:dataGrid. I'm using a session based bean boolean property in the rendered attribute of the p:dataGrid that gets set to true in my p:remoteCommand's actionListener="#{bookmarklet.loadImages}" method and then set to false in the closeListener="#{bookmarklet.close}". It never gets rendered even though the loadImages method gets executed and the boolean property is set to true. Ideally, I would like to render the p:dataGrid if the value="#{bookmarkletBean.imageURLs}" is empty. I tried rendered="#{!empty bookmarkletBean.imageURLs}" but I get an EL exception
page:
Code: Select all
<p:dialog header="#{bundle['bookmarklet.dialog.HEADER']}" widgetVar="scrapeDlg"
modal="true" height="450" width="700" draggable="false" resizable="false"
closeListener="#{bookmarklet.close}" onCloseUpdate="imageGrid">
<h:form id="scrapeFrm">
<p:commandButton onclick="rcTest()" value="call server"/>
<h:inputHidden id="scrapeURL" value="http://www.freefoto.com/preview/04-01-70?ffid=04-01-70"/>
<p:remoteCommand name="rcTest" process="@this,scrapeURL" actionListener="#{bookmarklet.loadImages}" update="imageGrid"/>
<p:dataGrid id="imageGrid" var="img" value="#{bookmarkletBean.imageURLs}" columns="1"
rows="1" paginator="true" effect="true"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} "
paginatorPosition="bottom"
rendered="#{bookmarkletBean.shouldRender}">
<p:column>
<h:panelGrid columns="1" style="width:100%">
<p:graphicImage value="#{img}" width="100" height="100"/>
</h:panelGrid>
</p:column>
</p:dataGrid>
</h:form>
</p:dialog>
Code: Select all
@Named
@Scope("session") public class BookmarkletBean extends BaseSessionBean{ private List imageURLs; private boolean shouldRender; private String hidden;
public String getHidden() {
return hidden;
}
public void setHidden(String hidden) {
this.hidden = hidden;
}
public List<String> getImageURLs() {
return imageURLs;
}
public void setImageURLs(List<String> imageURLs) {
this.imageURLs = imageURLs;
}
public boolean isShouldRender() {
return shouldRender;
}
public void setShouldRender(boolean shouldRender) {
this.shouldRender = shouldRender;
}
Code: Select all
@Named
@Scope("request") public class Bookmarklet extends BaseAction{ @Inject private BookmarkletBean bookmarkletBean; @Inject private BookmarkletService bookmarkletService;
public void loadImages(ActionEvent e) throws MalformedURLException, IOException {
ExternalContext context = FacesUtils.getExternalContext();
String scrapeURL = context.getRequestParameterMap().get("scrapeFrm:scrapeURL");
bookmarkletBean.setImageURLs(bookmarkletService.scrape(scrapeURL));
bookmarkletBean.setShouldRender(true);
}
public void close(CloseEvent e){
bookmarkletBean.setShouldRender(false);
}