Hi,

Jesse Kuhnert wrote:
It's up to you, but when you use something like Ajax"Direct"Link it will invoke your method directly, bypassing most of the standard rendering model.

If you have a blogPost object bound to a property which is persisted to your session then it should be available to you in your method. Are you sure this blogPost object has been set on your property at least once with a non null object?

Thanks for the response. I'll try to post more code here & hopefully make more sense.

The actual problem I am working with is part of a contact management component, so I'll use that example here (which isn't much more complex than the blog example). In this scenario I have a base Contact class and ContactField classes which can be added to the Contact.

To start with, I am coming to the ContactEdit page from a ContactList page. ContactList uses a listener (doAddContact/doEditContact) method and @InjectPage to forward over to the ContactEdit page. This works fine, so I won't post that code. In the doAddContact() listener, I create a new Contact object, save it to the database, and then set that new Contact object in the ContactEdit page (by calling setContact()). Again, this works as expected -- I have a new empty (but has an ID) Contact object in my ContactEdit page.

Here is my complete ContactEdit class:

public abstract class ContactEdit extends MyBasePage {
        
    public void doAddField(IRequestCycle cycle)
    {
        ContactField cf = new ContactField();
        cf.setContact(getContact());
        // THIS IS ALWAYS SHOWING NULL:
        log.info("Current contact: " + getContact());
        getPersistenceService().save(cf);
        setEditing(cf.getId(), true);
    }

    public void doStoreField(IRequestCycle cycle)
    {
        getPersistenceService().save(getCurrField());
        setEditing(getCurrField().getId(), false);
    }

    private void setEditing(Integer contactFieldId, boolean edit)
    {
        Set editIds = getFieldEditorIds();
        if (edit) {
            editIds.add(contactFieldId);
        } else {
            editIds.remove(contactFieldId);
        }
    }

    @Persist
    public abstract Contact getContact();       
    public abstract void setContact(Contact c);
        
    @Persist
    @InitialValue("ognl:new java.util.HashSet()")
    public abstract Set getFieldEditorIds();
    public abstract void setFieldEditorIds(Set edit);

    public abstract ContactField getCurrField();
    public abstract void setCurrField(ContactField cf);

}

Note the comment in doAddField(); this is the problem I'm having. The getContact() method is returning NULL when I use AjaxDirectLink to invoke doAddField() so I cannot associate the new ContactField objects with the page's Contact object.

Here is my ContactEdit.html (note, my ContactEdit.page is empty), with the input form removed (since I'm stuck at the stage before that when the new ContactField object is being created in the java page class).

<form jwcid="@Form">
<table>
<tr>
  <th>ID</th>
  <td>
    <span jwcid="@Insert" value="ognl:contact.id">0</span>
  </td>
</tr>
<tr>
  <th>Name</th>
  <td>
    <input jwcid="[EMAIL PROTECTED]" value="ognl:contact.name"/>
  </td>
</tr>
<tr>
  <th>Company</th>
  <td>
    <input jwcid="[EMAIL PROTECTED]" value="ognl:contact.company"/>
  </td>
</tr>
<tr>
  <td>Fields</td>
    <td jwcid="@Any" id="fields">
<span jwcid="@Foreach" source="ognl:contact.fields" value="currField" index="currFieldIndex"> <div jwcid="@Any" class="credential" id="ognl:'field_' + currField.id" style="width:400px;">
                                
<span jwcid="@If" condition="ognl:not fieldEditorIds.contains(currFieldIndex)">
                                
<span jwcid="@Insert" value="currField.label">Label</span>: <span jwcid="@Insert" value="currField.value">Field Value</span>
                                
          </span>         

          <!-- removed the input form for brevity -->

       </span> <!-- foreach -->

<a jwcid="@tacos:AjaxDirectLink" listener="listener:doAddField" updateComponents="ognl:{'fields'}">Add Field</a>
                        
  </td>
</tr>
</table>

So, the "contact" field (i.e. getContact()) is available to my .html template (e.g. I see the ID value correctly incrementing), but when I invoke the doAddField() method it seems to be back to NULL.

Thanks for any help.  I'm sure the problem is an obvious one.

Thanks,
Hans

On 4/17/06, *Hans L* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Hi,

    I'm new to Tacos (and Tapestry) and I'm trying to make some forms for
    adding/editing inter-related objects.  What I'm trying to do is probably
    very simple, but I'm missing something to get it all working.

    Here's a simplified example: I have a BlogPost and BlogPostImage classes
    and I want to create a single form that will allow me to specify the
    fields of the BlogPost and add any number of BlogPostImage objects to
    that BlogPost.

    I was able to take the AjaxForm examples that use "notes" and get
    something like that to work for adding/editing my BlogPostImage objects,
    but I can't seem to figure the "right" way to associate those
    BlogPostImage objects with my BlogPost.

    I have:

    <property name="blogPost" persist="session"/>

    in my .page file.

    In my .html template file I have something like this for adding new
    (empty) BlogPostImage object:

    <a jwcid="@tacos:AjaxDirectLink" listener="listener:doAddImage"
    updateComponents="ognl:{'images'}">Add Image</a>

    The problem is that in the doAddImage() method, the getBlogPost()
    always
    returns null.  So, I guess my question is: How do I make that blogPost
    available when I invoke the AjaxDirectLink?  I thought that this would
    happen automatically since it was set to persist.  Do I have to pass it
    as a parameter to the doAddImage() listener method?  Hopefully not ...

    I hope my question makes some sense.  Thanks in advance for any tips.

    Hans


    -------------------------------------------------------
    This SF.Net email is sponsored by xPML, a groundbreaking scripting
    language
    that extends applications into web and mobile media. Attend the live
    webcast
    and join the prime developer group breaking into this new coding
    territory!
    http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
    <http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642>
    _______________________________________________
    Tacos-devel mailing list
    [email protected]
    <mailto:[email protected]>
    https://lists.sourceforge.net/lists/listinfo/tacos-devel
    <https://lists.sourceforge.net/lists/listinfo/tacos-devel>




--
Jesse Kuhnert
Tacos/Tapestry, team member/developer

Open source based consulting work centered around dojo/tapestry/tacos/hivemind. http://opennotion.com



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Tacos-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tacos-devel

Reply via email to