Criação de Link na paginação do displaytag

1 resposta
R

olá galera,

estou utilizando display tag para fazer uma paginação de dados e decoradores para criar links, o problema é que quando utilizo o método
getCurrentRowObject() para recupera o objeto corrente, ou seja, o objeto
que clico no link, sempre recupero o primeiro registro da paginação(da pagina corrente), alguém tem alguma idéia…

vejam os códigos:

o JSP

<%@ page import="br.cefetce.lar.invente.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.displaytag.decorator.TableDecorator.*"  %>
<%@page errorPage="error.jsp" %>
<%@taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@include file="FormSearchEnredo2.jsp" %>
<%
  	Vector vetor = (Vector) session.getAttribute("vetor");
	//session.putValue("vetor", vetor);
	session.setAttribute("vetor", vetor);
	//request.setAttribute("vetor",vetor);
  	//System.out.println(vetor);
%>
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="../../css/displaytagex.css">
		<link href="images/css/grid.css" type="text/css" rel="stylesheet" /> 
	</head>
<body background="../../_themes/romtextb.jpg" bgcolor="#cccccc">
<font color=red>
<div id ="grid" align=center>

<display:table name="${vetor}" style="width: 85%; border: 0px" pagesize="5" export="true">

	<display:column property="id" title="Id" decorator = "br.cefetce.lar.invente.CheckWrapper"/>
	<display:column property="title" title="Título" style="width:200px"  />
	<display:column property="author" title="Autor" style="width:250px" />
	<display:column property="institution" title="Institutição" />
	<display:column property="provisionDate" title="Provision Date" style= "width: 100px" />
	<display:column property="learningObjectType" title="Tipo de Objeto Educacional" />
	
	<display:setProperty name="export.pdf" value="true"/>
	
</display:table>
</font>
</body>
</html>

o decorator

package br.cefetce.lar.invente;

import javax.servlet.jsp.PageContext;

import org.displaytag.decorator.DisplaytagColumnDecorator;
import org.displaytag.decorator.ColumnDecorator;
import org.displaytag.decorator.TableDecorator;
import org.displaytag.exception.DecoratorException;
import org.displaytag.properties.MediaTypeEnum;

import com.sun.org.apache.bcel.internal.generic.RET;

import br.cefetce.lar.invente.*;

public class CheckWrapper implements DisplaytagColumnDecorator{
	
	public class CheckWrapper extends TableDecorator{
	Object current = getCurrentRowObject();
	public String getTitle() throws DecoratorException {
		System.out.println(((FormResultBean)this.getCurrentRowObject()).getId());
		return "<FORM name='submitForm' method='post' action='http://localhost:8080/enredo1.1.4/RootSearchEnredo'>" +
		"<input type='hidden' name='submitForm' value='"+((FormResultBean)this.getCurrentRowObject()).getId()+"'checked/>"+
		"<a href='javascript:document.submitForm.submit()'>"+((FormResultBean)this.getCurrentRowObject()).getAuthor()+"</a><a href='#' ></a>";
	}
}

conto com a ajuda de vc’s…

1 Resposta

bebeto

Fala Rafael,

Do jeito que você está fazendo no código, a página html vai dar submit sempre no mesmo formulário (no caso o submitForm).
Uma saída é utilizar o getListIndex() da classe TableDecorator que retorna a posição do objeto corrente. Concatene com o nome do formulário que você sempre dará submit no formulário corrente.

return "<FORM name='submitForm"+Integer.toString(getListIndex())+"' method='post' action='http://localhost:8080/enredo1.1.4/RootSearchEnredo'>" + "<input type='hidden' name='submitForm' value='"+((FormResultBean)this.getCurrentRowObject()).getId()+"'checked/>"+ "<a href='javascript:document.submitForm"+getListIndex()+".submit()'>"+((FormResultBean)this.getCurrentRowObject()).getAuthor()+"</a><a href='#' ></a></FORM>";

Abraços,

Bebeto

Criado 15 de dezembro de 2006
Ultima resposta 29 de mar. de 2007
Respostas 1
Participantes 2