java.lang.illegalargumentexception нераспознанный тип контента - PullRequest
1 голос
/ 21 октября 2019

Получение java.lang.illegalargumentexception нераспознанного типа контента при отображении диалога.

Я пишу тестовое приложение, которое реализует некоторые демонстрационные примеры в простых лицах. В частности, я хочу реализовать таблицу данных (primefaces), в которой я могу открыть диалог и добавить командировочные расходы по нажатию кнопки. Это работало нормально с сервером Glassfish 5.0.1 (включая Mojarra 2.3.2 и Primefaces 5.0), но я получаю исключение выше с сервером Glassfish 5.1 (включая Mojarra 2.3.9 и Primefaces 6.1). В любом случае, список затрат в компоненте поддержки поддерживает правильные значения, только таблица не обновляется. Что может быть не так? Пожалуйста, игнорируйте некоторые константы стиля в bean-компоненте, это всего лишь тестовый проект.

contentCreateExpense.xhtml:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <body>
    <ui:composition>
        <h:form>
            <div>
                <h:outputLabel value="Neue Abrechnung erstellen" styleClass="caption-label-style"/>
                <br/>
            </div>

            <div>
                <p:outputLabel value="Name der Abrechnung: "/>
                <p:inputText value="#{createExpenseController.expenseName}">
                    <f:ajax/>
                </p:inputText>
                <br/>
            </div>

            <p:panel header="Details Ihrer Dienstreise">
                <h:panelGrid columns="2" cellpadding="5">
                    <p:outputLabel for="country" value="Land: "/>
                    <p:selectOneMenu id="country" value="#{createExpenseController.country}">
                        <p:ajax listener="#{createExpenseController.onCountryChange}" update="city" />
                        <f:selectItem itemLabel="Waehlen Sie ein Land aus" itemValue="" noSelectionOption="true"/>
                        <f:selectItems value="#{createExpenseController.countries}"/>
                    </p:selectOneMenu>

                    <p:outputLabel for="city" value="Stadt: "/>
                    <p:selectOneMenu id="city" value="#{createExpenseController.city}" style="#{createExpenseController.dropdownStyle}">
                        <f:selectItem itemLabel="Waehlen Sie eine Stadt aus" itemValue="" noSelectionOption="true"/>
                        <f:selectItems value="#{createExpenseController.cities}"/>
                    </p:selectOneMenu>

                    <p:outputLabel for="customer" value="Kunde: "/>
                    <p:selectOneMenu id="customer" value="#{createExpenseController.customer}" style="#{createExpenseController.dropdownStyle}">
                        <f:selectItem itemLabel="Waehlen Sie einen Kunden aus" itemValue="" noSelectionOption="true"/>
                        <f:selectItems value="#{createExpenseController.customers}"/>
                    </p:selectOneMenu>
                </h:panelGrid>

                <p:separator />

                <h:panelGroup id="dataTableGroup">
                    <p:dataTable id="costTable"
                                 var="c"
                                 value="#{createExpenseController.costs}"
                                 emptyMessage="Keine Kosten vorhanden">
                        <p:column id="positionColumn" headerText="Belegart" style="#{createExpenseController.tableStyle}">
                            <p:outputLabel id="position" value="#{c.type}" />
                        </p:column>
                        <p:column id="costsHeader" headerText="Kosten" style="#{createExpenseController.tableStyle}">
                            <p:outputLabel id="cost" value="#{c.cost}" />
                        </p:column>
                        <p:column id="actionHeader" headerText="Aktion" style="#{createExpenseController.tableStyle}">
                            <p:commandLink
                                id="deleteButton"
                                update="costTable"
                                value="Position loeschen"
                                process="@this"
                                actionListener="#{createExpenseController.removeCost(c)}"/>
                        </p:column>
                    </p:dataTable>
                </h:panelGroup>                

                <p:commandButton onclick="PF('costDialog').show();" value="Weitere Position hinzufuegen" update="costTable"/>
            </p:panel>
            <p:commandLink actionListener="#{createExpenseController.forwardMyExpensesActionListener()}" value="Abrechnung erstellen"/>
        </h:form>
        <h:form>
            <p:dialog header="Beleg hinzufuegen" widgetVar="costDialog" height="200" width="400" resizable="false">
                <p:panel>
                    <h:panelGrid id="costPanel" columns="2" cellpadding="5">
                        <p:outputLabel value="Belegart: "/>
                        <p:inputText id="typeInput" value="#{createExpenseController.currentType}" 
                                     required="true" requiredMessage="Geben Sie bitte eine Belegart an."/>
                        <p:outputLabel value="Kosten: "/>
                        <p:inputText id="costInput" value="#{createExpenseController.currentCost}" 
                                     validator="#{createExpenseController.validateBigDecimal}" required="true"
                                     requiredMessage="Geben Sie bitte die Kosten an." />
                        <p:message id="msgIdType" for="typeInput" style="#{createExpenseController.labelStyle}" />
                        <p:message id="msgIdCost" for="costInput" style="#{createExpenseController.labelStyle}" />
                    </h:panelGrid>
                </p:panel>
                <p:commandButton value="Kosten hinzufuegen" actionListener="#{createExpenseController.addCost()}" 
                                 oncomplete="if(!args.validationFailed) PF('costDialog').hide();" update=":#{p:component('costTable')} typeInput costInput"/>
            </p:dialog>  
        </h:form>
    </ui:composition>
