Reputation: 15
I want to transfer parameter #{myvar.tc} with f:attribute component. In the datatable cocukDoktor() method "dr_tc" came. I want to run drgor.sayfaYonlendirme() after parameter transfer. But #{myvar.tc} doesn't transfer. What can I do?
<h:dataTable value="#{doktor.cocukDoktor()}" var="myvar">
<table>
<tr>
<td>
<h:column>
<h:graphicImage class="doktorfoto" value="resources/images/doktorfoto.jpg"/>
</h:column>
</td>
<td>
<h:column>
<h:form>
<h:commandLink class="doktorismi" action="#{drgor.sayfaYonlendirme()}" actionListener="#{drgor.drtcAyarla}" >#{myvar.dr_adi} #{myvar.dr_soyadi}
<f:attribute name="dr_tc" value="#{myvar.dr_tc}"/>
</h:commandLink>
</h:form>
</h:column>
</td>
</tr>
</table>
</h:dataTable>
Bean code
@ManagedBean( name="drgor")
@SessionScoped
public class doktorgoruntule {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
String drAdi;
String drSoyadi;
public String getDrAdi() {
return drAdi;
}
public void setDrAdi(String drAdi) {
this.drAdi = drAdi;
}
public String getDrSoyadi() {
return drSoyadi;
}
public void setDrSoyadi(String drSoyadi) {
this.drSoyadi = drSoyadi;
}
public String dr_tc;
public void setDr_tc(String dr_tc) {
this.dr_tc = dr_tc;
}
public String getDr_tc() {
return dr_tc;
}
public void drtcAyarla(ActionEvent event){
dr_tc = (String)event.getComponent().getAttributes().get("dr_tc");
}
public String sayfaYonlendirme(){
return "cocukDoktorGoruntule?faces-redirect=true”";
}
public ResultSet cocukdoktorGoruntule() throws Exception{
try{
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/tipmerkezivt","postgres", "2569");
ps = conn.prepareStatement("select * from doktor \n" +
"WHERE\n" +
"dr_tc = '"+dr_tc+"'" , ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = ps.executeQuery();
return rs;
}
catch (Exception e) {
throw new Exception("Bağlantı başarısız!");
}
finally{
conn.close();
}
}
}
Upvotes: 1
Views: 361
Reputation: 458
Can you give it a try with
<h:form>
<h:dataTable value="#{doktor.cocukDoktor()}" var="myvar">
<h:column>
<h:graphicImage class="doktorfoto" value="resources/images/doktorfoto.jpg"/>
</h:column>
<h:column>
<h:commandLink class="doktorismi"
action="#{drgor.sayfaYonlendirme()}"
actionListener="#{drgor.drtcAyarla}"
value="#{myvar.dr_adi} #{myvar.dr_soyadi}"
>
<f:setPropertyActionListener target="#{drgor.tr_tc}" value="#{myvar.dr_tc}" />
</h:commandLink>
<h:column>
</h:dataTable>
</h:form>
Anyway, there is no need to do the table HTML stuff, it is done by the dataTable. Also the doctor class is missing to give you more help. To get more satisfying help, you need to provide more information.
Upvotes: 2