See error in Primefaces red component

人走茶凉 提交于 2019-12-11 01:53:15

问题


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?

EDIT: Added screenshot & Code

My 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:

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");
    }

}

回答1:


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.



来源:https://stackoverflow.com/questions/18889481/see-error-in-primefaces-red-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!