Great, many thanks again for the information. I bet others will find it pretty handy too!
On Mon, Jul 13, 2009 at 9:23 PM, Musachy Barroso<musa...@gmail.com> wrote: > you can sue that notation anywhere. A tip that will save you a lot of > time, always wrap the OGNl expressions with %{}, that's why the first > hidden is not getting evaluated. The second one has an empty value > because "goalToAchieve" is probably not pointing to anything. > > btw what #attr does is search for a value in all scopes (page, > request, session , application) > > musahcy > > On Mon, Jul 13, 2009 at 5:57 PM, Dimitrios > Christodoulakis<dimi....@gmail.com> wrote: >> Thanks again for helping out Musachy, >> I was wondering if there are any rules regarding when the notation you >> suggested below can be used. it works perfectly for setting url >> params. >> >> I was trying to use it (with struts2 tags) within a form (which is >> within the display:column tag) to pass the value to an action: >> >> <display:column> >> <s:form action="UpdateEntryForm"> >> <s:hidden name="mark" value="#attr.thisEntry.mark" /> >> <s:hiddenname="name" value="%{goalToAchieve.name}" /> >> <s:submit value="Edit"/> >> </s:form> >> </display:column> >> >> This creates an "Edit" button in each row for every object I iterate >> over, and I hoped to use the s:hidden tag to populate the underlying >> UpdateEntryForm action. I also try to test it by printing from the >> execute method as listed below, but the console output is just the >> literal for the mark and zero for the primitive: >> >> This id is: 0 >> This name is: #attr.thisEntry.mark >> >> My action class: >> >> public class UpdateEntryForm extends ActionSupport{ >> public String execute(){ >> System.out.println("This id is: "+ getId()); >> System.out.println("This name is: "+ getMark()); >> return SUCCESS; >> } >> private String name; >> private long mark; >> public String getName() { >> return name; >> } >> public void setName(String name){ >> this.name = name; >> } >> >> public String getMark() { >> return mark; >> } >> public void setMark(String mark){ >> this.mark = mark; >> } >> } >> >> Is there something wrong with the code above? Thanks again! >> >> On Mon, Jul 13, 2009 at 2:03 PM, Musachy Barroso<musa...@gmail.com> wrote: >>> The current row used by displaytag is pushed under the name set in >>> uid, so you could do this: >>> >>> <display:table name="goalToAchieve.entries" requestURI="" uid="thisGoal"> >>> <display:column> >>> <a href="<s:url action='DeleteEntryForm' escapeAmp="false"> >>> <s:param name="date" value="#attr.thisGoal.mark" /> >>> </s:url> >>> ">Remove</a> >>> </display:column> >>> >>> musachy >>> >>> On Mon, Jul 13, 2009 at 11:17 AM, Dimitrios >>> Christodoulakis<dimi....@gmail.com> wrote: >>>> Thanks. So, if I wanted to access a particular property (say this >>>> property is called mark) of an "entry" object which I am iterating >>>> over, I would do something like the following: >>>> >>>> <display:table name="goalToAchieve.entries" requestURI="" uid="thisGoal"> >>>> <display:column property="entry" /> >>>> <display:column property="date" sortable="true" >>>> defaultorder="ascending" title="TimeStamp"/> >>>> <display:column property="mark" /> >>>> <display:column> >>>> <a href="<s:url action='DeleteEntryForm' escapeAmp="false"> >>>> <s:param name="name" value="%{goalToAchieve.owner.fullName}" /> >>>> <s:param name="id" value="%{goalToAchieve.id}" /> >>>> <s:param name="date" value="#attr.entry.mark" /> >>>> </s:url> >>>> ">Remove</a> >>>> </display:column> >>>> >>>> So, I could pass mark as a url param via s:url within the display tag? >>>> >>>> Thanks for the information! >>>> >>>> On Mon, Jul 13, 2009 at 1:08 PM, Musachy Barroso<musa...@gmail.com> wrote: >>>>> Assuming that each entry is named "entry" by displayTag, you can >>>>> access it using "#attr.entry" (or "#attr['entry']") to access it from >>>>> the S2 tags. >>>>> >>>>> musachy >>>>> >>>>> On Mon, Jul 13, 2009 at 10:27 AM, Dimitrios >>>>> Christodoulakis<dimi....@gmail.com> wrote: >>>>>> Yes, that is exactly the case, hmm.. Although, how is the >>>>>> display:table tag finds the collection in the first place? >>>>>> >>>>>> Supposedly the display has some way of reaching the valuestack, it can >>>>>> even resolve the deeper notation <display:table >>>>>> name="goalToAchieve.entries" >>>>>> >>>>>> However, I will switch back to s:iterator to test if the syntax >>>>>> suggested will work. I mainly used the display tag as a quick way to >>>>>> sort the collection, but if I can't access the properties of the >>>>>> objects I am iterating over, it isn't of much use in this case >>>>>> >>>>>> On Mon, Jul 13, 2009 at 12:20 PM, Greg Lindholm<greg.lindh...@gmail.com> >>>>>> wrote: >>>>>>> OK, I see the problem now... you are not using <s:iterator> to go thru >>>>>>> the >>>>>>> entries, you are using <display:table>. >>>>>>> >>>>>>> The syntax suggested will not work since <display:table> does not know >>>>>>> anything about the value stack.The <s:param name="mark" value="%{mark}" >>>>>>> /> >>>>>>> uses the value stack to resolve 'mark' which will not work here, you >>>>>>> will >>>>>>> need to replace %{mark} with the right syntax to work with >>>>>>> <display:table> >>>>>>> iterator. >>>>>>> >>>>>>> And I don't know anything about <display:table> so you will need to >>>>>>> look up >>>>>>> how to access the properties of the entities you are iterating over so >>>>>>> as to >>>>>>> build the URL. >>>>>>> >>>>>>> >>>>>>> On Mon, Jul 13, 2009 at 12:28 PM, Dimitrios Christodoulakis < >>>>>>> dimi....@gmail.com> wrote: >>>>>>> >>>>>>>> I made the changes, but the view source indicates that the param >>>>>>>> "mark" is not passed. >>>>>>>> >>>>>>>> The url linked is formed like this: >>>>>>>> >>>>>>>> /secure/DeleteEntryForm.action?name=firstName+lastName&id=1 >>>>>>>> >>>>>>>> The name and id params are fields of the parent object, the one >>>>>>>> containing the collection. >>>>>>>> >>>>>>>> Actually, I tried with all fields taken from the collection object, >>>>>>>> like entry, and date but none gets passed as a param. Only properties >>>>>>>> exposed by the parent object, goalToAchieve are passed, shouldn't I be >>>>>>>> able to point to a field within a collection object too? >>>>>>>> >>>>>>>> It looks like individual collection object properties can be viewed >>>>>>>> using the iterator/display, but cannot be "captured" or passed as >>>>>>>> parameters for any other uses... unless I am missing something, or >>>>>>>> doing something wrong. >>>>>>>> >>>>>>>> >>>>>>>> On Mon, Jul 13, 2009 at 10:50 AM, Greg >>>>>>>> Lindholm<greg.lindh...@gmail.com> >>>>>>>> wrote: >>>>>>>> > Looks like you need to change entry.mark to just mark and remove the >>>>>>>> > <s:property value="%{entry}"/>. Also you probably don't need to pass >>>>>>>> > both >>>>>>>> > the name and id of the parent object. >>>>>>>> > >>>>>>>> > <a href="<s:url action='DeleteEntryForm' var="entry" >>>>>>>> > escapeAmp="false"> >>>>>>>> > <s:param name="id" value="%{goalToAchieve.id}" /> >>>>>>>> > <s:param name="mark" value="%{mark}" /> >>>>>>>> > </s:url> >>>>>>>> > ">Remove</a> >>>>>>>> > >>>>>>>> > >>>>>>>> > On Mon, Jul 13, 2009 at 10:48 AM, Dimitrios Christodoulakis < >>>>>>>> > dimi....@gmail.com> wrote: >>>>>>>> > >>>>>>>> >> Thanks for letting me know. Alright, so: >>>>>>>> >> >>>>>>>> >> This is the parent class: >>>>>>>> >> >>>>>>>> >> @Entity >>>>>>>> >> public class GoalToAchieve { >>>>>>>> >> @Id @GeneratedValue >>>>>>>> >> private Long id; >>>>>>>> >> >>>>>>>> >> @org.hibernate.annotations.CollectionOfElements >>>>>>>> >> @JoinTable (name="GoalToAchieve_entry", >>>>>>>> >> joincolum...@joincolumn(name="goalToAchieve_id")) >>>>>>>> >> private Set<JournalEntry> entries = new HashSet<JournalEntry>(); >>>>>>>> >> >>>>>>>> >> public Set<JournalEntry> getEntries() { >>>>>>>> >> return entries; >>>>>>>> >> } >>>>>>>> >> public void setEntries(SortedSet<JournalEntry> entries) { >>>>>>>> >> this.entries = entries; >>>>>>>> >> } >>>>>>>> >> >>>>>>>> >> public void addEntry(JournalEntry newEntry){ >>>>>>>> >> entries.add(newEntry); >>>>>>>> >> } >>>>>>>> >> >>>>>>>> >> public void deleteEntry(JournalEntry entry){ >>>>>>>> >> entries.remove(entry); >>>>>>>> >> } >>>>>>>> >> ..plus some other standard fields with getters and setters >>>>>>>> >> >>>>>>>> >> This is the child-class: >>>>>>>> >> >>>>>>>> >> @Embeddable >>>>>>>> >> public class JournalEntry { >>>>>>>> >> @org.hibernate.annotations.Parent >>>>>>>> >> private GoalToAchieve goalToAchieve; >>>>>>>> >> >>>>>>>> >> @Column >>>>>>>> >> private Long mark; >>>>>>>> >> public Long getMark() { >>>>>>>> >> return mark; >>>>>>>> >> } >>>>>>>> >> public void setMark(long mark){ >>>>>>>> >> this.mark = mark; >>>>>>>> >> } >>>>>>>> >> >>>>>>>> >> @Column(length = 255, nullable = false) >>>>>>>> >> private String entry; >>>>>>>> >> >>>>>>>> >> @Temporal(TemporalType.TIMESTAMP) >>>>>>>> >> @Column(nullable = false, updatable = false) >>>>>>>> >> private Date insertDate = new Date(); >>>>>>>> >> >>>>>>>> >> ..plus the rest getters and setters >>>>>>>> >> >>>>>>>> >> And this this the jsp part where I display the collection: >>>>>>>> >> >>>>>>>> >> <s:if test="goalToAchieve.entries.size > 0"> >>>>>>>> >> <display:table name="goalToAchieve.entries" requestURI="" >>>>>>>> uid="thisGoal"> >>>>>>>> >> <display:column property="entry" /> >>>>>>>> >> <display:column property="date" sortable="true" >>>>>>>> >> defaultorder="ascending" title="TimeStamp"/> >>>>>>>> >> <display:column property="mark" /> >>>>>>>> >> <display:column> >>>>>>>> >> <a href="<s:url action='UpdateEntryForm'> >>>>>>>> >> <s:param name="name" value="%{goalToAchieve.owner.fullName}" >>>>>>>> >> /> >>>>>>>> >> <s:param name="mark" value="#mark" /> >>>>>>>> >> </s:url> >>>>>>>> >> ">Edit</a> >>>>>>>> >> </display:column> >>>>>>>> >> <display:column> >>>>>>>> >> <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="entry.mark" /> >>>>>>>> >> <s:property value="%{entry}"/> >>>>>>>> >> </s:url> >>>>>>>> >> ">Remove</a> >>>>>>>> >> </display:column> >>>>>>>> >> </display:table> >>>>>>>> >> </s:if> >>>>>>>> >> >>>>>>>> >> ..and the delete action, which should take an entry reference and >>>>>>>> >> remove it from the collections looks like this: >>>>>>>> >> >>>>>>>> >> public class DeleteEntry extends ActionSupport{ >>>>>>>> >> public String execute(){ >>>>>>>> >> goalToAchieve.deleteEntry(entry); >>>>>>>> >> >>>>>>>> >> return SUCCESS; >>>>>>>> >> } >>>>>>>> >> >>>>>>>> >> private JournalEntry entry; >>>>>>>> >> private GoalToAchieve goalToAchieve; >>>>>>>> >> private long id; >>>>>>>> >> >>>>>>>> >> ... + getters and setters >>>>>>>> >> >>>>>>>> >> I guess right now, my problem has become how to pass a parameter >>>>>>>> >> referring to en entry (the mark field) to the delete action. Next, I >>>>>>>> >> would do a lookup within the action to find the entry object and >>>>>>>> >> remove it from the parent object collection, by calling >>>>>>>> >> deleteEntry(JournalEntry entry) >>>>>>>> >> >>>>>>>> >> On Mon, Jul 13, 2009 at 9:16 AM, Greg >>>>>>>> >> Lindholm<greg.lindh...@gmail.com> >>>>>>>> >> wrote: >>>>>>>> >> > You are not providing enough information for anyone to help you. >>>>>>>> >> > Since >>>>>>>> >> you >>>>>>>> >> > have changed your object and the jsp you had better include them >>>>>>>> >> > with >>>>>>>> any >>>>>>>> >> > request. >>>>>>>> >> > >>>>>>>> >> > >>>>>>>> >> > On Mon, Jul 13, 2009 at 9:51 AM, Dimitrios Christodoulakis < >>>>>>>> >> > dimi....@gmail.com> wrote: >>>>>>>> >> > >>>>>>>> >> >> Yes, that is a great suggestion actually. What I did was to add >>>>>>>> >> >> a new >>>>>>>> >> >> field based >>>>>>>> >> >> System.currentTimeMillis(), but the problem is adding it as a url >>>>>>>> >> >> parameter. >>>>>>>> >> >> >>>>>>>> >> >> For example, I am trying to add it as a url parameter below: >>>>>>>> >> >> >>>>>>>> >> >> <a href="<s:url action='UpdateEntryForm'> >>>>>>>> >> >> <s:param name="name" value="%{goalToAchieve.owner.fullName}" /> >>>>>>>> >> >> <s:param name="mark" value="%{mark}" /> >>>>>>>> >> >> </s:url> >>>>>>>> >> >> ">Edit</a> >>>>>>>> >> >> >>>>>>>> >> >> But, the only param passed is the fullName. The mark is not >>>>>>>> >> >> added to >>>>>>>> >> >> the url string. I think this is because the only object >>>>>>>> >> >> available on >>>>>>>> >> >> the valuestack is goalToAchieve, and using deeper notation I can >>>>>>>> >> >> reference as deep as the "entries" collection. But not to fields >>>>>>>> >> >> of >>>>>>>> >> >> each entry object. In other words, the display or iterator help >>>>>>>> >> >> me >>>>>>>> >> >> view the collection objects, but not extract and use any of their >>>>>>>> >> >> fields... I am not sure why this is happening, or if I am doing >>>>>>>> >> >> something wrong. >>>>>>>> >> >> >>>>>>>> >> > >>>>>>>> >> >>>>>>>> >> --------------------------------------------------------------------- >>>>>>>> >> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >>>>>>>> >> For additional commands, e-mail: user-h...@struts.apache.org >>>>>>>> >> >>>>>>>> >> >>>>>>>> > >>>>>>>> >>>>>>>> --------------------------------------------------------------------- >>>>>>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >>>>>>>> For additional commands, e-mail: user-h...@struts.apache.org >>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>>> --------------------------------------------------------------------- >>>>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >>>>>> For additional commands, e-mail: user-h...@struts.apache.org >>>>>> >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> "Hey you! Would you help me to carry the stone?" Pink Floyd >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >>>>> For additional commands, e-mail: user-h...@struts.apache.org >>>>> >>>>> >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >>>> For additional commands, e-mail: user-h...@struts.apache.org >>>> >>>> >>> >>> >>> >>> -- >>> "Hey you! Would you help me to carry the stone?" Pink Floyd >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >>> For additional commands, e-mail: user-h...@struts.apache.org >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >> For additional commands, e-mail: user-h...@struts.apache.org >> >> > > > > -- > "Hey you! Would you help me to carry the stone?" Pink Floyd > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org