Java jsp中的动态按钮
在我的jsp中,我有一个动态构造的表,如下所示:Java jsp中的动态按钮,java,html,jsp,Java,Html,Jsp,在我的jsp中,我有一个动态构造的表,如下所示: retour.append("<td bordercolor=#FFFFFF>"); retour.append("<input type=\"hidden\" id=\"id_"+nomTab+"_"+compteur+"\" value=\""+object.getIdDailyTimeSheet()+"\"/>");
retour.append("<td bordercolor=#FFFFFF>");
retour.append("<input type=\"hidden\" id=\"id_"+nomTab+"_"+compteur+"\" value=\""+object.getIdDailyTimeSheet()+"\"/>");
retour.append("<img src=\"icon_delete.gif\" onClick=\"deletearowById('id_"+nomTab+"_"+compteur+"')\" style=\"cursor:pointer\" name=\"action\" value=\"deleting\" />");
retour.append("</td>");
}
}
compteur++;
retour.append("</tr>");
}
retour.append ("</table>");'
'retour.append(“”)
retour.append("<td bordercolor=#FFFFFF>");
retour.append("<input type=\"hidden\" id=\"id_"+nomTab+"_"+compteur+"\" value=\""+object.getIdDailyTimeSheet()+"\"/>");
retour.append("<img src=\"icon_delete.gif\" onClick=\"deletearowById('id_"+nomTab+"_"+compteur+"')\" style=\"cursor:pointer\" name=\"action\" value=\"deleting\" />");
retour.append("</td>");
}
}
compteur++;
retour.append("</tr>");
}
retour.append ("</table>");'
s=HibernateUtil.currentSession();
tx=s.beginTransaction();
Query Query=s.createQuery(HQL\u查询)
for(Iterator it=query.iterate();it.hasNext();)
{
if(it.hasNext()){
Dailytimesheet object=(Dailytimesheet)it.next();
retour.append("<td>" +object.getActivity() +"</td>");
retour.append("<td>" +object.getProjectCode() + "</td>");
retour.append("<td>" +object.getWAName() + "</td>");
retour.append("<td>" +object.getTaskCode() +"</td>");
retour.append("<td>" +object.getTimeFrom() +"</td>");
retour.append("<td>" +object.getTimeSpent() + "</td>");
retour.append("<td>" +object.getPercentTaskComplete() + "</td>");
if (droitdaccess)
{
retour.append("<td bordercolor=#FFFFFF>");
retour.append("<input type=\"hidden\" id=\"id_"+nomTab+"_"+compteur+"\" value=\""+object.getIdDailyTimeSheet()+"\"/>");
retour.append("<img src=\"icon_delete.gif\" onClick=\"deletearowById('id_"+nomTab+"_"+compteur+"')\" style=\"cursor:pointer\" name=\"action\" value=\"deleting\" />");
retour.append("</td>");
}
}
compteur++;
retour.append("</tr>");
}
retour.append ("</table>");'
for(Iterator it=query.iterate();it.hasNext();)
{
if(it.hasNext()){
Dailytimesheet对象=(Dailytimesheet)it.next();
追加(“+object.getActivity()+”);
追加(“+object.getProjectCode()+”);
追加(“+object.getWAName()+”);
追加(“+object.getTaskCode()+”);
追加(“+object.getTimeFrom()+”);
retour.append(“+object.gettimespend()+”);
retour.append(“+object.getPercentTaskComplete()+”);
if(droitdaccess)
{
retour.追加(“”);
retour.追加(“”);
retour.追加(“”)
retour.append("<td bordercolor=#FFFFFF>");
retour.append("<input type=\"hidden\" id=\"id_"+nomTab+"_"+compteur+"\" value=\""+object.getIdDailyTimeSheet()+"\"/>");
retour.append("<img src=\"icon_delete.gif\" onClick=\"deletearowById('id_"+nomTab+"_"+compteur+"')\" style=\"cursor:pointer\" name=\"action\" value=\"deleting\" />");
retour.append("</td>");
}
}
compteur++;
retour.append("</tr>");
}
retour.append ("</table>");'
retour.append(“”);
retour.追加(“”);
retour.追加(“”);
retour.追加(“”);
}
}
计算机++;
retour.追加(“”);
}
retour.append(“”;'
在表旁边,我想显示一个名为send的按钮,以便发送表内容。
我真的不想在表为空的位置显示此按钮
retour.append("<td bordercolor=#FFFFFF>");
retour.append("<input type=\"hidden\" id=\"id_"+nomTab+"_"+compteur+"\" value=\""+object.getIdDailyTimeSheet()+"\"/>");
retour.append("<img src=\"icon_delete.gif\" onClick=\"deletearowById('id_"+nomTab+"_"+compteur+"')\" style=\"cursor:pointer\" name=\"action\" value=\"deleting\" />");
retour.append("</td>");
}
}
compteur++;
retour.append("</tr>");
}
retour.append ("</table>");'
因此,至少如果表中只填充了一条记录,我希望显示该按钮。
在这种情况下我该如何处理
retour.append("<td bordercolor=#FFFFFF>");
retour.append("<input type=\"hidden\" id=\"id_"+nomTab+"_"+compteur+"\" value=\""+object.getIdDailyTimeSheet()+"\"/>");
retour.append("<img src=\"icon_delete.gif\" onClick=\"deletearowById('id_"+nomTab+"_"+compteur+"')\" style=\"cursor:pointer\" name=\"action\" value=\"deleting\" />");
retour.append("</td>");
}
}
compteur++;
retour.append("</tr>");
}
retour.append ("</table>");'
谢谢。就像您在每行中创建了一个隐藏字段一样,您可以在关闭表标记后创建一个按钮:
retour.append("<td bordercolor=#FFFFFF>");
retour.append("<input type=\"hidden\" id=\"id_"+nomTab+"_"+compteur+"\" value=\""+object.getIdDailyTimeSheet()+"\"/>");
retour.append("<img src=\"icon_delete.gif\" onClick=\"deletearowById('id_"+nomTab+"_"+compteur+"')\" style=\"cursor:pointer\" name=\"action\" value=\"deleting\" />");
retour.append("</td>");
}
}
compteur++;
retour.append("</tr>");
}
retour.append ("</table>");'
retour.append("<input type='button' value='Send' onclick='fun()'/>");
retour.append(“”);
但是您必须设置一个条件来检查您的查询是否返回了任何行。如果返回,请使用上面的语句附加按钮,否则忽略它
retour.append("<td bordercolor=#FFFFFF>");
retour.append("<input type=\"hidden\" id=\"id_"+nomTab+"_"+compteur+"\" value=\""+object.getIdDailyTimeSheet()+"\"/>");
retour.append("<img src=\"icon_delete.gif\" onClick=\"deletearowById('id_"+nomTab+"_"+compteur+"')\" style=\"cursor:pointer\" name=\"action\" value=\"deleting\" />");
retour.append("</td>");
}
}
compteur++;
retour.append("</tr>");
}
retour.append ("</table>");'