【问题标题】:Action listener return value is not getting updated into input text value动作侦听器返回值未更新为输入文本值
【发布时间】:2019-09-05 17:19:36
【问题描述】:

我从返回字符串的动作监听器中调用了一个方法,我打算在 inputtext 字段中更新它,当我尝试这样做时,我没有将值输入到输入字段中

我尝试使用 process ="@this",它可以完美执行操作,并且如果我删除该操作未执行,则不更新字段

//这是我的后台豆

public String getNameWithFormID(long id) {
        TMapper tMapper = new TDao();
         map= new HashMap<>();
            List<TBean> tList = tMapper.getDistinctTName();

            for(TBean t1:tList) {
                map.put(t1.getID(), t1.getName());
            }
        System.out.println("id is"+id+"this is map in submit"+map);
        System.out.println("this is value of id"+map.get(id));
        return  map.get(id);
    }

//这是我的jsf代码

                   <p:commandButton  id = "formidid" value="ADD DATA TO FORM NAME" style="margin-right:20px;"  
                            styleClass="ui-priority-primary" process = "@form"  ajax = "true"
                             onclick ="hideshowAddCat();" actionListener ="#{tServices.getNameWithID(tBean.ID)}" update = ":formid:panelgridid" >


                    </p:commandButton>
                </div>
            <div class="ui-g-12 ui-lg-4" style="background:#f2f2f2;margin-top:15px;">                              
            <div class="card card-w-title">
            <label for="Nameid">FORM_NAME<i class="fa fa-asterisk" style="color: red;"></i></label>
                <p:panelGrid id = "panelgridid" columns="1" layout="grid" styleClass="ui-panelgrid-blank form-group">
                     <p:inputText id="Nameid" placeholder="FORM_NAME" value="#{tBean.formName}" required = "true">
                     </p:inputText>
                     output is <h:outputText value = "#{tBean.Name}"/>
                </p:panelGrid>    
            </div>
            </div>

【问题讨论】:

    标签: jsf


    【解决方案1】:

    在 JSF ajax 中,更新意味着更新中提到的任何 ID/ID,我们需要重新渲染这些组件。这并不意味着分配这些值。如果您希望该值与 inputText 绑定,请将值分配给与 inputText 绑定的支持 bean 变量。因此,在那之后,当您调用 pass 该 inputText 组件以进行更新时,它将显示最新值。将您的支持 bean 方法更新为

    public void getNameWithFormID(long id) {
    
            TMapper tMapper = new TDao();
             map= new HashMap<>();
                List<TBean> tList = tMapper.getDistinctTName();
    
                for(TBean t1:tList) {
                    map.put(t1.getID(), t1.getName());
                }
            System.out.println("id is"+id+"this is map in submit"+map);
            System.out.println("this is value of id"+map.get(id));
            this.formName = map.get(id); // Change is here (assuming that formName is class level variable, as directly bind to backing bean.
        }
    

    【讨论】:

    • 太好了,我认为您可以接受并支持答案。 ;)
    • 感谢您的反馈!声望低于 15 人的投票将被记录,但不会更改公开显示的帖子得分。
    • 收到此回复
    猜你喜欢
    • 2016-04-25
    • 2016-11-19
    相关资源
    最近更新 更多