Reputation: 563
I must be missing something that I hope someone can set me straight. The webapp I inherited uses struts2 and JSP pages, and I want to organize it using this layout manager ( http://igniteui.com/layout-manager/border-layout-markup ). There will be a menu on the left which has links that will load content into the center, while the 'main' page (header, footer, left menu) stays put which I believe fits the SPA principles. The 'content' in the middle will be JSP pages that have forms with input fields that are submitted after user actions.
What I'm not understanding is how struts actions fit into this. The app has actions that are defined in struts.xml and that works fine when that page/form is submitted. But what about when the new JSP is loaded into the content section of the main page? How or what action is associated with that loading?
Currently the main page uses an iframe for the content :
<div class="center">
<iframe id="ifrmContent" name="iframe" src="jspDefaultContent.jsp" </iframe>
</div>
and when a link is clicked in the left menu this is how I switch content :
$("#ifrmContent").attr('src','jspNewContent.jsp');
First I should ask if that is the right/best way to do this, as I've seen/heard that using iframes is not ideal.
Second, the specific problem is that there is no 'action' associated with this new JSP content page loading. So the OGNL that was used to fill in some s:select element lists with data from the database does not work. Specifically this WILL work : "%{@com.my.class@countryList}" because its calling a static variable within that Java server class, but this does NOT : "%{getCities()}" as it is looking to call a method of an action class.. and there is none. It doesn't call the MAIN page action, nor does it call the content page action class.
How can I get an action class associated to the content page I'm loading from a menu link? Or, how can/should this be organized so I don't have these problems, given that I only want to refresh/submit the content and not the entire MAIN page?
Thanks for any advice.
Upvotes: 1
Views: 1525
Reputation: 4912
First
You can use css to divide a page into header,footer,menu,body. This is a lightweight approach. This can replace iframe for your purpose.
Second
How can I get an action class associated to the content page I'm loading from a menu link?
You can point action items of any of your JSP pages to the action servlet(struts.xml). You have to point an action from this JSP page to the action you wanted to map in Struts.xml.
It is the same model as the basic struts2 program.
if you have a basic understanding of struts flow you can do this.
how can/should this be organized so I don't have these problems, given that I only want to refresh/submit the content and not the entire MAIN page?
If this is the case you shouldnot use iframes for content loading in body section. Iframe's will loading the entire webpage for each HTTP request.
Answer for this is to use AJAX with jQuery
Upvotes: 1
Reputation: 50203
There is nothing wrong using <iframe>
s (for the right purposes), they're the best option for their usecases (eg. embed a document in a page). Go ahead and check if they're misused here, if you care.
IgniteUI's Infragistics stuff does not seem to always suit Struts2 (nor Java at all) very well, they seem to be created with .NET ecosystem in mind. Another user asked about working with their File Uploader widget... be careful.
When you set the src
attribute of an <iframe>
, that URL gets called. Since you are using Struts2, no JSP should be called directly, they should instead be the results of the actions executions.
So... just call the actions, instead of the JSPs:
<div class="center">
<iframe id="ifrmContent" src="defaultContet.action" />
</div>
$("#ifrmContent").attr('src','newContent.action');
Upvotes: 1