Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正在从控制器更新bean值,单击按钮可多次插入_Java_Jsf_Jakarta Ee_Jpa - Fatal编程技术网

Java 正在从控制器更新bean值,单击按钮可多次插入

Java 正在从控制器更新bean值,单击按钮可多次插入,java,jsf,jakarta-ee,jpa,Java,Jsf,Jakarta Ee,Jpa,我不熟悉JSFJPARest,我想知道如何从控制器bean在bean中设置值 假设用户注册后,我想将这些值连同我在controllerbean中生成的日期一起插入数据库。现在我如何在POJO中设置这些值 register.xhtml <h:form id="registerForm"> <table> <tr> <td colspan="3" id="regi

我不熟悉JSFJPARest,我想知道如何从控制器bean在bean中设置值

假设用户注册后,我想将这些值连同我在controllerbean中生成的日期一起插入数据库。现在我如何在POJO中设置这些值

register.xhtml

<h:form id="registerForm">
            <table>
                <tr>
                    <td colspan="3" id="register">
                        <h2 style="border-bottom: 1px solid #CCCCCC;">Customer
                            Information</h2>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="name" value="Name:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputText id="name" size="20" required="true" requiredMessage="Please enter your name" value="#{registerController.selected.contactName}">
                                    <f:validateLength maximum="50"></f:validateLength>
                                </h:inputText>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="company" value="Company:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputText id="company" size="20" required="true" requiredMessage="Please enter your company" value="#{registerController.selected.company}">
                                    <f:validateLength maximum="50"></f:validateLength>
                                </h:inputText>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="designation" value="Designation:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputText id="designation"  size="20" required="true" requiredMessage="Please enter your designation" value="#{registerController.selected.designation}">
                                    <f:validateLength maximum="50"></f:validateLength>
                                </h:inputText>

                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="email" value="Email Id:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputText id="email"  size="20" required="true" requiredMessage="Please enter your email,eg:yourid@domain.com" value="#{registerController.selected.primaryEmailId}" title="eg:www.domain.com OR http://127.0.0.1/domain">
                                    <f:validateLength maximum="70"></f:validateLength>
                                </h:inputText>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="phone" value="Contact No:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputText id="phone" size="20" required="true" requiredMessage="Please enter your contact number" value="#{registerController.selected.contactNo}" title="eg:+919999999999">
                                    <f:validateLength minimum="13" maximum="25"></f:validateLength>
                                </h:inputText>
                            </td>
                        </tr>

                    </td>

                </tr>
                <tr>
                    <td colspan="4" id="loginInfo">
                        <h2 style="border-bottom: 1px solid #CCCCCC;">Login Information</h2>
                        <tr>
                            <td class="label"> 
                                <h:outputLabel for="email" value="Login Email:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputText id="email"  size="20" maxlength="70" required="true" requiredMessage="Please enter your login email id,eg:yourid@domain.com" value="#{loginController.selected.clientId}">
                                    <f:validateLength maximum="70"></f:validateLength>
                                </h:inputText>

                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="password" value="Password:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputSecret id="password"  size="20" maxlength="70" required="true" requiredMessage="Please enter your desired password(minimun 6 characters)" value="#{loginController.selected.password}">
                                    <f:validateLength minimum="6" maximum="50"></f:validateLength>
                                </h:inputSecret>

                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="confirm_password" value="Confirm Password:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputSecret id="confirm_password" size="20" required="true" requiredMessage="Please confirm your password">
                                    <f:validateLength minimum="6" maximum="50"></f:validateLength>
                                </h:inputSecret>
                            </td>
                        </tr>
                    </td>
                    <tr>
                        <td>
                            <h:commandButton value="Sign Up" action="">
                            </h:commandButton>
                        </td>
                    </tr>
                </tr>
                </table>
