动作侦听器的返回值未更新为输入文本值

时间:2019-09-05 17:19:36

标签: jsf

我从动作侦听器中调用了一个方法,该方法返回字符串,并且我打算在inputtext字段中对其进行更新,当我尝试这样做时,我不会在输入字段中获取值

我尝试使用过程=“ @ 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>

1 个答案:

答案 0 :(得分:0)

在JSF ajax更新中,意味着更新中提及的所有ID,我们都需要重新呈现这些组件。这并不意味着分配这些值。如果要使该值与inputText绑定,则将该值分配给与inputText绑定的后备bean变量。因此,在此之后,当您调用传递那个inputText组件以进行更新时,它将显示最新值。将您的backing 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.
    }