You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dimitrios Christodoulakis <di...@gmail.com> on 2009/07/12 22:54:04 UTC

problem with deleting objects from a collection

Good afternoon,

I am re-stating a problem I am facing, for which I provided a kind of
complicated description before: Deleting objects from a collection.
The owning, parent object is a hibernate persistent entity, which
contains a collection of components (value-type objects). Such
components don't have shared references, which means that removing a
component from the collection results in deleting the object from the
database.

I am calling an action which exposes the parent entity, goalToAchieve,
and the result page iterates over the collection
goalToAchieve.entries:

<display:table name="goalToAchieve.entries" requestURI="" uid="thisGoal">
    <display:column property="entry" />
    <display:column property="date" sortable="true"
defaultorder="ascending" title="TimeStamp"/>
</display:table>

The above works, fine. Each row of the table is an instance of the
JournalEntry class displaying two fields: an entry of type String and
a date of type Date. My objective is to give the user the option to
update or delete each row right from the table view. So, I thought to
add two more columns in each row: Update or Delete. I have not been
able to implement this properly, I tried with a url, and with a form.
My guess is that I cannot pass a reference to the row back to the
action performing the delete or update. Am I making this more
complicated than it really is? What can I be missing?

I tried adding one more column like this, hoping the entry property
will be available to the DeleteEntry action via the mini-form.

<display:column>
<s:form action="DeleteEntry">
    <s:property value="entry"/>
    <s:hidden name="id" value="%{goalToAchieve.id}" />
   <s:submit value="Remove"/>
</s:form>
</display:column>

The DeleteEntry action has all the getters and setters:

public String execute(){
		goalToAchieve = getSubscriberService().getGoalToAchieve(id);
		goalToAchieve.deleteEntry(entry);
		
		return SUCCESS;
}

public void setEntry(JournalEntry entry){
		this.entry = entry;
}
	
public JournalEntry getEntry(){
		return entry;
}

But I get java.lang.NullPointerException: actions.DeleteEntry.execute

1) I am not sure if the reference to the entry is passing over to the
action, and
2) if it does, seems like there is no entry object instantiated. But
the entry was instantiated at the time of the insert.

Any ideas about this, and general guidelines on deleting objects from
collections?

Appreciate the help.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: problem with deleting objects from a collection

Posted by Dimitrios Christodoulakis <di...@gmail.com>.
I think I might have an idea why the iterator or display tag do not
allow for working with collection items.

In the past I used form tags (like select) to prompt the user to make
a selection from a menu, my thought is that since I was using form
tags, by submitting the form, the property (item from the collection)
is passed to the valuestack and the action can work with it.

But an iterator or a display tag do not necessarily put properties on
the valuestack. Is this correct? I was wondering if I could use a set,
or push tag to either store the property to the scope or put it on the
top of the valuestack that way? Would you say this is a valid
strategy?

This has been troubling me for a few days, so I hope it is alright to
post my new thought on this. Thank you for any new input.

