• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with datatable binding attribute

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have been working on this since two days and couldnt solve it. Please advice

I have a index.jsp page which displays has two tabs(i have to include more but want to solve this first)
<f:view>
<ui:page id="page1">
<ui:html id="html1">
<ui:head id="head1">
<ui:link id="link1" url="/resources/stylesheet.css"/>
</ui:head>
<ui:body id="body1" style="-rave-layout: grid">
<ui:form id="form1">
<ui:tabSet id="tabSet1" selected="tab1" style="left: 24px; top: 24px; position: absolute">
<ui:tab id="tab1" style="height: 18px; width: 47px" text="Oracle">

<ui:panelLayout style="height: 462px; width: 621px">
<h:dataTable binding="#{ApplicationAlerts.dataTable}" headerClass="list-header" id="dataTable1" rowClasses="list-row-even,list-row-odd"
rules="groups" value="#{ApplicationAlerts.oracleAlerts}" var="currentRow">
<h:column>
<h:outputText value="#{currentRow.siteName}"/>
<f:facet name="header">
<h:outputText value="Site"/>
</f:facet>
</h:column>
<h:column>
<h:outputText value="#{currentRow.siteType}"/>
<f:facet name="header">
<h:outputText value="Product Built"/>
</f:facet>
</h:column>
<h:column>
<h:outputText value="#{currentRow.serverType}"/>
<f:facet name="header">
<h:outputText value="Hardware"/>
</f:facet>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Issues"/>
</f:facet>
<h:outputText value="#{currentRow.alertMessage}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Comments"/>
</f:facet>
<h:outputText value="#{currentRow.comments}"/>
</h:column>
<h:column>
<h:outputText value="#{currentRow.alertTime}"/>
<f:facet name="header">
<h:outputText value="Time"/>
</f:facet>

</h:column>
<h:column >
<f:facet name="header">
<h:outputText value="PrimaryServerHealth"/>
</f:facet>
<h:outputText value="primary server health"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="SecondaryServerHealth"/>
</f:facet>
<h:outputText value="primary server health"/>
<h:outputText value="#{ApplicationAlerts.dataTable.rowIndex}"/>
</h:column>

<h:column>
<h:commandButton action="#{ApplicationAlerts.editAlert}" value="edit" />
</h:column>
</h:dataTable>
</ui:panelLayout>

</ui:tab>
<ui:tab id="tab2" style="height: 18px; width: 47px" text="Oracle">

<ui:panelLayout style="height: 462px; width: 621px">
<h:dataTable binding="#{ApplicationAlerts.dataTable}" headerClass="list-header" id="dataTable2" rowClasses="list-row-even,list-row-odd"
rules="groups" value="#{ApplicationAlerts.mysqlAlerts}" var="currentRow">
<h:column>
<h:outputText value="#{currentRow.siteName}"/>
<f:facet name="header">
<h:outputText value="Site"/>
</f:facet>
</h:column>
<h:column>
<h:outputText value="#{currentRow.siteType}"/>
<f:facet name="header">
<h:outputText value="Product Built"/>
</f:facet>
</h:column>
<h:column>
<h:outputText value="#{currentRow.serverType}"/>
<f:facet name="header">
<h:outputText value="Hardware"/>
</f:facet>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Issues"/>
</f:facet>
<h:outputText value="#{currentRow.alertMessage}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Comments"/>
</f:facet>
<h:outputText value="#{currentRow.comments}"/>
</h:column>
<h:column>
<h:outputText value="#{currentRow.alertTime}"/>
<f:facet name="header">
<h:outputText value="Time"/>
</f:facet>
</h:column>
<h:column >
<f:facet name="header">
<h:outputText value="PrimaryServerHealth"/>
</f:facet>
<h:outputText value="primary server health"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="SecondaryServerHealth"/>
</f:facet>
<h:outputText value="primary server health"/>
<h:outputText value="#{ApplicationAlerts.dataTable.rowIndex}"/>

</h:column>

<h:column>
<h:commandButton action="#{ApplicationAlerts.editAlert}" value="edit"/>



</h:column>
</h:dataTable>
</ui:panelLayout>

</ui:tab>

</ui:tabSet>
</ui:form>
</ui:body>
</ui:html>
</ui:page>
</f:view>


I have a ApplicationAlertsDao which is a managed bean and performs edit and savealerts

