2012-03-20 79 views
1

有沒有辦法讓它當我點擊一個p:按鈕時出現一個隱藏的p:面板,並在下次它被渲染時再次隱藏?Primefaces面板

  <h:commandButton id="saveButton" value="save" oncomplete="cartComplete.show();"> 
      </h:commandButton> 
      <p:panel widgetVar="cartComplete"> 
       Shopping Cart Saved 
      </p:panel> 
+0

_「並且在下次渲染時再次隱藏」_這是什麼意思?頁面重新加載? – 2012-03-20 19:02:37

回答

2

嘗試......

<p:commandButton value="Save" action="#{myBean.setPanelVisibility}" update=":myForm:myPanel"/> 
<p:panel id="myPanel" rendered="#{myBean.renderPanel}"/> 

在豆切換renderPanel屬性。

1

在這裏你去...

<h:body> 
    <h:form prependId="false"> 
     <p:panel id="myPanel" style="display:none"> 
      Shopping Cart Saved 
     </p:panel> 
     <p:commandButton id="show" value="show" onclick="jQuery('#myPanel').show()"> 
     </p:commandButton> 
     <p:commandButton id="hide" value="hide" update="myPanel"> 
     </p:commandButton> 
    </h:form> 
</h:body> 

解釋:風格=「顯示:無」使面板被隱藏,並whenver要顯示它使用jquery(與primefaces已經自帶).show ()函數,第二個命令按鈕的最後update="myPanel"將重新呈現面板,它會再次隱藏...


更新

只是01同樣的想法,在Java類

私人字符串renderPanel = 「假」 使用styleClass="hide"(而不是style="display:none"

凡在你的CSS

.hide { 
    display:none; 
} 
+0

如果你需要面板的styleClass,你會怎麼做到這一點? – user489041 2013-09-09 17:57:26

+0

@ user489041,更新了我的答案... – Daniel 2013-09-09 18:40:36

0

; <p:commandButton value="Save" action="#{myBean.setPanelVisibility}" update="myPanel"/> <p:panel id="myPanel" rendered="#{myBean.renderPanel=='true'}"/>