You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by walidito <wa...@sgcib.com> on 2007/01/16 20:04:39 UTC
[s2] how to make s:iterator work
Hi everybody.
I have a problem with displaying a list of objects that I extract from a
hibernate database. I' searching for the simpler and the better way to do it
please.
I have two issues :
I am not sure about how to send it to the jsp. For the moment I am trying
this one from my action :
private List getListOfBooks() {
... // get books from Data Access Object classes
}
public String execute() throws Exception {
...
booklist = getListOfBooks();
this.request.setAttribute("listOfBooks", booklist);
return SUCCESS;
}
In my jsp, i don't know how to display it.
I tried many solutions without success among them :
<s:iterator value="%{listOfBooks}">
<s:property value="%{author}"/>
</s:iterator>
which does not work.
Help please !!
--
View this message in context: http://www.nabble.com/-s2--how-to-make-s%3Aiterator-work-tf3022827.html#a8396587
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [s2] how to make s:iterator work
Posted by walidito <wa...@sgcib.com>.
Now i understand better what struts 2 was doin, thanks !
Laurie Harper wrote:
>
> Making the getListOfBooks() method public is the way to go; then you can
> remove the setAttribute() stuff from your execute() method. Struts will
> make any public getter on your action available directly.
>
> L.
>
> walidito wrote:
>> Hi thanks a lot,
>> what you said about the private method is right. I don't know if it is
>> the
>> best solution, but it works well when I changed the method to public, so
>> thanks.
>> However, I' gonna try your last solution to see.
>> regards,
>>
>>
>> cilquirm wrote:
>>>
>>> scratch my original comment ( though the part regarding using the jstl
>>> is
>>> still valid. )
>>>
>>> the problem for you is that since listOfBooks is not in the valuestack
>>> directly, you would have to reference it via the request object, like so
>>>
>>> <s:iterator value="%{#request.listOfBooks}">
>>> ...
>>>
>>>
>>>
>>>
>>> walidito wrote:
>>>> Hi everybody.
>>>> I have a problem with displaying a list of objects that I extract from
>>>> a
>>>> hibernate database. I' searching for the simpler and the better way to
>>>> do
>>>> it please.
>>>> I have two issues :
>>>>
>>>> I am not sure about how to send it to the jsp. For the moment I am
>>>> trying
>>>> this one from my action :
>>>>
>>>> private List getListOfBooks() {
>>>> ... // get books from Data Access Object classes
>>>> }
>>>>
>>>> public String execute() throws Exception {
>>>> ...
>>>> booklist = getListOfBooks();
>>>> this.request.setAttribute("listOfBooks", booklist);
>>>> return SUCCESS;
>>>> }
>>>> In my jsp, i don't know how to display it.
>>>> I tried many solutions without success among them :
>>>>
>>>> <s:iterator value="%{listOfBooks}">
>>>> <s:property value="%{author}"/>
>>>> </s:iterator>
>>>> which does not work.
>>>>
>>>> Help please !!
>>>>
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/-s2--how-to-make-s%3Aiterator-work-tf3022827.html#a8400306
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [s2] how to make s:iterator work
Posted by Laurie Harper <la...@holoweb.net>.
Making the getListOfBooks() method public is the way to go; then you can
remove the setAttribute() stuff from your execute() method. Struts will
make any public getter on your action available directly.
L.
walidito wrote:
> Hi thanks a lot,
> what you said about the private method is right. I don't know if it is the
> best solution, but it works well when I changed the method to public, so
> thanks.
> However, I' gonna try your last solution to see.
> regards,
>
>
> cilquirm wrote:
>>
>> scratch my original comment ( though the part regarding using the jstl is
>> still valid. )
>>
>> the problem for you is that since listOfBooks is not in the valuestack
>> directly, you would have to reference it via the request object, like so
>>
>> <s:iterator value="%{#request.listOfBooks}">
>> ...
>>
>>
>>
>>
>> walidito wrote:
>>> Hi everybody.
>>> I have a problem with displaying a list of objects that I extract from a
>>> hibernate database. I' searching for the simpler and the better way to do
>>> it please.
>>> I have two issues :
>>>
>>> I am not sure about how to send it to the jsp. For the moment I am trying
>>> this one from my action :
>>>
>>> private List getListOfBooks() {
>>> ... // get books from Data Access Object classes
>>> }
>>>
>>> public String execute() throws Exception {
>>> ...
>>> booklist = getListOfBooks();
>>> this.request.setAttribute("listOfBooks", booklist);
>>> return SUCCESS;
>>> }
>>> In my jsp, i don't know how to display it.
>>> I tried many solutions without success among them :
>>>
>>> <s:iterator value="%{listOfBooks}">
>>> <s:property value="%{author}"/>
>>> </s:iterator>
>>> which does not work.
>>>
>>> Help please !!
>>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [s2] how to make s:iterator work
Posted by walidito <wa...@sgcib.com>.
Hi thanks a lot,
what you said about the private method is right. I don't know if it is the
best solution, but it works well when I changed the method to public, so
thanks.
However, I' gonna try your last solution to see.
regards,
cilquirm wrote:
>
>
> scratch my original comment ( though the part regarding using the jstl is
> still valid. )
>
> the problem for you is that since listOfBooks is not in the valuestack
> directly, you would have to reference it via the request object, like so
>
> <s:iterator value="%{#request.listOfBooks}">
> ...
>
>
>
>
> walidito wrote:
>>
>> Hi everybody.
>> I have a problem with displaying a list of objects that I extract from a
>> hibernate database. I' searching for the simpler and the better way to do
>> it please.
>> I have two issues :
>>
>> I am not sure about how to send it to the jsp. For the moment I am trying
>> this one from my action :
>>
>> private List getListOfBooks() {
>> ... // get books from Data Access Object classes
>> }
>>
>> public String execute() throws Exception {
>> ...
>> booklist = getListOfBooks();
>> this.request.setAttribute("listOfBooks", booklist);
>> return SUCCESS;
>> }
>> In my jsp, i don't know how to display it.
>> I tried many solutions without success among them :
>>
>> <s:iterator value="%{listOfBooks}">
>> <s:property value="%{author}"/>
>> </s:iterator>
>> which does not work.
>>
>> Help please !!
>>
>
>
--
View this message in context: http://www.nabble.com/-s2--how-to-make-s%3Aiterator-work-tf3022827.html#a8397097
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [s2] how to make s:iterator work
Posted by cilquirm <aa...@gmail.com>.
scratch my original comment ( though the part regarding using the jstl is
still valid. )
the problem for you is that since listOfBooks is not in the valuestack
directly, you would have to reference it via the request object, like so
<s:iterator value="%{#request.listOfBooks}">
...
walidito wrote:
>
> Hi everybody.
> I have a problem with displaying a list of objects that I extract from a
> hibernate database. I' searching for the simpler and the better way to do
> it please.
> I have two issues :
>
> I am not sure about how to send it to the jsp. For the moment I am trying
> this one from my action :
>
> private List getListOfBooks() {
> ... // get books from Data Access Object classes
> }
>
> public String execute() throws Exception {
> ...
> booklist = getListOfBooks();
> this.request.setAttribute("listOfBooks", booklist);
> return SUCCESS;
> }
> In my jsp, i don't know how to display it.
> I tried many solutions without success among them :
>
> <s:iterator value="%{listOfBooks}">
> <s:property value="%{author}"/>
> </s:iterator>
> which does not work.
>
> Help please !!
>
--
View this message in context: http://www.nabble.com/-s2--how-to-make-s%3Aiterator-work-tf3022827.html#a8396710
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [s2] how to make s:iterator work
Posted by cilquirm <aa...@gmail.com>.
I don't know particularly about the s:iterator, but since you said you're
using JSP, you can access the model via the jstl tags just as easily :
<c:forEach items="${listOfBooks}" var="book">
${book.author}
</c:forEach>
though, looking at your code again, I suspect it's because your getter is
class private.
It would have to be public.
-a
walidito wrote:
>
> Hi everybody.
> I have a problem with displaying a list of objects that I extract from a
> hibernate database. I' searching for the simpler and the better way to do
> it please.
> I have two issues :
>
> I am not sure about how to send it to the jsp. For the moment I am trying
> this one from my action :
>
> private List getListOfBooks() {
> ... // get books from Data Access Object classes
> }
>
> public String execute() throws Exception {
> ...
> booklist = getListOfBooks();
> this.request.setAttribute("listOfBooks", booklist);
> return SUCCESS;
> }
> In my jsp, i don't know how to display it.
> I tried many solutions without success among them :
>
> <s:iterator value="%{listOfBooks}">
> <s:property value="%{author}"/>
> </s:iterator>
> which does not work.
>
> Help please !!
>
--
View this message in context: http://www.nabble.com/-s2--how-to-make-s%3Aiterator-work-tf3022827.html#a8396707
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org