You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by nkunkov <nk...@escholar.com> on 2011/11/08 20:05:30 UTC

ClickClick paging and submit links

Hello,
I got a paginator from the ClickClick project and works just fine.
My only problem is that sometimes, i'd like to pass some parameters to the
next page and I don't always want to do this in the URL.  Since the
paginator is using a link - all the parameters will be passed in the URL.
I updated the paginator in such a way that it is using a submitLink and
submits a form with hidden parameters.  Unfortunately, something is off and
I can only get from page one to page two - i can't get to the last page and
next only goes one page up.  It must be something silly but I can't see it.
Or maybe I'm using a wrong approach?
I'm going to post the code that doesn't work and then the code that uses the
link and works.
Any help will be appreciated.

A problematic code:
protected void renderLast(HtmlStringBuffer buffer) {
        buffer.elementStart("li");
        String pageValue = String.valueOf(getPageTotal() - 1);     
        if (getCurrentPage() < getPageTotal() - 1) {        	
            buffer.appendAttribute("class", "last");
            buffer.closeTag();            
            SubmitLink submitLink = getSubmitLink();    
            	
            submitLink.setLabel(getLastLabelMessage());
            submitLink.setParameter(Table.PAGE, pageValue);
            submitLink.setTitle(getLastTitleMessage());
            Form form = new Form("nextForm");
            
            form.add(submitLink);            
            Field field = new HiddenField(Table.PAGE,String.class);            
            field.setValue(pageValue);
            form.add(field);          
            for (Enumeration<String> e = httpRequest.getParameterNames();
e.hasMoreElements();) {
				String param = e.nextElement();
				String value = httpRequest.getParameter(param);
				if(!param.equals("column") &&
				!param.equals("page") && 
				!param.equals("actionLink"))
				{	
					Field f = form.getField(param);					                                      
if (f != null)
						f.setValue(value);
					else
					{						
						f = new HiddenField(param,String.class);
						f.setValue(value);
						form.add(f);					                                                   }
				}
			}	
    		form.render(buffer);  
    		

        } else {
            buffer.appendAttribute("class", "last-off");
            buffer.closeTag();
            buffer.append("<table><tr><td><tr><td>");
            buffer.append(getLastLabelMessage());
            buffer.append("</td></tr></td></tr></table>");
        }
        
        buffer.elementEnd("li");
    }


Below is the method that only uses links and works fine:
protected void renderLastOrig(HtmlStringBuffer buffer) {
        buffer.elementStart("li");
        String pageValue = String.valueOf(getPageTotal() - 1);        
        if (getCurrentPage() < getPageTotal() - 1) {        	
            buffer.appendAttribute("class", "last");
            buffer.closeTag();
            buffer.append("<table><tr><td><tr><td>");
            AbstractLink controlLink = getControlLink();
            controlLink.setLabel(getLastLabelMessage());
            controlLink.setParameter(Table.PAGE, pageValue);
            controlLink.setTitle(getLastTitleMessage());
            
            
            StringBuffer params = new StringBuffer();
    		
    		for (Enumeration<String> e = httpRequest.getParameterNames();
e.hasMoreElements();) 
    		{
    			String param = e.nextElement();
    			if(!param.equals("column") &&
    			!param.equals("page") &&     			
    			!param.equals("actionLink"))
    			{			
    				controlLink.setParameter(param, httpRequest.getParameter(param));    				
    			}
    			
    		}
            
            
            controlLink.render(buffer);
        } else {
            buffer.appendAttribute("class", "last-off");
            buffer.closeTag();
            buffer.append("<table><tr><td><tr><td>");
            buffer.append(getLastLabelMessage());
        }
        buffer.append("</td></tr></td></tr></table>");
        buffer.elementEnd("li");
    }

--
View this message in context: http://click.1134972.n2.nabble.com/ClickClick-paging-and-submit-links-tp6975563p6975563.html
Sent from the click-user mailing list archive at Nabble.com.