Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 突出显示<;p:inputText>;使用PrimeFaces验证_Java_Spring_Jsf_Primefaces - Fatal编程技术网

Java 突出显示<;p:inputText>;使用PrimeFaces验证

Java 突出显示<;p:inputText>;使用PrimeFaces验证,java,spring,jsf,primefaces,Java,Spring,Jsf,Primefaces,我试图根据某些条件突出显示,但最终什么也没有得到。 以下是我的xhtml代码: <p:inputText value="#{loginTo.userName}" id="username" required="true" label="username" maxlength="20" requiredMessage="#{appLoginParameter['AppLoginNameRequiredMsg']}"> </p:inputText> 但我遇到了空指针异常。

我试图根据某些条件突出显示
,但最终什么也没有得到。 以下是我的xhtml代码:

<p:inputText value="#{loginTo.userName}" id="username" required="true" label="username" maxlength="20"  requiredMessage="#{appLoginParameter['AppLoginNameRequiredMsg']}">
</p:inputText>
但我遇到了空指针异常。

尝试以下操作:

public 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];

}

这段代码将只找到树中具有您传递的id的第一个组件。如果树中有两个具有相同名称的组件(如果它们位于两个不同的命名容器下,这是可能的),或者您也可以在表单中设置
prependId=“false”

在哪里获取空指针?UIInput password=(UIInput)uiComponent.getAttributes().get(“password”);在这行中“现在”,因为这是您第一次调用uiComponent。您的uiComponent是否为空?另外,
UIInput password=(UIInput)uiComponent.getAttributes().get(“密码”)
实际上是
UIInput password=(UIInput)uiComponent.getAttributes().get(“用户名”)在您提供的代码中。那可能会引起一些混乱…哦,对不起,我的错。但是我初始化我的UIC组件。与此类似,UIComponent=UIComponent.getCurrentComponent(facesContext);我不太确定,我贴了一个答案。希望它能帮助你D
public 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];

}