Avatar billede fredand Forsker
15. februar 2012 - 08:48 Der er 1 løsning

Where to put a call to the database in a struts2+springapp

Hello guys!

Hope you could help me with some giudelines with struts2 and spring.

I would like to get som text from a database, but I can not figure out how to do that at the right place in my struts2 app.

I got this "LinkAction":
<action name="*Link" method="{1}" class="test.LinkAction">
    <result name="page1" type="tiles">tiles_for_page1</result>
    <result name="page2" type="tiles">tiles_for_page2</result>
</action>
...that responds on links like:
<a href="<s:url action="page1Link"/>" >Page 1</a>

How ever in one page that tiles_for_page1 consists of I would like to fetch some data (list of products) from the database for example like:
<s:iterator value="products">
    <tr id="row_<s:property value="id"/>">
        <td>
            <s:property value="name" />
        </td>
        <td>
            <s:property value="description" />
        </td>
    </tr>
</s:iterator>

I guess I should do the call, for example, findAll in the ProductsServiceImpl in a *Action class.
But where should I put this call so this data is fetched and populated in the page before the page is rendered?

Hope I made this description of the problem understandable,

Best regards
Fredrik
Avatar billede fredand Forsker
15. februar 2012 - 21:16 #1
Hello guys!

I solved it with 2 actions like:

Called from a a href:
        <action name="page1" class="page1Action" method="execute">
            <result name="success" type="tiles">page1</result>
        </action>
       
Called from an form
        <action name="page2" class="page2Action"
            method="save">
            <result name="input" type="tiles">page1</result>
            <result name="success" type="tiles">page2</result>
        </action>

In page1Action I call the database and fetch some texts.
In page2Action a store some date from a form into the database.

How ever I did not mange to get from my LinkAction to the page1Axtion.

So if any one got any idea how to do that please let me know.

Best regards
Fredrik

Best regards
Fredrik
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester