Primefaces InputText将空值传递给辅助bean

时间:2013-12-12 02:29:34

标签: jsf jsf-2 primefaces

我正在使用JSF模板,其中包含聊天应用程序的顶视图,左视图和内容视图。左侧是使用复合组件显示的讨论列表。当我选择一个讨论时,所选讨论中的每个对话都需要显示在内容中。内容窗格中有一个创建按钮,允许在所选讨论中创建新文本。单击“创建”,将打开一个对话框以输入消息文本。

问题是,当我在左侧选择讨论,然后单击内容中的create时,对话框中的文本消息将空值传递给辅助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>

我对create的支持bean(displayDiscussionBean)是一个SessionScoped bean,并且为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);
    }
}

有什么建议我在这里做错了吗?

1 个答案:

答案 0 :(得分:0)

请尝试仅使用一个表单。删除内部表格。我也有类似的问题,并删除内部形式为我工作。

如果这不起作用,请尝试将“进程”或“执行”属性添加到调用bean方法的按钮