Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

mysql - trying to upgrade old java jsf application

Sorry first time i am posting anything.... I am trying to upgrade an old Java/JSF application to tomcat 8, JSF 1.2 and JDK 1.6. I am getting interactive errors on the dataconverter.

Here is the error when trying to save: Screenshot

#{currentRow.value['horseledger.DATE']}' Cannot convert [3/31/19 12:00 AM] of type [class java.util.Date] to [class java.sql.Date]

Here is the JSF code:

<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="2.1" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:webuijsf="http://www.sun.com/webui/webuijsf">
    <jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
    <f:view>
        <webuijsf:page id="page1">
            <webuijsf:html id="html1">
                <webuijsf:head id="head1">
                    <webuijsf:link id="link1" url="/resources/stylesheet.css"/>
                </webuijsf:head>
                <webuijsf:body id="body1" style="-rave-layout: grid">
                    <webuijsf:form binding="#{PartnerTrans.form1}" id="form1" virtualFormsConfig="partner | partnerDD | partnerDD , statement | statementDD | statementDD , save | table1:tableRowGroup1:tableColumn2:dropDown1 table1:tableRowGroup1:tableColumn5:textField3 table1:tableRowGroup1:tableColumn6:textField4 table1:tableRowGroup1:tableColumn3:textField1 table1:tableRowGroup1:tableColumn4:textField2 | savebtn , add/delete | | table1:tableRowGroup1:tableColumn7:button1 addbtn">
                        <div style="position: absolute; left: 48px; top: 0px">
                            <jsp:directive.include file="header.jspf"/>
                        </div>
                        <webuijsf:label id="label1" labelLevel="1" style="position: absolute; left: 48px; top: 120px" text="Partner:"/>
                        <webuijsf:label id="label2" labelLevel="1" style="position: absolute; left: 48px; top: 144px" text="Statement:"/>
                        <webuijsf:table augmentTitle="false" id="table1" style="position: absolute; left: 48px; top: 216px" title="Transactions" width="560">
                            <webuijsf:tableRowGroup binding="#{PartnerTrans.tableRowGroup1}" id="tableRowGroup1" rows="10"
                                sourceData="#{PartnerTrans.partnerledgerDataProvider}" sourceVar="currentRow">
                                <webuijsf:tableColumn headerText="Transaction" id="tableColumn2">
                                    <webuijsf:dropDown converter="#{PartnerTrans.dropDown1Converter}" id="dropDown1"
                                        items="#{PartnerTrans.partnertranstypeDataProvider.options['transtype.TRANSTYPE,transtype.TRANSDESC']}" selected="#{currentRow.value['partnerledger.TRANSTYPE']}"/>
                                    <webuijsf:message for="dropDown1" id="message1" showDetail="false" showSummary="true"/>
                                </webuijsf:tableColumn>
                                <webuijsf:tableColumn headerText="Units" id="tableColumn3" sort="partnerledger.UNITS">
                                    <webuijsf:textField id="textField1" text="#{currentRow.value['partnerledger.UNITS']}"/>
                                    <webuijsf:message for="textField1" id="message2" showDetail="false" showSummary="true"/>
                                </webuijsf:tableColumn>
                                <webuijsf:tableColumn headerText="Unit Price" id="tableColumn4" sort="partnerledger.UNITPRICE">
                                    <webuijsf:textField id="textField2" text="#{currentRow.value['partnerledger.UNITPRICE']}"/>
                                    <webuijsf:message for="textField2" id="message3" showDetail="false" showSummary="true"/>
                                </webuijsf:tableColumn>
                                <webuijsf:tableColumn headerText="Total" id="tableColumn1" width="20">
                                    <webuijsf:staticText converter="#{PartnerTrans.numberConverter1}" id="staticText1" text="#{currentRow.value['partnerledger.UNITS'] * currentRow.value['partnerledger.UNITPRICE']}"/>
                                </webuijsf:tableColumn>
                                <webuijsf:tableColumn headerText="Date" id="tableColumn5" sort="partnerledger.DATE">
                                    <webuijsf:textField converter="#{PartnerTrans.dateTimeConverter1}" id="textField3" text="#{currentRow.value['partnerledger.DATE']}"/>
                                    <webuijsf:message for="textField3" id="message4" showDetail="false" showSummary="true"/>
                                </webuijsf:tableColumn>
                                <webuijsf:tableColumn headerText="Notes" id="tableColumn6" sort="partnerledger.NOTES">
                                    <webuijsf:textField id="textField4" text="#{currentRow.value['partnerledger.NOTES']}"/>
                                    <webuijsf:message for="textField4" id="message5" showDetail="false" showSummary="true"/>
                                </webuijsf:tableColumn>
                                <webuijsf:tableColumn headerText="Delete" id="tableColumn7">
                                    <webuijsf:button actionExpression="#{PartnerTrans.button1_action}" id="button1" text="Delete"/>
                                </webuijsf:tableColumn>
                            </webuijsf:tableRowGroup>
                        </webuijsf:table>
                        <webuijsf:button actionExpression="#{PartnerTrans.addbtn_action}" id="addbtn"
                            style="left: 72px; top: 192px; position: absolute; width: 150px" text="Add Transaction"/>
                        <webuijsf:button actionExpression="#{PartnerTrans.savebtn_action}" id="savebtn"
                            style="left: 240px; top: 192px; position: absolute; width: 150px" text="Save Changes"/>
                        <webuijsf:button actionExpression="#{PartnerTrans.returnbtn_action}" id="returnbtn"
                            style="left: 408px; top: 192px; position: absolute; width: 150px" text="Return to Menu"/>
                        <webuijsf:staticText id="staticText2" style="position: absolute; left: 432px; top: 144px" text="Statement Total:"/>
                        <webuijsf:staticText binding="#{PartnerTrans.totalstxt}" converter="#{PartnerTrans.numberConverter1}" id="totalstxt" style="position: absolute; left: 528px; top: 144px"/>
                        <webuijsf:messageGroup id="messageGroup1" style="left: 624px; top: 144px; position: absolute"/>
                        <webuijsf:dropDown binding="#{PartnerTrans.statementDD}" converter="#{PartnerTrans.bigDecimalConverter1}" id="statementDD"
                            items="#{PartnerTrans.statementdatesDataProvider.options['statementdates.STATEMENTID,statementdates.STATEDESC']}"
                            onChange="webui.suntheme.common.timeoutSubmitForm(this.form, 'statementDD');" style="position: absolute; left: 144px; top: 144px" valueChangeListenerExpression="#{PartnerTrans.statementDD_processValueChange}"/>
                        <webuijsf:dropDown binding="#{PartnerTrans.partnerDD}" converter="#{PartnerTrans.bigDecimalConverter2}" id="partnerDD"
                            items="#{PartnerTrans.partnersDataProvider.options['partners.PARTNERID,partners.PARTNERNAME']}"
                            onChange="webui.suntheme.common.timeoutSubmitForm(this.form, 'partnerDD');" style="position: absolute; left: 144px; top: 120px" valueChangeListenerExpression="#{PartnerTrans.partnerDD_processValueChange}"/>
                    </webuijsf:form>
                </webuijsf:body>
            </webuijsf:html>
        </webuijsf:page>
    </f:view>
