2013-12-12 69 views
0

我正在使用帶有聊天應用程序的頂部,左側和內容視圖的JSF模板。左邊是使用複合組件顯示的討論列表。當我選擇一個討論時,所選討論中的每個對話都需要在內容中顯示。內容窗格中有一個創建按鈕,允許在選定的討論中創建新文本。點擊創建時,會打開一個對話框輸入消息文本。Primefaces InputText將空值傳遞給支持bean

問題是,當我選擇左側的討論,然後單擊內容中的創建時,對話框中的文本消息將空白值傳遞給輔助bean。 setter方法正在調用,但傳遞的值爲空。我觀察到,如果我在加載頁面時單擊創建,而不選擇討論,它會發送正確值的消息。即使在選擇討論後,每一個後續的創建仍然會傳遞相同的價值。

我使用Primefaces 3.4.2和GlassFish 4

下面是中央窗格XHTML

<h:body> 
     <h:form id="newForm"> 
      <p:commandLink id="test" value="Create Bubble" /> 
      <p:overlayPanel id="panel" for="test" > 
       <p:commandButton id="map" icon="ui-icon-map" onclick="map_dlg.show();"/> 
       <p:commandButton id="map1" icon="ui-icon-document" onclick="survey_dlgcreate.show();"/> 
       <p:commandButton id="map2" icon="ui-icon-folder" onclick="txt_dlg.show();"/> 
      </p:overlayPanel> 
      <a:discussionComp discussion="#{displayDiscussionBean}"/> 
     </h:form>      
     <p:focus id="focus" context="textdlg"/> 
     <p:dialog id="textdlg" modal="true" header="Text bubble" appendToBody="true" hideEffect="fade" widgetVar="txt_dlg"> 
        <h:form id="t3"> 
         <p:outputLabel value="Enter your message"/><p:inputText value="#{displayDiscussionBean.txtMsg}"/> 
         <p:commandButton icon="Post" action="#{displayDiscussionBean.createTextBubble()}" oncomplete="txt_dlg.hide();"/> 
        </h:form> 
     </p:dialog>      
</h:body> 

這裏是我的左邊面板是什麼。

<!--IMPLEMENTATION--> 
<cc:implementation> 
    <h:form id="leftPanel"> 
     <p:dataTable id="disc" value="#{cc.attrs.discussionModel}" var="discussion" style="margin-top: 2px;height: 100%" selectionMode="single" selection="#{discussionBean.selectedDiscussion}" > 
      <p:ajax event="rowSelect" update=":detail_panel" /> 
      <f:facet name="header"> 
       Discussions 
       <h:commandLink action="#{discussionBean.createDiscussion()}"> 
        <p:graphicImage id="add" url="/resources/images/plus.png" style="height: 25px;float: right" /> 
        <p:tooltip for="add" value="Add Discussion" style="font-size: 12px" hideEffect="fade"/> 
       </h:commandLink> 
      </f:facet> 
      <p:column style="font-size: 12px;"> 
       #{discussion.title} 
      </p:column> 
     </p:dataTable> 
    </h:form> 
</cc:implementation> 

我支持bean(displayDiscussionBean)的創建是一個SessionScoped豆,並先後爲txtMsg get和set方法。然而,在提交時,set方法被觸發,但是具有空值。以下是後臺bean。

@Named 
@SessionScoped 
public class DisplayDiscussionBean implements Serializable { 


    private static final long serialVersionUID = 1L; 
    @EJB 
    private DiscussionEJB discussionEJB; 
    private TextEJB textEJB; 
    private DiscussionEntity de; 
    private HashMap<Integer, TextEntity> textMap; 
    private String selectedOption; 
    @Inject 
    private DiscussionBean discussionBean; 
    private String msg; 
    private Integer currentBubbleId; 
    private Integer currentBubbleType = 55; 
    @Inject 
    private Locations loc; 
    private String txtMsg; 
    private TreeNode root; 

    private Integer did; 

    public Integer getDid() { 
     return did; 
    } 

    public void setDid(Integer did) { 
     this.did = did; 
     setDetails(); 
    } 

    public DisplayDiscussionBean() { 
    } 

    public DisplayDiscussionBean(Integer id) { 
    } 

    private void setDetails() { 
     de = discussionEJB.getDiscussionDetails(did); 
     textMap = new HashMap<>(); 
     root = new DefaultTreeNode("Root", null); 
     Map<Integer, TreeNode> nodeMap = new HashMap<>(); 
     for (BubbleEntity b : de.getBubbleList()) { 
      TreeNode node = new DefaultTreeNode(b, null); 
      nodeMap.put(b.getBubbleId(), node); 
       TextEntity te = (TextEntity) b; 
       textMap.put(te.getBubbleId(), te); 
     } 
     for (BubbleEntity b : de.getBubbleList()) { 
      if (b.getParentId() != null) { 
       TreeNode currNode = nodeMap.get(b.getBubbleId()); 
       TreeNode parentNode = nodeMap.get(b.getParentId()); 
       currNode.setParent(parentNode); 
      } else { 
       TreeNode currNode = nodeMap.get(b.getBubbleId()); 
       currNode.setParent(root); 
      } 

     } 
    } 
    public void createTextBubble() {  
     if (did == null){ 
      did=discussionBean.getSelectedDiscussion().getDiscussionId();    
    } 
     textEJB.createTextBubble(txtMsg, did, null);  
    } 
    public DiscussionEntity getDe() { 
     return de; 
    } 
    public void setDe(DiscussionEntity de) { 
     this.de = de; 
    } 
    public TreeNode getRoot() { 
     return root; 
    } 
    public void setRoot(TreeNode root) { 
     this.root = root; 
    } 
    public HashMap<Integer, TextEntity> getTextMap() { 
     return textMap; 
    } 
    public void setTextMap(HashMap<Integer, TextEntity> textMap) { 
     this.textMap = textMap; 
    } 
    public String getSelectedOption() { 
     return selectedOption; 
    } 
    public void setSelectedOption(String selectedOption) { 
     this.selectedOption = selectedOption; 
    } 
    public Integer getCurrentBubbleId() { 
     return currentBubbleId; 
    } 
    public void setCurrentBubbleId(Integer currentBubbleId) { 
     this.currentBubbleId = currentBubbleId; 
    } 
    public Integer getCurrentBubbleType() { 
     return currentBubbleType; 
    } 
    public void setCurrentBubbleType(Integer currentBubbleType) { 
     this.currentBubbleType = currentBubbleType; 
    } 
    public String getTxtMsg() { 
     return txtMsg; 
    } 
    public void setTxtMsg(String txtMsg) { 
     this.txtMsg = txtMsg; 
     System.out.println("set text msg is "+txtMsg); 
    } 
} 

任何suggestioins我在做什麼錯在這裏?

回答

0

請嘗試僅使用一種形式。刪除內部表單。我也有類似的問題,並刪除內部形式爲我工作。

如果不起作用嘗試加入「過程」或「執行」屬性,你的按鈕它調用你的bean的方法

+0

感謝您的答覆。我沒有任何嵌套形式。我嘗試使用命令按鈕的進程屬性,但沒有改變任何東西。由於它在左側窗格中沒有選擇任何內容時將值傳遞給後臺bean,因此我認爲可能會將焦點添加到表單可能會受益,但也沒有。試圖在視圖和會話範圍之間切換,這也沒有幫助。 – jpr

+0

我知道它太舊了......但有沒有解決方法?我來到同一個問題... – JiangHongTiao

相關問題