On Sun, Jul 12, 2009 at 5:16 PM, Dimitrios
Christodoulakis<di...@gmail.com> wrote:
> Thanks Dave,
>
> Yes, the <s:property.../> isn't supposed to be there....  Thanks for
> pointing this out. Indeed, it has to be an object there, in order to
> do the remove from the collection. Since this value-type component
> (entry) does not have a primary key to look it up from, I am a bit at
> a loss how to continue from here.
>
> If you don't mind, could you explain a little bit further? I have
> successfully removed entity object from collections before because all
> I neede was the primary key to be passed to the delete action. Then
> inside the action I did the look up using the key and removed the
> object. But with this type of object I have hit a roadblock.
>
> I appreciate any further help.
>
>
> This is the class:
>
> @Embeddable
> public class JournalEntry {
>
>        @org.hibernate.annotations.Parent
>        private GoalToAchieve goalToAchieve;
>
>        @Column(length = 255, nullable = false)
>        private String entry;
>
>        @Temporal(TemporalType.TIMESTAMP)
>        @Column(nullable = false, updatable = false)
>        private Date insertDate = new Date();
>
>
> ....plus the appropriate getters and setters..
>
> On Sun, Jul 12, 2009 at 5:03 PM, Dave Newton<ne...@yahoo.com> wrote:
>> Dimitrios Christodoulakis wrote:
>>>
>>> I tried adding one more column like this, hoping the entry property
>>> will be available to the DeleteEntry action via the mini-form.
>>>
>>> <display:column>
>>> <s:form action="DeleteEntry">
>>>    <s:property value="entry"/>
>>>    <s:hidden name="id" value="%{goalToAchieve.id}" />
>>>   <s:submit value="Remove"/>
>>> </s:form>
>>> </display:column>
>>
>> What's that <s:property.../> supposed to be doing?
>>
>> It's not a form field; there's no entry reference being passed back. Even if
>> it *was* a form field it's still not passing a *reference* back--forms
>> *only* submit strings. Always. If you want an actual *entry* object there
>> either needs to be some type conversion, database retrieval, etc.
>>
>> Dave
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: problem with deleting objects from a collection

Posted by Dimitrios Christodoulakis <di...@gmail.com>.
Thanks Dave,

Yes, the <s:property.../> isn't supposed to be there....  Thanks for
pointing this out. Indeed, it has to be an object there, in order to
do the remove from the collection. Since this value-type component
(entry) does not have a primary key to look it up from, I am a bit at
a loss how to continue from here.

If you don't mind, could you explain a little bit further? I have
successfully removed entity object from collections before because all
I neede was the primary key to be passed to the delete action. Then
inside the action I did the look up using the key and removed the
object. But with this type of object I have hit a roadblock.

I appreciate any further help.


This is the class:

@Embeddable
public class JournalEntry {
	
	@org.hibernate.annotations.Parent
	private GoalToAchieve goalToAchieve;
	
	@Column(length = 255, nullable = false)
	private String entry;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false, updatable = false)
	private Date insertDate = new Date();


....plus the appropriate getters and setters..

On Sun, Jul 12, 2009 at 5:03 PM, Dave Newton<ne...@yahoo.com> wrote:
> Dimitrios Christodoulakis wrote:
>>
>> I tried adding one more column like this, hoping the entry property
>> will be available to the DeleteEntry action via the mini-form.
>>
>> <display:column>
>> <s:form action="DeleteEntry">
>>    <s:property value="entry"/>
>>    <s:hidden name="id" value="%{goalToAchieve.id}" />
>>   <s:submit value="Remove"/>
>> </s:form>
>> </display:column>
>
> What's that <s:property.../> supposed to be doing?
>
> It's not a form field; there's no entry reference being passed back. Even if
> it *was* a form field it's still not passing a *reference* back--forms
> *only* submit strings. Always. If you want an actual *entry* object there
> either needs to be some type conversion, database retrieval, etc.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: problem with deleting objects from a collection

Posted by Dimitrios Christodoulakis <di...@gmail.com>.
I am starting to think that using embeddable might be more hassle than
it sounds. i am considering switching to an entity object and dealing
with a collection of entities instead. Given that I will not have any
shared references anyway, it might solve the problem.

I tried attaching a unique field to each embeddable, like a
System.currentTimeMillis(), just to identify the entries, but although
I can display the properties of each object in the collection, since
the object actually exposed is the parent owning object, I can't
attach a specific component attribute as a url parameter:

<a href="<s:url action='DeleteEntryForm' var="entry" escapeAmp="false">
<s:param name="name" value="%{goalToAchieve.owner.fullName}" />
<s:param name="id" value="%{goalToAchieve.id}" />
<s:param name="mark" value="mark" />
<s:property value="%{entry}"/>
  </s:url>
">Remove</a>

Now, I added the follow to the class:

       @Column
	private Long mark;
	public Long getMark() {
		return mark;
	}
	public void setMark(long mark){  //set at each new instance
		this.mark = mark;
	}

But the parameter is not added to the url. Am I doing this wrong, or
is there another way before switching to entities?

Thanks again.

On Sun, Jul 12, 2009 at 5:03 PM, Dave Newton<ne...@yahoo.com> wrote:
> Dimitrios Christodoulakis wrote:
>>
>> I tried adding one more column like this, hoping the entry property
>> will be available to the DeleteEntry action via the mini-form.
>>
>> <display:column>
>> <s:form action="DeleteEntry">
>>    <s:property value="entry"/>
>>    <s:hidden name="id" value="%{goalToAchieve.id}" />
>>   <s:submit value="Remove"/>
>> </s:form>
>> </display:column>
>
> What's that <s:property.../> supposed to be doing?
>
> It's not a form field; there's no entry reference being passed back. Even if
> it *was* a form field it's still not passing a *reference* back--forms
> *only* submit strings. Always. If you want an actual *entry* object there
> either needs to be some type conversion, database retrieval, etc.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: problem with deleting objects from a collection

Posted by Dave Newton <ne...@yahoo.com>.
Dimitrios Christodoulakis wrote:
> I tried adding one more column like this, hoping the entry property
> will be available to the DeleteEntry action via the mini-form.
> 
> <display:column>
> <s:form action="DeleteEntry">
>     <s:property value="entry"/>
>     <s:hidden name="id" value="%{goalToAchieve.id}" />
>    <s:submit value="Remove"/>
> </s:form>
> </display:column>

What's that <s:property.../> supposed to be doing?

It's not a form field; there's no entry reference being passed back. 
Even if it *was* a form field it's still not passing a *reference* 
back--forms *only* submit strings. Always. If you want an actual *entry* 
object there either needs to be some type conversion, database 
retrieval, etc.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org