Here I am started to design a portal wise home,login,register ....around 10 common jsp pages.
Its very hard to create these many jsp pages for each portal ,which is an most elegant way.So decided to split the jsp's into header,body,footer and using common header and footer.each time body is changing.
<jsp:include /header.jsp>...body<jsp:include /footer.jsp>
Some thing like above.But the problem raises now is the header footer design is not same for all portals.
So decide to make each and every block dynamic which settings will come from database like menu list ,palce of blocks etc ...
Which is the best way to do it.I came to know there are few frameworks like Tiles
,Wicket,Sitemash etc ...
And also referred Better alternative to Apache Tiles confused to decide.
Can anyone familiar with those frameworks guide me in a right way ??or suggest any new ways which i am missing.
Using java(servlets),Msql as DB.I'm not using Struts(agreeing that don't know :)).
Thanks for your time.
IMO Tiles
because its stable and vast user base , and good documentation too.
It provides good compilation of multiple Jsp into view
example
<definition name="myapp.homepage" template="/layouts/classic.jsp">
<put-attribute name="title" value="Tiles tutorial homepage" />
<put-attribute name="header" value="/tiles/banner.jsp" />
<put-attribute name="menu" value="/tiles/common_menu.jsp" />
<put-attribute name="body" value="/tiles/home_body.jsp" />
<put-attribute name="footer" value="/tiles/credits.jsp" />
</definition>
Like wise you can define as many you want , based on the definition name you return from the servlet, tiles would construct the complete JSP for you.Isnt that neat.
They can be integrated with many popular MVC frameworks like
- Spring MVC
- Struts 2.0
and list goes on.
Related
I need to pass a query parameter to the graphicImage to prevent IE from using an old cached image.
I tried below and getting this error: File not found: /RES_NOT_FOUND
<h:graphicImage library="default" name="img/MSM_HeaderSplash.png?v=1.1"
alt=" " width="487" height="68" />
Below works, but I really don't want to hardcode the resources path:
<h:graphicImage value="resources/default/1_0/img/MSM_HeaderSplash.png?v=1.1"
alt=" " width="487" height="68" />
You can try this
Easiest would be to add the folder as a "virtual context" of the servletcontainer which you're using. It's unclear which one you're using. In Tomcat it's a matter of adding a new to the server.xml
<Context docBase="/path/to/images" path="/images" />
and in Glassfish it's a matter of adding an alternatedocroot to the glassfish-web.xml
<property name="alternatedocroot_1" value="from=/images/* dir=/path/to" />
Refer the documentation of the servletcontainer for details. Ultimately they should be accessible by a normal URL so that you can just use for example:
<p:graphicImage value="/images/MSM_HeaderSplash.png?v=1.1" />
I used below to resolve the issue. It is not as intuitive as using the graphicImage's library and name attributes. Please let me know if there is other work around. Thanks
<h:graphicImage value="#{resource['default:img/MSM_HeaderSplash.png']}&v=1.0" alt=" " width="487" height="68" />
The best option for your case seems to be to use HTML <img /> tag. Surprisingly, most of image cache solutions are based in a random generated String, as there is no HTML standard way to achieve it. That will cheat the browser and force it to download it again.
There's no need to hardcode the image path more than once, just make use of <ui:param /> to keep variales in facelets.
<ui:param name="imageFolder" value="resources/images" />
<img src="#{imageFolder}/image.jpg?#{currentDate.time}" />
Where #{currentDate} is a current Date instance. This can be implemented by adding a request scoped bean to your faces-config:
<managed-bean>
<managed-bean-name>currentDate</managed-bean-name>
<managed-bean-class>java.util.Date</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
That evaluates to kind of:
<img src="resources/images/image.jpg?1403302512505">
So your current image will be retrieved in each request.
Another choice is to disable the entire browser cache at web-filter level, despite this would affect your whole content.
See also:
Display Current Date on JSF Page
How to force a web browser NOT to cache images
How to control web page caching, across all browsers?
What I want to accomplish is something like this:
<%# taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld"%>
<stripes:layout-definition>some definition</stripes:layout-definition>
<stripes:layout-render name="someName" />
And then by loading the content of that jsp I will get the content of the layout rendered. The way I do it now is to have two separate files, one with the definition and the other one containing only the render-code. This seems wasteful and basically duplicates the number of required jsps.
I am limited to use Stripes 1.5.3 as there are migration issues with moving to 1.5.7
Content outside of the is blithely ignored, but you can have nested layouts:
<stripes:layout-definition>some definition
<stripes:layout-render name="someName" />
</stripes:layout-definition>
Bit of a background:
We have an existing spring webflow that we want to have ajaxified so that the page can be displayed
in a "lightbox" (at a different URL) where the user can interact with the flow in a similar way to the full existing page.
The normal registration form sits at
http://localhost:8080/csso/customer/registration?execution=e1s1.
(csso is the application name)
The webflow in Spring Webflow has an id of /customer/registration.
<flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<flow-location id="customer/registration" path="/WEB-INF/views/customer/registration/registration-flow.xml"/>
</flow-registry>
registration-flow.xml
<view-state id="create" model="customer" view="customer/registration/create">
<on-render>
<evaluate expression="customer.setAcceptTermsAndConditions(false)"/>
</on-render>
<transition on="submit" to="confirm" />
<transition on="cancel" to="cancel" bind="false" />
</view-state>
Now my problem is I need to access this page in two different ways.
Directly. Which works currently.
As an include in a different JSP page
(tabEntry.jsp accessed with controller /tabEntry) in such a way that the flow of the form is not interrupted.
How can I include /customer/registration inside tabEntry in such a way that clicking on submit goes through the same flow?
Problems faced:
Including /customer/registration by jsp:include doesn't work since /customer/registration is not a controller. Also #include doesn't work since a call to /customer/redirection includes a redirect which sets the execution key for webflow
The form action is automatically set to /tabEntry but it should be set to the second state of /customer/registation to continue with the flow.
Happy to accept design changes instead of hammering it technically.
I´m new to Spring Webflow, so I have a Question about a (or more) Flows.
I want to build a few facelets in JSF and one start Page that can have different ui-params in an ui-include, depending on what i want to add in the flow later.
Example application.xhtml:
`<ui:include src="start.xhtml">
<ui:param name="page1" value="page1.xhtml" />
<ui:param name="page2" value="page2.xhtml" />
<!-- page 3 should be ignored -->
<!-- <ui:param name="page3" value="page3.xhtml" /> -->
<ui:param name="page4" value="page4.xhtml" />
</ui:include>`
Now i have my start-flow.xml where i want to check, which ui:params the page got.
But i don´t knwo how to to that, and i couldn´t find anything similar on the web. so i assume, this might be the wrong way to do so :-)
Can anyone help me out?
My goal is to have a flow (independent from hardcoded facelets, so i can check a list of ui:params what facelets i have and to use them, like:
`<view-state id="start" view="${flowScope.allViews[0]}">
<!-- assuming every facelet has a next-action -->
<transition on="next" to="${flowScope.allViews[1]}" />
</view-state>`
Pretty sure you cant just get a list of JSF includes/params in Spring Webflow.
The closest thing you can get to it is to grab FacesContext and try to locate known components by their ids:
boolean haveComponent1 = (FacesContext.getCurrentInstance().getViewRoot().findComponent("component1") != null);
Assuming you know component IDs in included pages in webflow you can do something like:
<decision-state id="doSomSink">
<on-entry>
<evaluate expression='FacesContext.getCurrentInstance().getViewRoot().findComponent("component1") != null)' result="flowScope.haveComponent1" result-type="bool"></evaluate>
</on-entry>
<if test="flowScope.haveComponent1" then="doIt" else="doNothing"/>
</decision-state>
I am using Apache tiles for templating and part of the template is a header text. This text depends on the section the page belongs to. Each page contains a bean and the header text is built using the properties of that bean. The bean will have a different name for each page.
So, in my JSP file I would have something like this:
<div>${myBean.id} - ${myBean.name}</div>
I want to get that expression in the tile definition and I tried this:
<definition template="/WEB-INF/tiles/layout/mytemplate.jsp">
<put-attribute name="title" expression="${myBean.id} - ${myBean.name}" />
</definition>
And in the template I do:
<div class="title-header"><tiles:insertAttribute name="title" /></div>
But the result is the unprocessed EL expression:
<div>${myBean.id} - ${myBean.name}</div>
The code has been simplified here to keep this post concise but this is exactly what I'm trying to do. There are also reasons why I am trying to do it this way.
Any idea why the EL expresion is not being processed?
Thanks
NOTE: I am fairly new to JSP and Apache Tiles so I may not have used the correct terminology.
I just wanted to point out that Barry's answer (in his comment on the original post) helped me out. You need to have tiles-el.jar on your classpath (if you want to use the standard EL; presumably you need the corresponding JARs for MVEL or OGNL).
Tiles 2. Regarding AttributeEvaluator, here's how you can set that up if you're using Spring:
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles/**/views.xml</value>
</list>
</property>
<!-- Initialize expression language support for use in Tiles definitions. -->
<property name="tilesProperties">
<props>
<prop key="org.apache.tiles.evaluator.AttributeEvaluator">org.apache.tiles.evaluator.el.ELAttributeEvaluator</prop>
</props>
</property>
</bean>
Tiles 3. Spring's TilesConfigurer for Tiles 3 automatically checks the classpath for the JSP API 2.1 and Tiles EL JARs. If it finds them both, it automatically creates an EL-aware attribute evaluator.