为什么 JSF + Tomahawk App 生成 MYSQL 数据库中所有空字段的记录

发布于 2024-11-07 22:08:15 字数 4382 浏览 3 评论 0原文

以下内容有效,但是当单击创建按钮时,它会提交一条包含所有空字段的记录,

<f:view>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>New Movie</title>
        <link rel="stylesheet" type="text/css" href="/diamondfilms.com.ar/faces/jsfcrud.css" />
    </head>
    <body>
    <h:panelGroup id="messagePanel" layout="block">
        <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
    </h:panelGroup>
    <h1>New Movie</h1>
            <h:form>
        <h:inputHidden id="validateCreateField" validator="#{movie.validateCreate}" value="value"/>
        <h:panelGrid columns="2">
            <h:outputText value="Name:"/>
            <h:inputText id="name" value="#{movie.movie.name}" title="Name" />
            <h:outputText value="Sinopsis:"/>
            <h:inputText id="sinopsis" value="#{movie.movie.sinopsis}" title="Sinopsis" />
            <h:outputText value="Cast:"/>
            <h:inputText id="cast" value="#{movie.movie.cast}" title="Cast" />
            <h:outputText value="Trailer:"/>
            <h:inputText id="trailer" value="#{movie.movie.trailer}" title="Trailer" />
            <h:outputText value="Release:"/>
            <h:selectOneRadio id="release" value="#{movie.movie.release}" title="Release">
                <f:selectItem itemLabel="YES" itemValue="S" />
                <f:selectItem itemLabel="NO" itemValue="N" />
            </h:selectOneRadio>
            <h:outputText value="Facebook Button:"/>
            <h:inputText id="imagen6" value="#{movie.movie.facebookButton}" title="Image6" />       
         <h:form id="calendarForm2">
            <h:outputLabel for="releaseDate" value="Date (MM/dd/yyyy HH:mm:ss): "/>
            <t:inputCalendar id="releaseDate" monthYearRowClass="yearMonthHeader" weekRowClass="weekHeader" popupButtonStyleClass="standard_bold"
                currentDayCellClass="currentDayCell" value="#{movie.movie.releaseDate}" renderAsPopup="true"
                popupTodayString="Hoy :"
                popupDateFormat="MM/dd/yyyy" popupWeekString="Semana :"
                helpText="MM/DD/YYYY"
                forceId="true">
              <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
            </t:inputCalendar>
         </h:form>
      </h:panelGrid>
     </h:form>                
            <h:form id="uploadForm1" enctype="multipart/form-data" >
                <h:outputText value="Image1:"/>
                <t:inputFileUpload id="file" value="#{movie.upLoad.upFile}" required="true" />
                <h:commandButton value="Upload" action="#{movie.upLoadFile}" />
           </h:form>
        <h:form>
        <br />
        <h:commandLink action="#{movie.create}" value="Create"/>
        <br />
        <br />
        <h:commandLink action="#{movie.listSetup}" value="Show All Movie Items" immediate="true"/>
        <br />
        <br />
        <h:commandLink value="Index" action="welcome" immediate="true" />
    </h:form>
    </body>
</html>

其中:

private MovieFacade jpaController = null;

@Resource
private UserTransaction utx = null;

    public String create() {
    try {
        utx.begin();
    } catch (Exception ex) {
    }
    try {
        Exception transactionException = null;
        jpaController.create(pelicula);
        try {
            utx.commit();
        } catch (javax.transaction.RollbackException ex) {
            transactionException = ex;
        } catch (Exception ex) {
        }
        if (transactionException == null) {
            JsfUtil.addSuccessMessage("Movie was successfully created.");
        } else {
            JsfUtil.ensureAddErrorMessage(transactionException, "A persistence error occurred.");
        }
    } catch (Exception e) {
        try {
            utx.rollback();
        } catch (Exception ex) {
        }
        JsfUtil.ensureAddErrorMessage(e, "A persistence error occurred.");
        return null;
    }
    return listSetup();
}

它甚至会验证 非常感谢!!

