struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bryan <nihil...@gmail.com>
Subject Re: some best practices questions
Date Wed, 07 Jul 2004 16:17:13 GMT
I myself get caching with hibernate which I am using for persistance 
but I wanted the more fine grained control like this so that I could page 
back and forth using displaytag.org. 

here is my jsp code for paging, hope this shows why I am doing it. I guess 
my code is more for implimenting a client view than for heavy duty caching.

snip=
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/c" prefix="c" %>
<%@ taglib uri="/tags/displaytag-el-12" prefix="display" %>

<c:set var="forSaleProperties" value="${forSaleProperties}"></c:set>
<c:set var="contextPath" value="${request.getContextPath}"></c:set>
<c:out value="${request.getContextPath}"/>

<display:table name="${forSaleProperties}" pagesize="15"
requestURI="${pageContext.request.contextPath}/client-search-for-sale-properties-action.do">
	<display:column property="id" title="Id"
href="${pageContext.request.contextPath}/client-property-view-for-sale-action.do"
paramId="id"  paramProperty="id"/>
	<display:column property="name" title="Name"/>
	<display:column property="shortDescription" title="Desc"/>
	<display:column property="town" title="Town" sortable="true"/>
	<display:setProperty name="sort.behavior" value="list" />
	<display:setProperty name="paging.banner.include_first_last" value="true" />
</display:table>
=snip

Cause everything is cached it is a snip to move back and forth through
the records.

--b


