Jsf 复合组件列表输入文本值

Jsf 复合组件列表输入文本值,jsf,jsf-2,primefaces,composite-component,Jsf,Jsf 2,Primefaces,Composite Component,我有一个XHTML页面,它描述了以下用户复合组件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"

我有一个XHTML页面,它描述了以下用户复合组件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui_component="http://java.sun.com/jsf/composite/ui_component" >
    <h:body>
         <h:form id="mergeform">          
                    <p:separator/>
                    <p:panelGrid styleClass="tableEdit" style="width: 100%">
                        <f:facet name="header">
                            <p:row>    
                                <p:column colspan="2">  
                                    <h:outputLabel style="font-size: 20px;" value="1-ое застрахованное лицо" />    
                                </p:column>
                                <p:column style="text-align: right; width: 20em;">
                                    <p:commandButton style="font-size: 14px;" value="Общий поиск" immediate="true" 
                                                     onclick="dialogPersonList.show();document.getElementById('mergeform:personNumber').value = '1';dlg22Search.show();" 
                                                     action="#{mergeBean.updateListPerson}"
                                                     oncomplete="dlg22Search.hide();"
                                                     update=":mergeform:enpsearchtable mergeform:checkSearch"/>
                                </p:column> 
                            </p:row> 
                        </f:facet>                  
                        <p:row>    
                            <p:column colspan="3">
                                <ui_component:personTable id="First" form="mergeform" id_link="Second" bean="#{mergeBean}" val="#{mergeBean.merge}" smoChanger="true" >
                                    <f:validator validatorId="FIOValidator" for="FIOValid" />                               
                                </ui_component:personTable>                            
                          </p:column> 
                        </p:row> 
                    </p:panelGrid>
                    <p:panelGrid styleClass="tableEdit" style="width: 100%">
                        <f:facet name="header">
                            <p:row>    
                                <p:column colspan="2">  
                                    <h:outputLabel style="font-size: 20px;" value="2-ое застрахованное лицо" />  
                                </p:column>
                                <p:column style="text-align: right; width: 20em;">
                                    <p:commandButton style="font-size: 14px;" value="Общий поиск" immediate="true" 
                                                     onclick="dialogPersonList.show();document.getElementById('mergeform:personNumber').value = '2';dlg22Search.show();"
                                                     action="#{mergeBean.updateListPerson}" 
                                                     oncomplete="dlg22Search.hide();"
                                                     update=":mergeform:enpsearchtable mergeform:checkSearch" />
                                </p:column> 
                            </p:row> 
                        </f:facet>
                        <p:row>    
                            <p:column colspan="3">  
                                <ui_component:personTable id="Second" bean="#{mergeBean}" val="#{mergeBean.merge.inputData}" smoChanger="true" >
                                    <f:validator validatorId="FIOValidator" for="FIOValid" />  
                                </ui_component:personTable>
                            </p:column> 
                        </p:row> 
                    </p:panelGrid>
         </h:form>        
    </h:body>
</html>
我试图绑定到第一个自定义组件中的第一个文本输入,以及在第二个自定义组件中查找关联文本输入并将其值检查为空和null的方法。但当我在pery input中插入一行时,第二个输入将被插入调试器input.getValue()。ToString()等于用户输入的值,而不是实际值。为什么会发生这种情况?我如何通过编程在侦听器中获得真正的价值

PS,因此我在DOM树中查找组件:

 public static UIComponent findComponent(final String id) {
    FacesContext context = FacesContext.getCurrentInstance();
    UIViewRoot root = context.getViewRoot();
    final UIComponent[] found = new UIComponent[1];

    root.visitTree(new FullVisitContext(context), new VisitCallback() {
        @Override
        public VisitResult visit(VisitContext context, UIComponent component) {
            if (component.getId().equals(id)) {
                found[0] = component;
                return VisitResult.COMPLETE;
            }
            return VisitResult.ACCEPT;
        }
    });

    return found[0];
}
@ManagedBean
@SessionScoped
public class MergeBean implements Serializable {

    private Person selectedPerson;

    public MergeBean() {
    }

    public Message getMerge() {
        if (this.merge == null) {
            this.merge = new Message();
            this.merge.setInputData(new Message());
        }
        return this.merge;
    }

    public void setMerge(Message merge) {
        this.merge = merge;
    }

    public void changeField(AjaxBehaviorEvent event) {
        String id = event.getComponent().getId();
        String valStr = ((HtmlInputText) event.getComponent()).getValue().toString();
        if (valStr != null && !valStr.isEmpty()) {
            String idChange = id.substring(0, id.length() - 5);
            UIInput input = (UIInput) UtilsUIXhtml.findComponent(idChange + "Second");
            //TODO
            Object objTemp = input.getSubmittedValue();
            //String tempStr = objTemp.toString();
            String cngStr = input.getValue().toString();
            if (cngStr == null || cngStr.isEmpty()) {
                input.setValue(valStr);
            }
        }
    }
}
 public static UIComponent findComponent(final String id) {
    FacesContext context = FacesContext.getCurrentInstance();
    UIViewRoot root = context.getViewRoot();
    final UIComponent[] found = new UIComponent[1];

    root.visitTree(new FullVisitContext(context), new VisitCallback() {
        @Override
        public VisitResult visit(VisitContext context, UIComponent component) {
            if (component.getId().equals(id)) {
                found[0] = component;
                return VisitResult.COMPLETE;
            }
            return VisitResult.ACCEPT;
        }
    });

    return found[0];
}