【问题标题】:Primefaces InputText passing empty value to the backing beanPrimefaces InputText将空值传递给支持bean
【发布时间】:2013-12-30 07:11:11
【问题描述】:

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

问题是,当我选择左侧的讨论,然后单击内容中的创建时,对话框中的文本消息正在将空白值传递给支持 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 bean,并且具有 txtMsg 的 get 和 set 方法。但是在提交时,set 方法被触发,但值为空白。下面是backing 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);
    }
}

任何建议我在这里做错了什么?

【问题讨论】:

    标签: jsf jsf-2 primefaces


    【解决方案1】:

    尝试只使用一种形式。删除内部形式。我也有类似的问题,删除内部形式对我有用。

    如果这不起作用,请尝试将“process”或“execute”属性添加到调用您的 bean 方法的按钮

    【讨论】:

    • 感谢您的回复。我没有任何嵌套形式。我尝试使用命令按钮的进程属性,但这并没有改变任何东西。由于它在左窗格上没有选择任何内容时将值传递给支持 bean,我认为可能将焦点添加到表单可能会受益,但这也没有。尝试在视图和会话范围之间切换,也没有帮助。
    • 我知道它太老了.. 但是有什么解决办法吗?我遇到了同样的问题...
    猜你喜欢
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 2011-06-09
    • 1970-01-01
    • 2012-07-19
    • 1970-01-01
    相关资源
    最近更新 更多