On Wed, 07 Jul 2004 08:41:39 -0700, Michael McGrady
<mike@michaelmcgrady.com> wrote:
> I, for one and one only, think that this sort of thing is directly
> addressing the most common recurrent question on this list.  So, if
> anything, this de-spams the list.  Thanks for the suggestion.
> 
> At 04:57 AM 7/7/2004, you wrote:
> >Sorry if this is considered spamming the list ....
> >
> >Speaking of storing stuff in session scope. I've developed what I think is
> >a handy class which I think it useful for
> >when I want to store something like a search in a session variable.
> >
> >For instance if I want to page through it ( using displaytags.org (10 out
> >of 10)) or simply if I don't want to fetch
> >from the database time and time again.
> >By default the data expires on an hourly basis. And if a different
> >combination of parameters is sent it expires
> >the cached stuff.
> >
> >Here is the class
> >
> >snip=
> >package ie.jestate.struts.client;
> >
> >import java.util.Date;
> >
> >/**
> >* @author Bryan Hunt
> >*/
> >//TODO:Perhaps I should be generating a MD5 or something but I can't see a
> >good reason to use any more CPU
> >
> >public class HashGenerator {
> >
> >    private StringBuffer buffer;
> >
> >
> >    /**
> >     *
> >     */
> >    public HashGenerator() {
> >        super();
> >        buffer = new StringBuffer(50);
> >        // TODO Auto-generated constructor stub
> >    }
> >
> >    /**
> >     * @param urbanAreas
> >     */
> >    public void add(Integer[] array,String fieldname) {
> >        for (int i = 0; i < array.length; i++) {
> >            Integer integer = array[i];
> >            buffer.append(integer);
> >        }
> >        buffer.append(fieldname);
> >        buffer.append("-");
> >    }
> >
> >    /**
> >     * @param priceRangeStart
> >     */
> >    public void add(Integer integer,String fieldname) {
> >        // TODO Auto-generated method stub
> >        buffer.append(integer);
> >        buffer.append(fieldname);
> >        buffer.append("-");
> >    }
> >
> >    /**
> >     * @return
> >     */
> >    public String getHash() {
> >
> >        //I append the hour onto the end of the string so that a hash will
> >        //only be good for a max of one hour.
> >        Date date = new Date();
> >
> >        return buffer.toString()+ "-" + new Integer(date.getHours());
> >    }
> >
> >}
> >
> >=snip
> >
> >And here is example usage.
> >snip=
> >/*
> >* Created on 24-Jun-2004
> >*/
> >package ie.jestate.struts.client;
> >
> >import ie.jestate.struts.BaseAction;
> >
> >import java.util.Set;
> >
> >import javax.servlet.http.HttpServletRequest;
> >import javax.servlet.http.HttpServletResponse;
> >import javax.servlet.http.HttpSession;
> >
> >import org.apache.struts.action.ActionForm;
> >import org.apache.struts.action.ActionForward;
> >import org.apache.struts.action.ActionMapping;
> >import org.apache.struts.action.DynaActionForm;
> >
> >/**
> >* @author Bryan Hunt
> >  *
> >*/
> >public class ForSaleSearchAction extends BaseAction {
> >
> >    /* (non-Javadoc)
> >     * @see
> > org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
> > org.apache.struts.action.ActionForm,
> > javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
> >     */
> >    public ActionForward execute(
> >        ActionMapping actionMapping,
> >        ActionForm actionForm,
> >        HttpServletRequest request,
> >        HttpServletResponse response)
> >        throws Exception {
> >
> >        //TODO: Database based initialization of the countries collection
> >        DynaActionForm dynaform = (DynaActionForm) actionForm;
> >        HttpSession session = request.getSession();
> >        String forSalePropertiesSearchCheckSum = (String)
> > session.getAttribute(Constants.FOR_SALE_CHECK_SUM);
> >        String newForSalePropertiesSearchCheckSum = null;
> >
> >        Integer[] urbanAreas = (Integer[]) dynaform.get("urbanAreas");
> >        Integer priceRangeStart = (Integer) dynaform.get("priceRangeStart");
> >        Integer priceRangeEnd = (Integer) dynaform.get("priceRangeEnd");
> >        Integer[] propertyTypes = (Integer[]) dynaform.get("propertyTypes");
> >
> >        HashGenerator hashGenerator = new HashGenerator();
> >                    hashGenerator.add(urbanAreas,"urbanAreas");
> >                    hashGenerator.add(priceRangeStart,"priceRangeStart");
> >                    hashGenerator.add(priceRangeEnd,"priceRangeEnd");
> >                    hashGenerator.add(propertyTypes,"propertyTypes");
> >                    newForSalePropertiesSearchCheckSum =
> > hashGenerator.getHash();
> >
> >            if(forSalePropertiesSearchCheckSum != null &&
> > forSalePropertiesSearchCheckSum.equals(newForSalePropertiesSearchCheckSum)) {
> >                System.out.println("Checksums match");
> >            }
> >
> >        if (forSalePropertiesSearchCheckSum == null
> >            ||
> > !forSalePropertiesSearchCheckSum.equals(newForSalePropertiesSearchCheckSum)){
> >
> >            Set forSaleProperties =
> >                findForSaleProperties(
> >                    urbanAreas,
> >                    priceRangeStart,
> >                    priceRangeEnd,
> >                    propertyTypes);
> >
> >session.setAttribute(Constants.FOR_SALE_PROPERTIES_SEARCH_RESULT,
> >forSaleProperties);
> >            session.setAttribute(
> >                Constants.FOR_SALE_CHECK_SUM,
> >                newForSalePropertiesSearchCheckSum);
> >//                TODO:Add logging functionality
> >                System.out.println("Returning fresh search results");
> >
> >        } else
> >        /*
> >                  if (
> >
> >session.getAttribute("forSalePropertiesSearchCheckSum").equals(
> >                        forSalePropertiesSearchCheckSum))
> >                 */
> >            {
> >            //This means that it is the same search, just called again.
> >            //TODO:Add logging functionality
> >            System.out.println("Returning cached search results");
> >
> >
> >        }
> >
> >        //TODO: Decent logging is needed here
> >        System.out.println(forSalePropertiesSearchCheckSum);
> >        System.out.println(newForSalePropertiesSearchCheckSum);
> >        System.out.println(" ---------------------------------------" );
> >
> >        return actionMapping.findForward("success");
> >        }
> >}
> >
> >=snip
> >
> >
> >
> >
> >Christina Siena wrote:
> >
> >>I recently developed an application with a complex UI. One of the pages
> >>required querying the database based on user selection and re-displaying
> >>the page with the retrieved data and any previous existing user
> >>selections. Four different fields can trigger a db query resulting in
> >>page re-display and validations can also result in page re-display. Each
> >>time the page is re-displayed, the "state" of the page must be
> >>"remembered" from the last time it was displayed. (still with me so far?)
> >>Most of the data re
> 
> 
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message