Question

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

Red component

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

}
Was it helpful?

Solution

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:

Error message

It seems that I am missing a converter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top