查看Primefaces红色组件中的错误 [英] See error in Primefaces red component

查看:109
本文介绍了查看Primefaces红色组件中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在tab组件中有一些Primefaces输入组件,它们是从java bean类获取数据的.他们完美地工作.问题是一定有问题,因为如果我切换到另一个选项卡然后又回来,则组件会变成红色.虽然它们仍然可以工作,但这可能与我的应用程序中存在的另一个问题有关.我怎么看这个红色是什么意思?控制台上没有消息.有没有我收到的消息吗?

I have some Primefaces input components in a tab component, which get their data from a java bean class. They work perfectly. The problem is that something is must be wrong, because if I change to another tab and come right back the components become red. They still work though, but this might be related with another problem I have in my application. How can I see what this red means? No messages appear on the console. Are there any messages that I don't get?

添加了屏幕截图&代码

Added screenshot & Code

我的代码:

XHTML:

<!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
<h:body>
    <ui:composition>
        <h:form>
            <p:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
                <h:outputText value="Item: "/>
                <p:selectOneMenu value="#{devTestController.items}">  
                    <f:selectItems value="#{devTestController.items}" var="item" itemLabel="#{item.label}" itemValue="#{item.value}"/>  
                </p:selectOneMenu>
            </p:panelGrid>
            <p:commandButton value="asdf1" action="#{devTestController.doAction()}"/>   
        </h:form>
    </ui:composition>
</h:body>
</html>

Java bean:

Java bean:

import java.util.LinkedList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class DevTestController
{
    private List<Parameter> items;

    @PostConstruct
    public void initList()
    {
        items = new LinkedList<>();
        items.add(new Parameter("Item1", "Item1"));
        items.add(new Parameter("Item2", "Item2"));
        items.add(new Parameter("Item3", "Item3"));
    }

    public List<Parameter> getItems()
    {
        return items;
    }

    public void doAction()
    {
        System.out.println("asdf");
    }

}

推荐答案

我找到了它.我不得不将h:messages标记放在某个位置,然后使用按钮对其进行更新. 我现在在XHTML中的表单:

I found it. I had to put an h:messages tag somewhere and update it using a button. My form in XHTML now:

<h:form>
    <h:messages id="errorMessages" style="color:red;margin:8px;" />
    <br></br>
    <p:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
        <h:outputText value="Item: "/>
        <p:selectOneMenu value="#{devTestController.items}">  
            <f:selectItems value="#{devTestController.items}" var="item" itemLabel="#{item.label}" itemValue="#{item.value}"/>  
        </p:selectOneMenu>
    </p:panelGrid>
    <p:commandButton value="asdf1" update = "errorMessages" action="#{devTestController.doAction()}"/>  
</h:form>

现在,当我按下按钮时会收到消息:

Now I get the messages when I press the button:

看来我想念一个转换器.

It seems that I am missing a converter.

这篇关于查看Primefaces红色组件中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