Jsp page to insert data

Thread Solved
Reply

Join Date: Sep 2007
Posts: 23
Reputation: kohuke is an unknown quantity at this point 
Solved Threads: 0
kohuke kohuke is offline Offline
Newbie Poster

Jsp page to insert data

 
0
  #1
Aug 27th, 2008
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.
  1. ---code--
  2. <h:outputText value="PropertyID:"/>
  3. <h:selectOneMenu id="propertyID" value="#{contractProperty.contractProperty.propertyID}" title="PropertyID" required="true" requiredMessage="The propertyID field is required." >
  4. <f:selectItems value="#{property.propertyItemsAvailableSelectOne}"/>
  5. </h:selectOneMenu>
  6. <h:outputText value="ContractID:"/>
  7. <h:selectOneMenu id="contractID" value="#{contractProperty.contractProperty.contractID}" title="ContractID" required="true" requiredMessage="The contractID field is required." >
  8. <f:selectItems value="#{contract.contractItemsAvailableSelectOne}"/>
  9. </h:selectOneMenu>
  10.  
  11. <br />
  12. <h:commandLink action="#{contractProperty.create}" value="Create"/>
  13. <br />
  14. --code---
This is the contractproperty class file.
  1. @Entity
  2. @Table(name = "contract_property", catalog = "varad1", schema = "")
  3. @NamedQueries({@NamedQuery(name = "ContractProperty.findAll",
  4. query = "SELECT c FROM ContractProperty c"),
  5. @NamedQuery(name = "ContractProperty.findByContractpropertyID",
  6. query = "SELECT c FROM ContractProperty c WHERE c.contractpropertyID" +
  7. " = :contractpropertyID"),
  8. @NamedQuery(name = "ContractProperty.findByCreated",
  9. query = "SELECT c FROM ContractProperty c WHERE c.created = :created"),
  10. @NamedQuery(name = "ContractProperty.findByUpdated",
  11. query = "SELECT c FROM ContractProperty c WHERE c.updated = :updated")})
  12.  
  13. public class ContractProperty implements Serializable {
  14. private static final long serialVersionUID = 1L;
  15. @Id
  16. @GeneratedValue(strategy = GenerationType.IDENTITY)
  17. @Basic(optional = false)
  18. @Column(name = "contract_property_ID")
  19. private Integer contractpropertyID;
  20. @Basic(optional = false)
  21. @Column(name = "created")
  22. @Temporal(TemporalType.TIMESTAMP)
  23. private Date created;
  24. @Column(name = "updated")
  25. @Temporal(TemporalType.DATE)
  26. private Date updated;
  27. @JoinColumn(name = "property_ID", referencedColumnName = "property_ID")
  28. @ManyToOne(optional = false)
  29. private Property propertyID;
  30. @JoinColumn(name = "contract_ID", referencedColumnName = "contract_ID")
  31. @ManyToOne(optional = false)
  32. private Contract contractID;
  33. @JoinColumn(name = "created_by", referencedColumnName = "employee_ID")
  34. @ManyToOne(optional = false)
  35. private Employee createdBy;
  36. @JoinColumn(name = "updated_by", referencedColumnName = "employee_ID")
  37. @ManyToOne
  38. private Employee updatedBy;
  39.  
  40. public ContractProperty() {
  41. }
  42.  
  43. public ContractProperty(Integer contractpropertyID) {
  44. this.contractpropertyID = contractpropertyID;
  45. }
  46.  
  47. public ContractProperty(Integer contractpropertyID, Date created) {
  48. this.contractpropertyID = contractpropertyID;
  49. this.created = created;
  50. }
  51.  
  52. public Integer getContractpropertyID() {
  53. return contractpropertyID;
  54. }
  55.  
  56. public void setContractpropertyID(Integer contractpropertyID) {
  57. this.contractpropertyID = contractpropertyID;
  58. }
  59.  
  60. -more stuff-
  61.  
  62. public Property getPropertyID() {
  63. return propertyID;
  64. }
  65.  
  66. public void setPropertyID(Property propertyID) {
  67. this.propertyID = propertyID;
  68. }
  69.  
  70. public Contract getContractID() {
  71. return contractID;
  72. }
  73.  
  74. public void setContractID(Contract contractID) {
  75. this.contractID = contractID;
  76. }
  77.  
  78.  
  79.  
  80. @Override
  81. public int hashCode() {
  82. int hash = 0;
  83. hash += (contractpropertyID != null ? contractpropertyID.hashCode() : 0);
  84. return hash;
  85. }
  86.  
  87. @Override
  88. public boolean equals(Object object) {
  89. // TODO: Warning - this method won't work in the case the id fields are not set
  90. if (!(object instanceof ContractProperty)) {
  91. return false;
  92. }
  93. ContractProperty other = (ContractProperty) object;
  94. if ((this.contractpropertyID == null && other.contractpropertyID != null)
  95. || (this.contractpropertyID != null &&
  96. !this.contractpropertyID.equals(other.contractpropertyID))) {
  97. return false;
  98. }
  99. return true;
  100. }
  101.  
  102.  
  103. }