</body>
</html>    

CreateExpenseController.java:

package com.testmanagement.controller;

import com.testmanagement.dto.Cost;
import com.testmanagement.dto.LastLoginDto;
import com.testmanagement.service.LastLoginService;
import com.testmanagement.util.URLParams;
import java.io.IOException;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;

@Named
@ViewScoped
public class CreateExpenseController implements Serializable {

    private static final String CAPTION_LABEL_STYLE = "margin-right: 10px; margin-left: 10px; margin-top: 10px; margin-bottom: 10px; color: #3399ff; background-color: white; font-weight: normal; font-size: 12px; background: white; font-size: 18px;";
    private static final String LABEL_STYLE = "margin-right: 10px; margin-left: 10px; margin-top: 10px; margin-bottom: 10px; color: #3399ff; background-color: white; font-weight: normal; font-size: 12px; background: white;";
    private static final String BUTTON_STYLE = "margin-right: 10px; margin-left: 10px; margin-top: 10px; margin-bottom: 10px; color: #3399ff; background-color: white; font-weight: normal; font-size: 12px; background: white;";
    private static final String MENU_STYLE = "color: #3399ff; background-color: white; font-weight: normal; font-size: 12px; background: white;";
    private static final String DROPDOWN_STYLE = "margin-right: 10px; margin-left: 10px; width: 200px; color: #3399ff; background-color: white; font-weight: normal; font-size: 12px; background: white;";
    private static final String TABLE_STYLE = "color: #3399ff; background-color: white; font-weight: normal; font-size: 12px; background: white;";

    private String text;
    private String expenseName;
    private Date expenseDate;

    private List<Cost> costs;
    private BigDecimal sum;
    private String currentType = "";
    private String currentCost = "";

    private Map<String, Map<String, String>> data = new HashMap<String, Map<String, String>>();
    private String country;
    private String city;
    private String customer;
    private Map<String, String> countries;
    private Map<String, String> cities;
    private Map<String, String> customers;

    @Inject
    private ParamTransportBean paramTransportBean;

    @Inject
    private LastLoginService lastLoginService;

    @PostConstruct
    public void init() {
        try {
            lastLoginService.save(new LastLoginDto(null, "manager", new Date()));
        } catch (Exception e) {
        }

        countries = new HashMap<String, String>();
        countries.put("USA", "USA");
        countries.put("Deutschland", "Deutschland");
        countries.put("Brasilien", "Brasilien");

        Map<String, String> map = new HashMap<String, String>();
        map.put("New York", "New York");
        map.put("San Francisco", "San Francisco");
        map.put("Denver", "Denver");
        data.put("USA", map);

        map = new HashMap<String, String>();
        map.put("Berlin", "Berlin");
        map.put("Muenchen", "Muenchen");
        map.put("Frankfurt", "Frankfurt");
        data.put("Deutschland", map);

        map = new HashMap<String, String>();
        map.put("Sao Paulo", "Sao Paulo");
        map.put("Rio de Janerio", "Rio de Janerio");
        map.put("Salvador", "Salvador");
        data.put("Brasilien", map);

        customers = new HashMap<String, String>();
        customers.put("SAP", "SAP");
        customers.put("Microsoft", "Microsoft");
        customers.put("IBM", "IBM");

        costs = new ArrayList<Cost>();
        sum = BigDecimal.ZERO;
    }

    public String getCaptionLabelStyle() {
        return CAPTION_LABEL_STYLE;
    }

