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


This is version 13. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]


Part II: Create Weblog UI - A HowTo for creating a UI (in Struts) for managing the DAOs created in the Hibernate Relationships tutorial. I've eliminated creating managers in this tutorial for a couple reasons: 1) to reduce the amount of code and 2) to show you that you don't have to create them.

About this Tutorial

In this section, you'll create a UI that has the following features.
  • Create a Weblog
  • View Weblog and its Entries
  • Add a New Entry
  • Edit/Save an existing Entry
  • Edit a Weblog and its Users
  • Edit a User and their Weblogs

Table of Contents

  • [1] Modify userForm.jsp to allow creating/editing a weblog (many-to-many)
  • [2] Modify the UserAction to support editing a user's weblogs
  • [3] Create an EntryAction to handle CRUD-ing Entries
  • [4] Add the ability to see all Weblogs and edit them, as well as their users

Modify userForm.jsp to allow creating/editing a weblog [#1]

In order for the Struts version of AppFuse to allow editing of a Weblog's attributes from the User object, you need to modify User.java to support indexed properties. You can do this by adding indexedProperties="true" to the @struts.form tag in User.java.


* @struts.form include-all="true" extends="BaseForm" indexedProperties="true"

A weblog record has 3 fields: weblogId, blogTitle and dateCreated. The blogTitle is the only field that users should be able to edit. The rest of them can be set programmatically. Open web/pages/userForm.jsp and add the following code to the bottom of the form (between </table> and </form>.

<fieldset style="position: absolute; top: 190px; left: 520px">
    <legend style="font-weight: bold">Weblogs</legend>
    <c:forEach var="blog" items="${userForm.weblogs}" varStatus="index">
        <input type="hidden" name="weblogs[<c:out value='${index.index}'/>].weblogId" value="<c:out value='${blog.weblogId}'/>"/>
        <input type="hidden" name="weblogs[<c:out value='${index.index}'/>].username" value="<c:out value='${blog.username}'/>"/>
        <input type="hidden" name="weblogs[<c:out value='${index.index}'/>].dateCreated" value="<fmt:formatDate value='${blog.dateCreated}' pattern="MM/dd/yyyy"/>"/>
        <input type="text" name="weblogs[<c:out value='${index.index}'/>].blogTitle" size="40" value="<c:out value='${blog.blogTitle}'/>"/><br/>
    </c:forEach>

</fieldset>

Run "ant clean deploy", go to http://localhost:8080/appfuse/editProfile.html and login as "tomcat/tomcat". You should see a screenshot like the one below.

UserWithWeblog.png

If you try to save at this point, you'll probably get the following error:

Warning The process did not complete. Details should follow.
Warning IllegalArgumentException occurred calling getter of org.appfuse.model.Weblog.weblogId
Warning object is not an instance of declaring class

Modify the UserAction to support editing a user's weblogs [#2]

Create an EntryAction to handle CRUD-ing Entries [#3]

Add the ability to see all Weblogs and edit them, as well as their users [#4]


Attachments:
WeblogWithUsers.png Info on WeblogWithUsers.png 12462 bytes
WeblogAction.java Info on WeblogAction.java 5803 bytes
weblogList.jsp Info on weblogList.jsp 1483 bytes
WeblogWithEntry.png Info on WeblogWithEntry.png 14386 bytes
WeblogCRUD.png Info on WeblogCRUD.png 38859 bytes
UserWithWeblog.png Info on UserWithWeblog.png 10692 bytes
weblogForm.jsp Info on weblogForm.jsp 1782 bytes
WeblogWithCategory.png Info on WeblogWithCategory.png 15572 bytes


Go to top   More info...   Attach file...
This particular version was published on 06-Nov-2006 13:52:47 MST by MattRaible.