The following works but when create button is hit is clicked it commits a record with all null filds

<f:view>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>New Movie</title>
        <link rel="stylesheet" type="text/css" href="/diamondfilms.com.ar/faces/jsfcrud.css" />
    </head>
    <body>
    <h:panelGroup id="messagePanel" layout="block">
        <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
    </h:panelGroup>
    <h1>New Movie</h1>
            <h:form>
        <h:inputHidden id="validateCreateField" validator="#{movie.validateCreate}" value="value"/>
        <h:panelGrid columns="2">
            <h:outputText value="Name:"/>
            <h:inputText id="name" value="#{movie.movie.name}" title="Name" />
            <h:outputText value="Sinopsis:"/>
            <h:inputText id="sinopsis" value="#{movie.movie.sinopsis}" title="Sinopsis" />
            <h:outputText value="Cast:"/>
            <h:inputText id="cast" value="#{movie.movie.cast}" title="Cast" />
            <h:outputText value="Trailer:"/>
            <h:inputText id="trailer" value="#{movie.movie.trailer}" title="Trailer" />
            <h:outputText value="Release:"/>
            <h:selectOneRadio id="release" value="#{movie.movie.release}" title="Release">
                <f:selectItem itemLabel="YES" itemValue="S" />
                <f:selectItem itemLabel="NO" itemValue="N" />
            </h:selectOneRadio>
            <h:outputText value="Facebook Button:"/>
            <h:inputText id="imagen6" value="#{movie.movie.facebookButton}" title="Image6" />       
         <h:form id="calendarForm2">
            <h:outputLabel for="releaseDate" value="Date (MM/dd/yyyy HH:mm:ss): "/>
            <t:inputCalendar id="releaseDate" monthYearRowClass="yearMonthHeader" weekRowClass="weekHeader" popupButtonStyleClass="standard_bold"
                currentDayCellClass="currentDayCell" value="#{movie.movie.releaseDate}" renderAsPopup="true"
                popupTodayString="Hoy :"
                popupDateFormat="MM/dd/yyyy" popupWeekString="Semana :"
                helpText="MM/DD/YYYY"
                forceId="true">
              <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
            </t:inputCalendar>
         </h:form>
      </h:panelGrid>
     </h:form>                
            <h:form id="uploadForm1" enctype="multipart/form-data" >
                <h:outputText value="Image1:"/>
                <t:inputFileUpload id="file" value="#{movie.upLoad.upFile}" required="true" />
                <h:commandButton value="Upload" action="#{movie.upLoadFile}" />
           </h:form>
        <h:form>
        <br />
        <h:commandLink action="#{movie.create}" value="Create"/>
        <br />
        <br />
        <h:commandLink action="#{movie.listSetup}" value="Show All Movie Items" immediate="true"/>
        <br />
        <br />
        <h:commandLink value="Index" action="welcome" immediate="true" />
    </h:form>
    </body>
</html>

where:

private MovieFacade jpaController = null;

@Resource
private UserTransaction utx = null;

    public String create() {
    try {
        utx.begin();
    } catch (Exception ex) {
    }
    try {
        Exception transactionException = null;
        jpaController.create(pelicula);
        try {
            utx.commit();
        } catch (javax.transaction.RollbackException ex) {
            transactionException = ex;
        } catch (Exception ex) {
        }
        if (transactionException == null) {
            JsfUtil.addSuccessMessage("Movie was successfully created.");
        } else {
            JsfUtil.ensureAddErrorMessage(transactionException, "A persistence error occurred.");
        }
    } catch (Exception e) {
        try {
            utx.rollback();
        } catch (Exception ex) {
        }
        JsfUtil.ensureAddErrorMessage(e, "A persistence error occurred.");
        return null;
    }
    return listSetup();
}

It even validates
Thank you very much!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪我们做朋友吧 2024-11-14 22:08:15

您的创建按钮与输入值的形式不同。您需要以与命令链接/按钮相同的形式输入感兴趣的输入。

Your create button is not in the same form as the input values. You need to put the input of interest in the same form as the command link/button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文