contract view jsp
  1. ---some other stuff----
  2. <h:outputText value="ContractPropertyCollection:" />
  3. <h:panelGroup>
  4. <h:outputText rendered="#{empty contract.contract.contractPropertyCollection}" value="(No Items)"/>
  5. <h:dataTable value="#{contract.contract.contractPropertyCollection}" var="item"
  6. border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px"
  7. rendered="#{not empty contract.contract.contractPropertyCollection}">
  8. <h:column>
  9. <f:facet name="header">
  10. <h:outputText value="ContractpropertyID"/>
  11. </f:facet>
  12. <h:outputText value=" #{item.contractpropertyID}"/>
  13. </h:column>
  14. <h:column>
  15. <f:facet name="header">
  16. <h:outputText value="PropertyID"/>
  17. </f:facet>
  18. <h:outputText value=" #{item.propertyID}"/>
  19. </h:column>
  20. <h:column>
  21. <f:facet name="header">
  22. <h:outputText value="ContractID"/>
  23. </f:facet>
  24. <h:outputText value=" #{item.contractID}"/>
  25. </h:column>
  26. <h:column>
  27. <f:facet name="header">
  28. <h:outputText escape="false" value="&nbsp;"/>
  29. </f:facet>
  30. <h:commandLink value="Show" action="#{contractProperty.detailSetup}">
  31. <f:param name="jsfcrud.currentContract" value="#{jsfcrud_class['jpa.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][contract.contract][contract.converter].jsfcrud_invoke}"/>
  32. <f:param name="jsfcrud.currentContractProperty" value="#{jsfcrud_class['jpa.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][item][contractProperty.converter].jsfcrud_invoke}"/>
  33. <f:param name="jsfcrud.relatedController" value="contract" />
  34. <f:param name="jsfcrud.relatedControllerType" value="jpa.ContractController" />
  35. </h:commandLink>
  36. <h:outputText value=" "/>
  37. <h:commandLink value="Edit" action="#{contractProperty.editSetup}">
  38. <f:param name="jsfcrud.currentContract" value="#{jsfcrud_class['jpa.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][contract.contract][contract.converter].jsfcrud_invoke}"/>
  39. <f:param name="jsfcrud.currentContractProperty" value="#{jsfcrud_class['jpa.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][item][contractProperty.converter].jsfcrud_invoke}"/>
  40. <f:param name="jsfcrud.relatedController" value="contract" />
  41. <f:param name="jsfcrud.relatedControllerType" value="jpa.ContractController" />
  42. </h:commandLink>
  43. <h:outputText value=" "/>
  44. <h:commandLink value="Destroy" action="#{contractProperty.destroy}">
  45. <f:param name="jsfcrud.currentContract" value="#{jsfcrud_class['jpa.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][contract.contract][contract.converter].jsfcrud_invoke}"/>
  46. <f:param name="jsfcrud.currentContractProperty" value="#{jsfcrud_class['jpa.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][item][contractProperty.converter].jsfcrud_invoke}"/>
  47. <f:param name="jsfcrud.relatedController" value="contract" />
  48. <f:param name="jsfcrud.relatedControllerType" value="jpa.ContractController" />
  49. </h:commandLink>
  50. </h:column>
  51. </h:dataTable>
  52. </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...
Last edited by kohuke; Aug 27th, 2008 at 1:04 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC