Duplicate componend ID

Hi,

It seems that I'm having problems with duplicate componend ID's when I deploy my application.

As long as I run it from jdeveloper, everything runs fine, but once I deploy it to a sun application server, things start to go wrong...

The first time I visit a view, I perform a search and based on that search, a panelgrid is dynamically filled with database data.

The second time I visit that same page it goes wrong when the page submits, resulting in an error message: javax.servlet.ServletException: Component ID j_id_id21:j_id25 has already been found in the view.

Does anyone know what could be going wrong of has anybody encountered a similar situation and found a solution?

[720 byte] By [-wouter-a] at [2007-11-26 16:18:57]
# 1

Well I'd imagine when your moving from one page to that page something is envoked to populate your datatable and the list or collection that is in it.. So i'd have to give an educated guess that your list or collection is just being added to rather than repopulated? you know what i mean? Just a guess.. Code might help get some more replies.

jbayugaa at 2007-7-8 22:42:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

It is getting repopulated, but I think that that might actually be the problem...

I assume that cache is the problem.

Cache keeps the components, they get rendered again and I get duplicate ID's.

Any ideas on how to disable cache for a certain page.

Anyway, here's part of the code. "searchContracts()" is being called by a commandbutton's action.

public String searchContracts(){

String query = "";

query += "SELECT CTR.ContractId AS ContractId, CTR.title AS title, CTR.activeon AS activeon, CTR.expireson AS expireson, CTREB.new_status AS status, CT.FullName AS FullName, CTEB.new_department AS Department ";

query += "FROM ContractBase AS CTR ";

query += "LEFT OUTER JOIN ContractExtensionBase AS CTREB ON CTR.ContractId = CTREB.ContractId ";

query += "LEFT OUTER JOIN ContactBase AS CT ON CTR.ContactId = CT.ContactId ";

query += "LEFT OUTER JOIN ContactExtensionBase AS CTEB ON CTR.ContactId = CTEB.ContactId ";

query += "WHERE CTREB.new_type = 1 ";

if(this.getInputContractName().getValue() != null && !this.getInputContractName().getValue().equals("")){

query += "AND CTR.title LIKE '%" + this.getInputContractName().getValue() + "%' ";

}

if(this.getContractStatusChoice().getValue() != null && !this.getContractStatusChoice().getValue().equals("4")){

if(this.getContractStatusChoice().getValue().equals("5")){

query += "AND (CTREB.new_status = '1' OR CTREB.new_status = '2') ";

}

else{

query += "AND CTREB.new_status = '" + this.getContractStatusChoice().getValue() + "' ";

}

}

if(this.getInputContractstartFrom().getValue() != null && !this.getInputContractstartFrom().getValue().equals("")){

if(this.getContractstartChoice().getValue().equals("1")){

query += "AND CTR.activeon = '" + this.getInputContractstartFrom().getValue() + "' ";

}

if(this.getContractstartChoice().getValue().equals("2")){

query += "AND CTR.activeon < '" + this.getInputContractstartFrom().getValue() + "' ";

}

if(this.getContractstartChoice().getValue().equals("3")){

query += "AND CTR.activeon > '" + this.getInputContractstartFrom().getValue() + "' ";

}

if(this.getContractstartChoice().getValue().equals("4")){

query += "AND (CTR.activeon BETWEEN '" + this.getInputContractstartFrom().getValue() + "' AND '" + this.getInputContractstartTo().getValue() + "') ";

}

}

if(this.getInputContractendFrom().getValue() != null && !this.getInputContractendFrom().getValue().equals("")){

if(this.getContractendChoice().getValue().equals("1")){

query += "AND CTR.expireson = '" + this.getInputContractendFrom().getValue() + "' ";

}

if(this.getContractendChoice().getValue().equals("2")){

query += "AND CTR.expireson < '" + this.getInputContractendFrom().getValue() + "' ";

}

if(this.getContractendChoice().getValue().equals("3")){

query += "AND CTR.expireson > '" + this.getInputContractendFrom().getValue() + "' ";

}

if(this.getContractendChoice().getValue().equals("4")){

query += "AND (CTR.expireson BETWEEN '" + this.getInputContractendFrom().getValue() + "' AND '" + this.getInputContractendTo().getValue() + "') ";

}

}

ResultSet rs = this.readSQLData(query);

try{

rs.last();

this.setResultSetLength(rs.getRow());

rs.beforeFirst();

}

catch(SQLException e){

System.out.println(e.getMessage() + " at SearchContracts.searchContracts");

}

this.createPanelGrid();

this.getBtnFirst().setRendered(true);

this.getBtnPrevious().setRendered(true);

this.getBtnNext().setRendered(true);

this.getBtnLast().setRendered(true);

this.getBtnFirst().setDisabled(true);

this.getBtnPrevious().setDisabled(true);

if(this.getResultSetLength() > this.DISPLAYEDRESULTS){

this.getBtnNext().setDisabled(false);

this.getBtnLast().setDisabled(false);

}

else{

this.getBtnNext().setDisabled(true);

this.getBtnLast().setDisabled(true);

}

FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("go", "newsearch");

this.appendChildren(rs, 0);

return "success";

}

private void createPanelGrid() {

this.searchContractsGrid = new HtmlPanelGrid();//(HtmlPanelGrid) FacesContext.getCurrentInstance().getApplication().createComponent(HtmlPanelGrid.COMPONENT_TYPE);

this.searchContractsGrid.setColumns(7);

this.searchContractsGrid.setCellpadding("1");

this.searchContractsGrid.setBorder(1);

this.searchContractsGrid.setRendered(true);

this.searchContractsGrid.setWidth("100%");

this.searchContractsGrid.setStyleClass("tablesmalltextcentered");

}

private void appendChildren(ResultSet rs, int position){

List children = this.searchContractsGrid.getChildren();

children.clear();

HtmlOutputText text1 = new HtmlOutputText();

text1.setValue("Contract name");

text1.setStyleClass("textbold");

HtmlOutputText text6 = new HtmlOutputText();

text6.setValue("Contact");

text6.setStyleClass("textbold");

HtmlOutputText text2 = new HtmlOutputText();

text2.setValue("Start date");

text2.setStyleClass("textbold");

HtmlOutputText text3 = new HtmlOutputText();

text3.setValue("End date");

text3.setStyleClass("textbold");

HtmlOutputText text7 = new HtmlOutputText();

text7.setValue("Contract with");

text7.setStyleClass("textbold");

HtmlOutputText text4 = new HtmlOutputText();

text4.setValue("Status");

text4.setStyleClass("textbold");

HtmlOutputText text5 = new HtmlOutputText();

text5.setValue("View detail");

text5.setStyleClass("textbold");

children.add(text1);

children.add(text6);

children.add(text2);

children.add(text3);

children.add(text7);

children.add(text4);

children.add(text5);

try{

rs.beforeFirst();

for(int i = 0; i < position; i++){

rs.next();

}

int stop = position + this.DISPLAYEDRESULTS;

while(rs.next() && position < stop){

text1 = new HtmlOutputText();

text1.setValue(rs.getString("title"));

text6 = new HtmlOutputText();

text6.setValue(rs.getString("FullName"));

text2 = new HtmlOutputText();

text2.setValue(new AdminDate(rs.getString("activeon")).toString());

text3 = new HtmlOutputText();

text3.setValue(new AdminDate(rs.getString("expireson")).toString());

text7 = new HtmlOutputText();

text7.setValue(this.convertDepartment(rs.getInt("Department")));

text4 = new HtmlOutputText();

text4.setValue(this.convertStatus(rs.getString("status")));

HtmlOutputLink link = new HtmlOutputLink();

link.setValue("viewdetail.jsp?ID=" + rs.getString("ContractId"));

HtmlOutputText linkText = new HtmlOutputText();

linkText.setValue("View detail");

link.getChildren().add(linkText);

children.add(text1);

children.add(text6);

children.add(text2);

children.add(text3);

children.add(text7);

children.add(text4);

children.add(link);

position++;

}

String action = (String)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("go");

if(!action.equals("newsearch")){

if(action.equals("next")){

this.getBtnPrevious().setDisabled(false);

this.getBtnFirst().setDisabled(false);

if(position >= this.getResultSetLength()){

this.getBtnNext().setDisabled(true);

this.getBtnLast().setDisabled(true);

}

}

if(action.equals("previous")){

this.getBtnNext().setDisabled(false);

this.getBtnLast().setDisabled(false);

if(position == 1){

this.getBtnPrevious().setDisabled(true);

this.getBtnFirst().setDisabled(true);

}

}

if(action.equals("first")){

this.getBtnFirst().setDisabled(true);

this.getBtnPrevious().setDisabled(true);

this.getBtnNext().setDisabled(false);

this.getBtnLast().setDisabled(false);

}

if(action.equals("last")){

this.getBtnFirst().setDisabled(false);

this.getBtnPrevious().setDisabled(false);

this.getBtnNext().setDisabled(true);

this.getBtnLast().setDisabled(true);

}

}

FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("searchcontractscount", position);

FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("searchcontractsrs", rs);

}

catch(SQLException e){

System.out.println(e.getMessage() + " at Search.appendChildren");

}

}

-wouter-a at 2007-7-8 22:42:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...