    public String getLabelStyle() {
        return LABEL_STYLE;
    }

    public String getButtonStyle() {
        return BUTTON_STYLE;
    }

    public String getMenuStyle() {
        return MENU_STYLE;
    }

    public String getDropdownStyle() {
        return DROPDOWN_STYLE;
    }

    public String getTableStyle() {
        return TABLE_STYLE;
    }

    public Map<String, Map<String, String>> getData() {
        return data;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCustomer() {
        return customer;
    }

    public void setCustomer(String customer) {
        this.customer = customer;
    }

    public Map<String, String> getCountries() {
        return countries;
    }

    public Map<String, String> getCities() {
        return cities;
    }

    public Map<String, String> getCustomers() {
        return customers;
    }

    public String getText() {
        return text;
    }

    public String getExpenseName() {
        return expenseName;
    }

    public void setExpenseName(String expenseName) {
        this.expenseName = expenseName;
    }

    public Date getExpenseDate() {
        return expenseDate;
    }

    public void setExpenseDate(Date expenseDate) {
        this.expenseDate = expenseDate;
    }

    public void setText(String text) {
        this.text = text;
    }

    public List<Cost> getCosts() {
        return costs;
    }

    public void setCosts(List<Cost> costs) {
        this.costs = costs;
    }

    public BigDecimal getSum() {
        return sum;
    }

    public String getCurrentType() {
        return currentType;
    }

    public void setCurrentType(String currentType) {
        this.currentType = currentType;
    }

    public String getCurrentCost() {
        return currentCost;
    }

    public void setCurrentCost(String currentCost) {
        this.currentCost = currentCost;
    }

    public int getNumberOfCosts() {
        return costs.size();
    }

    public void addCost() {
        BigDecimal c = new BigDecimal(currentCost);
        costs.add(new Cost(currentType, c));
        sum = sum.add(c);
        currentType = null;
        currentCost = null;
    }

    public void removeCost(Cost c) {
        costs.remove(c);
        sum = sum.subtract(c.getCost());
    }

    public int indexOf(BigDecimal c) {
        return costs.indexOf(c);
    }

    public void validateBigDecimal(FacesContext context, UIComponent comp, Object value) {
        String stringValue = (String) value;
        BigDecimal c;
        try {
            c = new BigDecimal(stringValue);
            if (c.compareTo(BigDecimal.ZERO) <= 0) {
                ((UIInput) comp).setValid(false);
                FacesMessage message = new FacesMessage("msgIdCost", "Geben Sie bitte eine positive Zahl ein.");
                context.addMessage(comp.getClientId(context), message);
            }
        } catch (Exception e) {
            ((UIInput) comp).setValid(false);
            FacesMessage message = new FacesMessage("msgIdCost", "Geben Sie bitte eine gueltige Zahl ein.");
            context.addMessage(comp.getClientId(context), message);
        }
    }

    public void onCountryChange() {
        if (country != null && !country.equals("")) {
            cities = data.get(country);
        } else {
            cities = new HashMap<String, String>();
        }
    }

    public void forwardMyExpensesActionListener() {
        URLParams urlParams = new URLParams();
        String conversationId = paramTransportBean.initializeConversation();
        paramTransportBean.setExpenseName(expenseName);
        paramTransportBean.setCountry(country);
        paramTransportBean.setCity(city);
        paramTransportBean.setCustomer(customer);
        paramTransportBean.setCosts(costs);
        paramTransportBean.setSum(sum);
        urlParams.appendParameter("cid", conversationId);
        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
        String url = "myExpensesClient.xhtml" + urlParams.getParams();
        try {
            externalContext.redirect(url);
        } catch (IOException e) {
        }
    }

}    

Ожидаемый результат заключается в том, что моя таблица данных обновляется после добавления стоимости перемещения в диалоговом окне. Однако я получаю следующее исключение:

Severe:   Error Rendering View[/createExpenseClient.xhtml]
java.lang.IllegalArgumentException: Unerkannter Inhaltstyp
	at com.sun.faces.renderkit.RenderKitImpl.createResponseWriter(RenderKitImpl.java:259)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1125)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:415)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:170)
	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:132)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:102)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:199)
	at javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:708)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1540)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:119)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:550)
	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:75)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:114)
	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:199)
	at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:439)
	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:144)
	at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
	at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
	at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
	at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
	at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
	at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:515)
	at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
	at java.lang.Thread.run(Thread.java:745)    
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...