</jsp:root>

here is the java code:

/*
 * PartnerTrans.java
 *
 * Created on July 10, 2007, 12:12 AM
 * Copyright ketnera
 */
package renpheracctv5;

import com.sun.data.provider.RowKey;
import com.sun.data.provider.impl.CachedRowSetDataProvider;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.Body;
import com.sun.webui.jsf.component.Button;
import com.sun.webui.jsf.component.DropDown;
import com.sun.webui.jsf.component.Form;
import com.sun.webui.jsf.component.Head;
import com.sun.webui.jsf.component.Html;
import com.sun.webui.jsf.component.Label;
import com.sun.webui.jsf.component.Link;
import com.sun.webui.jsf.component.Message;
import com.sun.webui.jsf.component.MessageGroup;
import com.sun.webui.jsf.component.Page;
import com.sun.webui.jsf.component.StaticText;
import com.sun.webui.jsf.component.Table;
import com.sun.webui.jsf.component.TableColumn;
import com.sun.webui.jsf.component.TableRowGroup;
import com.sun.webui.jsf.component.TextField;
import com.sun.webui.jsf.model.SingleSelectOptionsList;
import java.math.BigDecimal;
import javax.faces.FacesException;
import javax.faces.convert.BigDecimalConverter;
import javax.faces.convert.DateTimeConverter;
import javax.faces.convert.NumberConverter;
import javax.faces.event.ValueChangeEvent;

/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 */
public class PartnerTrans extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
    private int __placeholder;

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
        statementdatesDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet)getValue("#{SessionBean1.statementdatesRowSet}"));
        partnersDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet)getValue("#{SessionBean1.partnersRowSet}"));
        partnerledgerDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet)getValue("#{SessionBean1.partnerledgerRowSet}"));
        partnertranstypeDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet)getValue("#{SessionBean1.partnertranstypeRowSet}"));
        dateTimeConverter1.setTimeZone(null);
        dateTimeConverter1.setPattern("MM/dd/yyyy");
        numberConverter1.setMinIntegerDigits(1);
        numberConverter1.setMaxIntegerDigits(40);
        numberConverter1.setMaxFractionDigits(3);
        numberConverter1.setType("currency");
        numberConverter1.setCurrencySymbol("$");
    }

    private Form form1 = new Form();

    public Form getForm1() {
        return form1;
    }

    public void setForm1(Form f) {
        this.form1 = f;
    }

    private CachedRowSetDataProvider statementdatesDataProvider = new CachedRowSetDataProvider();

    public CachedRowSetDataProvider getStatementdatesDataProvider() {
        return statementdatesDataProvider;
    }

    public void setStatementdatesDataProvider(CachedRowSetDataProvider crsdp) {
        this.statementdatesDataProvider = crsdp;
    }

    private BigDecimalConverter statementDD

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Created a custom converter that converted the java.util.date to a java.sql.date. I am going to work on adding the ability to handle different formats shortly but did this to get the application working! Code is below:

public class CustSQLDateConverter implements Converter
{
    private String dateFormat = new String();

     public void SetDateFormat (String df)
     {
         dateFormat = df;
     }


    @Override
     public Object getAsObject(FacesContext context, UIComponent component, 
            String value)
    {
        SimpleDateFormat format = new SimpleDateFormat(dateFormat);
        Date parsed = null;
        try {
            parsed = format.parse(value);

        } catch(ParseException pe)
        {
            pe.printStackTrace();
        }
        java.sql.Date sql = new java.sql.Date(parsed.getTime());  
        return (sql);

    }

    public String getAsString(FacesContext context, UIComponent component,
            Object value)
    {
        String dtstring = value.toString();
        String[] dt = dtstring.split("-");
        String fmtDate = dt[1] + "/" + dt[2] + "/" + dt[0];
        return fmtDate;
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...