public class ApplicationAlertsDao {

private ArrayList<ApplicationInstanceTaskAlertBean> alerts;
Logger log;
private HtmlDataTable dataTable;
private ApplicationInstanceTaskAlertBean alert;

public ApplicationAlertsDao() {

}

public ArrayList<ApplicationInstanceTaskAlertBean> getOracleAlerts(){
return getAlerts("oracle");
}

public ArrayList<ApplicationInstanceTaskAlertBean> getMysqlAlerts(){
return getAlerts("mysql");
}


public ArrayList<ApplicationInstanceTaskAlertBean> getAlerts(String catName) {
System.out.println("loading alerts");
Connection con = null;
alerts = new ArrayList<ApplicationInstanceTaskAlertBean>();
try {
Context ctx = new InitialContext();
DataSource oracleds = (DataSource) ctx.lookup("java:jdbc/oracle/mgtdb");
con = oracleds.getConnection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select site_name,site_type ,server_type,app_inst_task_alert_message ,app_inst_task_alert_comments,app_inst_task_alert_time,seq_app_inst_task_alert from app_inst_task_alerts join app_inst_task_alert_comments using(seq_app_inst_task_alert)join app_inst_tasks using(seq_app_inst_task)join app_instances using(seq_app_instance)join servers using(seq_server)join applications using(seq_application)join app_categories using(seq_app_category)join sites using(seq_site) where app_category_name='" + catName + "'");
while (rs.next()) {
alert = new ApplicationInstanceTaskAlertBean();
System.out.println(rs.getString(1));
alert.setSiteName(rs.getString(1));
alert.setSiteType(rs.getString(2));
alert.setServerType(rs.getString(3));
alert.setAlertMessage(rs.getString(4));
alert.setComments(rs.getString(5));
alert.setAlertTime(rs.getDate(6));
alert.setAlertId(rs.getInt(7));
alerts.add(alert);

}

setAlerts(alerts);
} catch (NamingException ex) {
//java.util.logging.Logger.getLogger(ApplicationAlertsDAO.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
try {
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
return alerts;
}


public void setAlerts(ArrayList<ApplicationInstanceTaskAlertBean> alerts) {
System.out.println("setting alerts");
this.alerts = alerts;
}

public HtmlDataTable getDataTable() {
System.out.println("getdatatable");
return dataTable;
}

public void setDataTable(HtmlDataTable dataTable) {
System.out.println("setdatatable");
this.dataTable = dataTable;
}

public ApplicationInstanceTaskAlertBean getAlert() {
return alert;
}

public void setAlert(ApplicationInstanceTaskAlertBean alert) {

System.out.println("setting alerts");
this.alert = alert;
}

public String editAlert(){
System.out.println("editAlert");
System.out.println("row index"+dataTable.getRowIndex());
//System.out.println((FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("index")));
alert=(ApplicationInstanceTaskAlertBean)dataTable.getRowData();
System.out.println("return edit");
return "edit";

}

public String saveAlert() {
Connection con = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:jdbc/oracle/mgtdb");
con = ds.getConnection();
PreparedStatement st=null;
st = con.prepareStatement("update app_inst_task_alerts set app_inst_task_alert_message=? where seq_app_inst_task_alert=?");
st.setString(1,alert.getAlertMessage());
st.setInt(2,alert.getAlertId());
st.executeUpdate();
st=con.prepareStatement("update app_inst_task_alert_comments set app_inst_task_alert_comments=? where seq_app_inst_task_alert=?");
st.setString(1,alert.getComments());
st.setInt(2,alert.getAlertId());
st.executeUpdate();

} catch (Exception ex) {
ex.printStackTrace();
}finally{
try {
con.close();
} catch (SQLException ex) {
// java.util.logging.Logger.getLogger(ApplicationAlertsDAO.class.getName()).log(Level.SEVERE, null, ex);
}
}

return "save";
}

}

what i want to achieve is, i am displaying all the alerts thru dataTable and adding an edit button to each row. the selected row is displayed in another page in editable formate and save. i could perform the edit and save but the problem is, when i am using binding attribute in both the tab's datatable, only one tab is displaying the data. the other one is blank. if i doest add the binding attribute, i am not able to do selecte a row correctly and edit and save. How to solve this

I hope i am clear on what i want.Thanks for going thru my question.
Any advice would be helpful.... thanks in advance
reply
    Bookmark Topic Watch Topic
  • New Topic