2011-03-08 3 views
1

세션 빈 속성을 기반으로 <p:dataGrid>을 조건부로 숨기거나 표시하려고합니다. 내 <p:dataGrid>은 p : 대화 상자에 래핑되며 p : 대화 상자의 closeListener 및 onCloseUpdate 속성을 사용하여 <p:dataGrid>의 숨기기/표시를 제어 할 수 있다고 생각했습니다. 내 <p:remoteCommand>의 메서드에서 true로 설정되고 다음 closeListener="#{bookmarklet.close}" false로 설정된 p : dataGrid의 렌더링 된 특성에서 세션 기반 bean 부울 속성을 사용하고 있습니다. loadImages 메서드가 실행되고 boolean 속성이 true로 설정된 경우에도 렌더링되지 않습니다. 이상적으로 value="#{bookmarkletBean.imageURLs}"이 비어있는 경우 <p:dataGrid>을 렌더링하고 싶습니다. rendered="#{!empty bookmarkletBean.imageURLs}" 시도했지만 EL 예외가 발생합니다.p : dataGrid와 그 내용을 조건부로 렌더링

페이지 :

<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> 

세션 빈 :

@Named 
@Scope("session") 
public class BookmarkletBean extends BaseSessionBean{ 
    private List<String> 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; 
    } 
} 

액션 클래스 :

@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); 
    } 
} 

답변

4
처음 false로 값을 렌더링하는 구성 요소를 설정할 때 문제가

은 그렇지 않습니다 페이지에 존재합니다. imageGrid에서 update가 호출되면 업데이트 할 구성 요소가 없습니다.

<p:dataGrid>을 에 넣고 <p:dataGrid> 대신 <p:outputPanel>으로 업데이트하면됩니다.

<h:form id="scrapeFrm"> 
    <p:commandButton onclick="rcTest()" value="call server"/> 
    <h:inputHidden id="scrapeURL" value="url"/> 
    <p:remoteCommand name="rcTest" update="imageGrid" process="@this,scrapeURL" actionListener="#{bookmarklet.loadImages}" /> 
    <p:outputPanel id="imageGrid"> 
     <p:dataGrid var="img" rendered="#{bookmarkletBean.shouldRender} value="#{bookmarkletBean.imageURLs}""> 
      ... 
     </p:dataGrid> 
    </p:outputPanel> 
</h:form> 
+0

예 :

c12

+0

@ 콜린 아 .. 확인 내 대답이 업데이트되었습니다. – Mark

+0

도움을 주셔서 감사합니다! 위의 제안을 사용하여 조건부 렌더링을 수행 할 수 있었지만 패널을 다시 숨기는 방법은 무엇입니까? 나는 대화 상자의 closeListener = "# {bookmarklet.close}"onCloseUpdate = "imageGrid"를 사용하고 나서 bookmarklet.close 메서드에서 shouldRender를 false로 설정하려고 시도했지만 대화 상자가 다시 열리면 패널이 이미 렌더링되었습니다. 어떤 아이디어? – c12

관련 문제