kohuke 0 Newbie Poster

Hi. Me again. I was wondering how could i code my jsp page when i want the following page.

I have the main contract page where you can see the certain property that is in that contract. Contract and Property are connected by contractproperty which contains both contractID and propertyID.
I need to make form to add a new property to the contract. And i need the contractId to be automatically selected when i start to insert the new property to the contract.
It seems simple to do it with just the JSP page that access the database directly, but when i use java classes to access the database then how should i write the query to allow me to do the following. Currently when i begin to add the new contract i have to select the contract ID manually. So how can i do it automatically.(I cut out not so important parts of the code)

Well this is the form to insert the new property to the contract.

---code--
                    <h:outputText value="PropertyID:"/>
                    <h:selectOneMenu id="propertyID" value="#{contractProperty.contractProperty.propertyID}" title="PropertyID" required="true" requiredMessage="The propertyID field is required." >
                        <f:selectItems value="#{property.propertyItemsAvailableSelectOne}"/>
                    </h:selectOneMenu>
                    <h:outputText value="ContractID:"/>
                    <h:selectOneMenu id="contractID" value="#{contractProperty.contractProperty.contractID}" title="ContractID" required="true" requiredMessage="The contractID field is required." >
                        <f:selectItems value="#{contract.contractItemsAvailableSelectOne}"/>
                    </h:selectOneMenu>
                    
                <br />
                <h:commandLink action="#{contractProperty.create}" value="Create"/>
                <br />
--code---

This is the contractproperty class file.

@Entity
@Table(name = "contract_property", catalog = "varad1", schema = "")
@NamedQueries({@NamedQuery(name = "ContractProperty.findAll", 
    query = "SELECT c FROM ContractProperty c"),
@NamedQuery(name = "ContractProperty.findByContractpropertyID",
    query = "SELECT c FROM ContractProperty c WHERE c.contractpropertyID" +
    " = :contractpropertyID"),
@NamedQuery(name = "ContractProperty.findByCreated", 
    query = "SELECT c FROM ContractProperty c WHERE c.created = :created"),
@NamedQuery(name = "ContractProperty.findByUpdated",
    query = "SELECT c FROM ContractProperty c WHERE c.updated = :updated")})

public class ContractProperty implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "contract_property_ID")
    private Integer contractpropertyID;
    @Basic(optional = false)
    @Column(name = "created")
    @Temporal(TemporalType.TIMESTAMP)
    private Date created;
    @Column(name = "updated")
    @Temporal(TemporalType.DATE)
    private Date updated;
    @JoinColumn(name = "property_ID", referencedColumnName = "property_ID")
    @ManyToOne(optional = false)
    private Property propertyID;
    @JoinColumn(name = "contract_ID", referencedColumnName = "contract_ID")
    @ManyToOne(optional = false)
    private Contract contractID;
    @JoinColumn(name = "created_by", referencedColumnName = "employee_ID")
    @ManyToOne(optional = false)
    private Employee createdBy;
    @JoinColumn(name = "updated_by", referencedColumnName = "employee_ID")
    @ManyToOne
    private Employee updatedBy;

    public ContractProperty() {
    }

    public ContractProperty(Integer contractpropertyID) {
        this.contractpropertyID = contractpropertyID;
    }

    public ContractProperty(Integer contractpropertyID, Date created) {
        this.contractpropertyID = contractpropertyID;
        this.created = created;
    }

    public Integer getContractpropertyID() {
        return contractpropertyID;
    }

    public void setContractpropertyID(Integer contractpropertyID) {
        this.contractpropertyID = contractpropertyID;
    }

    -more stuff-

    public Property getPropertyID() {
        return propertyID;
    }

    public void setPropertyID(Property propertyID) {
        this.propertyID = propertyID;
    }

    public Contract getContractID() {
        return contractID;
    }

    public void setContractID(Contract contractID) {
        this.contractID = contractID;
    }

    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (contractpropertyID != null ? contractpropertyID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ContractProperty)) {
            return false;
        }
        ContractProperty other = (ContractProperty) object;
        if ((this.contractpropertyID == null && other.contractpropertyID != null)
                || (this.contractpropertyID != null &&
                !this.contractpropertyID.equals(other.contractpropertyID))) {
            return false;
        }
        return true;
    }


}

contract view jsp

---some other stuff----
<h:outputText value="ContractPropertyCollection:" />
                    <h:panelGroup>
                        <h:outputText rendered="#{empty contract.contract.contractPropertyCollection}" value="(No Items)"/>
                        <h:dataTable value="#{contract.contract.contractPropertyCollection}" var="item" 
                                     border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px" 
                                     rendered="#{not empty contract.contract.contractPropertyCollection}">
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="ContractpropertyID"/>
                                </f:facet>
                                <h:outputText value=" #{item.contractpropertyID}"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="PropertyID"/>
                                </f:facet>
                                <h:outputText value=" #{item.propertyID}"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="ContractID"/>
                                </f:facet>
                                <h:outputText value=" #{item.contractID}"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText escape="false" value="&nbsp;"/>
                                </f:facet>
                                <h:commandLink value="Show" action="#{contractProperty.detailSetup}">
                                    <f:param name="jsfcrud.currentContract" value="#{jsfcrud_class['jpa.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][contract.contract][contract.converter].jsfcrud_invoke}"/>
                                    <f:param name="jsfcrud.currentContractProperty" value="#{jsfcrud_class['jpa.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][item][contractProperty.converter].jsfcrud_invoke}"/>
                                    <f:param name="jsfcrud.relatedController" value="contract" />
                                    <f:param name="jsfcrud.relatedControllerType" value="jpa.ContractController" />
                                </h:commandLink>
                                <h:outputText value=" "/>
                                <h:commandLink value="Edit" action="#{contractProperty.editSetup}">
                                    <f:param name="jsfcrud.currentContract" value="#{jsfcrud_class['jpa.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][contract.contract][contract.converter].jsfcrud_invoke}"/>
                                    <f:param name="jsfcrud.currentContractProperty" value="#{jsfcrud_class['jpa.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][item][contractProperty.converter].jsfcrud_invoke}"/>
                                    <f:param name="jsfcrud.relatedController" value="contract" />
                                    <f:param name="jsfcrud.relatedControllerType" value="jpa.ContractController" />
                                </h:commandLink>
                                <h:outputText value=" "/>
                                <h:commandLink value="Destroy" action="#{contractProperty.destroy}">
                                    <f:param name="jsfcrud.currentContract" value="#{jsfcrud_class['jpa.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][contract.contract][contract.converter].jsfcrud_invoke}"/>
                                    <f:param name="jsfcrud.currentContractProperty" value="#{jsfcrud_class['jpa.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][item][contractProperty.converter].jsfcrud_invoke}"/>
                                    <f:param name="jsfcrud.relatedController" value="contract" />
                                    <f:param name="jsfcrud.relatedControllerType" value="jpa.ContractController" />
                                </h:commandLink>
                            </h:column>
                        </h:dataTable>
                    </h:panelGroup>

How should i edit the class/new contractproperty.jsp to make the webapp to as i want?
Since the code is netbeans generated i'm little behind of understanding it, but i'm doing my best to chew trought it...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.