注册bean

    public String getContactName() {
        return contactName;
    }

    public void setContactName(String ContactName) {
        this.contactName = contactName;
    }

    public String getCompany() {
        System.out.println("get....." + company);
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
        System.out.println("set....." + company);
    }

    public String getDesignation() {
        System.out.println("get....." + designation);
        return designation;
    }

    public void setDesignation(String designation) {
        this.designation = designation;
        System.out.println("set....." + primaryDesignation);
    }

    public String getContactNo() {
        return contactNo;
    }

    public void setContactNo(String contactNo) {
        this.contactNo = contactNo;;
    }

    public String getEmailId() {
        return emailId;
    }

    public void setEmailId(String emailId) {
        this.emailId = emailId;
    }

    public String getActiveFlag() {
        return activeFlag;
    }

    public void setActiveFlag(String activeFlag) {
        this.activeFlag = activeFlag;
    }

    public String getCreatedBy() {
        System.out.println("get create name....." + createdBy);
        createdBy=getPrimaryContactName();
        return createdBy;
    }

    public void setCreatedBy(String primaryContactName) {
        this.createdBy = primaryContactName;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
        System.out.println("set....." + createdOn);
    }
    public String getLastUpdatedBy() {
        return lastUpdatedBy;
    }

    public void setLastUpdatedBy(String primaryContactName) {
        this.lastUpdatedBy = primaryContactName;
    }
    public Date getLastUpdatedOn() {
        return lastUpdatedOn;
    }

   public void setLastUpdatedOn(Date lastUpdatedOn) {
       this.lastUpdatedOn = lastUpdatedOn;
    }
我有两个控制器registerController和loginController,其中我有业务逻辑

@ManagedBean(name = "registerController")
@SessionScoped
    public String prepareCreate() {
    System.out.println("Inside create");
    current = new Register();
    System.out.println("Inside create current");
    selectedItemIndex = -1;
    return "Signup Success";
}

public String create() {
    try {
        System.out.println("I am inside create");
        getFacade().create(current);
        JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("RegisterCreated"));
        return prepareCreate();
    } catch (Exception e) {
        System.out.println("I am here inside create exception");
        e.printStackTrace();
        JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
        return null;
    }
}

public Date generateCurrentTime()
{
    // get current system time yyyy/MMM/dd HH:mm:ss
    Calendar currentDate = Calendar.getInstance();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    String dateNow = formatter.format(currentDate.getTime());
            Date convertedDate=null;
            try
            {
            convertedDate=formatter.parse(dateNow);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            System.out.println("date now is:"+dateNow);
            return convertedDate;
}
类似地,loginController也包含相同的代码。 如何在pojo中为createdOn和lastUpdatedOn feilds设置convertedDate属性

我使用了@ManagedBeanProperty,但它无法设置值

@ManagedBeanProperty(value=#{registerController.getgenerateCurrentTime})
  @Column(name = "created_on")
   @Temporal(TemporalType.DATE)
   private Date createdOn;


  @ManagedBeanProperty(value=#{registerController.getgenerateCurrentTime})
  @Column(name = "created_on")
   @Temporal(TemporalType.DATE)
   private Date lastUpdatedOn;
请指出我的错误。我使用了@sessionscoped

正如你所看到的,我有两个表格,它们相互依赖。当用户单击register按钮时,我如何将它们插入到数据库中…我应该首先在按钮上传递控件,然后单击controller,比如setupController,然后调用register and login controller吗

谢谢:)


表单的提交是否会导致在backbean中存储字段的值(如果没有使用ajax)

在命令按钮中提供一个action,如
action=“#{setupController.create}”
将导致在将字段分配给bean后提交表单时调用该方法
create

你也可以以行动的形式提供它


参考

正如其他朋友所说,您需要调用一个操作来设置支持bean上的值……您可以创建一个由按钮操作调用的方法,在该方法中,您可以调用您的服务将数据存储在数据库中。干杯

您是否提供了的操作方法?我在问是否应该说action=“#{setupController.create}”,或者是否有其他方法来执行此操作。我正在使用value=“#{registerController.selected.contactName}”将值存储在后台bean中.既然我有两个控制器,我应该再创建一个控制器来传递控制器,在该控制器中我调用registerController和loginController的创建方法…同样对于每个用户,我要添加createdOn feild,它存储逻辑在控制器中的日期。我如何在我的back bean中更新这个值??值仅在提交表单时存储在backbean中。不仅通过将其作为value=“#{registerController.selected.contactName}”提供或者你需要提供这意味着当一个用户注册时,你需要两个操作,首先你要调用createdon,然后再创建?我明白了…我所困惑的是如何在一次单击按钮时调用两个控制器??
@ManagedBeanProperty(value=#{registerController.getgenerateCurrentTime})
  @Column(name = "created_on")
   @Temporal(TemporalType.DATE)
   private Date createdOn;


  @ManagedBeanProperty(value=#{registerController.getgenerateCurrentTime})
  @Column(name = "created_on")
   @Temporal(TemporalType.DATE)
   private Date lastUpdatedOn;
<h:commandButton value="Sign Up" action="">