JSF JDBC primefaces数据表编辑无效

时间:2013-05-24 12:27:16

标签: jsf jdbc primefaces datatable

EditPage问题: 我正在使用除主键,外键属性之外的值填充编辑页面。并且未设置SelectOneMenu值。 屏幕上有大约30个字段可供查看和编辑。

我想显示两个表中的字段i)StudyMaster和ii)在primefaces dataTable中的赞助商,并对其执行创建,读取,更新和删除操作。创建和读取操作正在运行。单击编辑不会使用dataTable的所选行的所有属性填充编辑页面。

如何填充编辑页面中的选定行?有人会帮忙吗? 我想在不使用JPA的情况下开发应用程序并在Tomcat中部署。

以下是研究和赞助者表的结构:

  StudyMaster table structure:
    StudyId int primary key auto_increment,
    StudyName varchar(30) unique not null,
    SponsorId int not null foreign key to Sponsors table. 


  Sponsors table structure:
    SponsorId: int primary key auto_increment,
    SponsorName: varchar(30) unique not null,
    Address: varchar(255)

StudyMaster.xhtml(dataTable中的命令按钮)

点击数据表中的以下按钮导航到编辑页面

  <p:column style="text-align: center;">
                    <p:commandButton id="btneditstudy" value="Edit" action="EditStudy1"
                     title="Edit">
                        <f:setPropertyActionListener value="#{item}" target="#
                            {studymasterdao.selectedStudy}"/>
                    </p:commandButton>                        
  </p:column>

EditStudy1.xhtml:

<ui:composition template="/SRAtemplate.xhtml">
        <ui:define name="head">
            <title> Edit StudyMaster</title>
        </ui:define>
        <ui:define name="heading">
            Edit StudyMaster Details
        </ui:define>
        <ui:define name="body">
            <br/>
            <br/> 

        <h:form id="editstudyform">
            <h:messages id="editstudymessages" errorStyle="color:red;font-family:Myriad Pro;font-weight:bold;font-size:16;"
                        infoStyle="color:white;font-family:Myriad Pro;font-weight:bold;font-size:16;"/>
            <p:growl id="msg" autoUpdate="true"/>

            <p:panelGrid columns="2" rendered="#{not empty studymasterdao.selectedStudy}">

                <f:facet name="header">
                    Edit Study
                </f:facet>

                <h:outputLabel for="StudyName" value="StudyName*:"/>
                <p:inputText id="StudyName" value="#{studymasterdao.selectedStudy.studyName}" maxlength="20" 
                             required="true" requiredMessage="StudyName must be entered"                        
                             validatorMessage="StudyName must be an alphanumeric value">                        
                </p:inputText>

                <h:outputLabel for="Sponsor" value="Sponsor*:"/>
                    <p:selectOneMenu id="Sponsor" value="#
 {studymasterdao.selectedStudy.sponsorId}" effect="fade" effectSpeed="0" 
                                     required="true" requiredMessage="Sponsor must be 
 selected">  
                        <f:selectItems value="#{studymasterdao.getSponsorsList()}" 
 var="sponsor"
                                       itemLabel="#{sponsor.sponsorName}" itemValue="# 
 {sponsor.sponsorId}"/>
                    </p:selectOneMenu>

                <h:outputLabel for="StudyId" value="StudyId*:"/>
                <p:inputText id="StudyId" disabled="true" value="#{studymasterdao.selectedStudy.studyPhase}" />

                <p:commandButton id="btnUpdateStudy" value="Save" actionListener="#{studymasterdao.updateStudy()}"
                                 update=":editstudyform:editstudymessages" onclick="alert('primefaces button');" oncomplete="alert('primefaces button')"/>
                <h:commandButton id="jsfbtn" value="Save1" actionListener="#{studymasterdao.updateStudy()}" onclick="alert('jsf button');"/>
                <p:commandButton id="btnCancelStudy" value="Back" action="StudyMaster" title="Back to StudyMaster"/>

            </p:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>

模态课程:

public class Studymaster {
    private Integer studyId;
    private String studyName;
    private Integer sponsorId;
    private String sponsorName;
   <<rest of the attributes and corresponding getters and setters>>

JSF托管bean

package com.mek.sample.jsfcrud.dao;
import com.mek.sample.jsfcrud.model.Sponsors;
import com.mek.sample.jsfcrud.model.Studymaster;
import javax.annotation.Resource;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.primefaces.context.RequestContext;
<<various other imports>

    @ManagedBean(name = "studymasterdao")
    @SessionScoped
    public class StudymasterDao{

        private Integer studyId;
        private String studyName;
        private Integer sponsorId;
        private String sponsorName;
        private Studymaster SelectedStudy

       //add update and retrieve methods.

更新

  • 我正在学习java,java wep-app开发,我是.Net 开发商。我正在尝试开发基于JSF的示例应用程序 使用jdbc,My-SQL和Tomcat进行crud。我喜欢JSF,因为它是基于组件的 还有一些事件驱动的模型。我想实现CRUD操作 最小的java类不担心MVC2模型 时刻。请建议我用MVC1来实现这个简单的问题 模型。我知道可以开发现代webapps 使用JSF,Java / JavaEE平台的类似桌面的应用程序。

0 个答案:

没有答案