Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
HibernateRelationshi...




JSPWiki v2.2.33

[RSS]


Hide Menu

HibernateRelationshipsUI


Difference between version 47 and version 46:

At line 403 added 2 lines.
This covers most of the things you need to know for using Hibernate's relationships and modifying child elements. However, it doesn't cover adding or deleting child elements.
At line 407 added 4 lines.
There are many different ways to add and delete child elements from a form. This section is a work in progress and shows a quick-n-dirty (complete with bugs!) way of doing this.
In __weblogForm.jsp__, add a "Delete" button just after the "Posted at" information:
At line 407 changed 4 lines.
public void setLookupDAO(LookupDAO dao) {
super.dao = dao;
this.dao = dao;
}
Posted at: <nested:write property="timeCreated"/></span>
<input type="button" class="button" name="delete" style="font-size: 11px"
onclick="parentNode.parentNode.removeChild($('entry<%=index%>'))" value="Delete"/>
At line 413 changed 2 lines.
# Add html:select tag to weblogForm.jsp, include prettying up - show screenshot
# POSSIBLITY: Add "title" to Entry.java
Run __ant deploy-web__, refresh your browser - and you should be able to delete the entry. Click "Save" after clicking "Delete" to complete the process. While this works, it's not the ideal solution. Since it just removes the entry (and it's form elements) from the form, it doesn't re-adjust the index numbers on other entries. This means that deleting will only work for the last entry. In addition, the entry won't be deleted from the "entry" table (try ''select * from entry''). Both of these issues could likely be fixed if you linked the "Delete" button to an action (or Ajax) that deleted the entry from the database.
At line 420 added 1 line.
To add a new entry, there are also a number of things you can do. The simplest one I've found is to duplicate an existing set of entry fields, re-index the input element names and clear the values. To do this: add the following after the ending &lt;/nested:iterate&gt; for the "entries":
At line 417 changed 1 line.
!!Add the ability to delete an entry
[{Java2HtmlPlugin
At line 419 changed 1 line.
# Wrap nested:iterate with div id
<hr />
<input type="button" class="button" onclick="toggleDisplay('newentry');
if ($('newentry').style.display == '') {
var entries = parentNode.getElementsByTagName('div');
$('newentry').innerHTML = entries[entries.length-2].innerHTML;
// reset all fields to blank, and change their names
var inputs = $('newentry').getElementsByTagName('input');
var index = inputs[0].name.substring(inputs[0].name.indexOf('[')+1, inputs[0].name.indexOf(']'));
var next = parseInt(index) + 1;
for (i=0; i < inputs.length; i++) {
inputs[i].name = inputs[i].name.replace(index, next);
if (inputs[i].name == 'delete') {
inputs[i].onclick =
function() { $('newentry').innerHTML = ''; $('newentry').style.display='none'; };
} else if (inputs[i].name.indexOf('weblogId') == -1) {
inputs[i].value = '';
}
}
// reset any textareas
var boxes = $('newentry').getElementsByTagName('textarea');
for (i=0; i < boxes.length; i++) {
boxes[i].name = boxes[i].name.replace(index, next);
boxes[i].value = '';
}
// reset any selects
var dropdowns = $('newentry').getElementsByTagName('select');
for (i=0; i < dropdowns.length; i++) {
dropdowns[i].name = dropdowns[i].name.replace(index, next);
dropdowns[i].selectedIndex = 0;
}
boxes[0].focus();
this.value = this.value.replace('Add', 'Cancel');
} else {
this.value = this.value.replace('Cancel', 'Add');
}" value="Add New Entry"/>
<div id="newentry" style="display: none"></div>
}]
At line 421 changed 21 lines.
<nested:iterate property="entries" id="entry" indexId="index">
<div id="entry<%=index%>">
<nested:hidden property="entryId"/>
<nested:hidden property="weblogId"/>
<!--<nested:hidden property="timeCreated"/> -->
<nested:textarea property="text" style="width: 400px; height: 100px"/>
<br />
<span style="color: #333; font-size: 11px; margin: 0 5px">
Category:
<nested:select property="categoryId" style="color: #333; font-size: 11px; margin: 2px 10px 0 0">
<html:options collection="availableCategories" property="categoryId" labelProperty="name"/>
</nested:select>
Posted at: <nested:write property="timeCreated"/></span>
<input type="submit" class="button" style="font-size: 11px"
onclick="parentNode.parentNode.removeChild($('entry<%=index%>'))" value="Delete"/>
</div>
</nested:iterate>
# This will delete, but only the first one - might need some more JavaScript magic to shuffle the numbers
# Delete only works if last entry is deleted
# Add only works if there's already an existing one to replicate.

Back to HibernateRelationshipsUI, or to the Page History.