• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

data table- row selection

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all. i am new to JSF. i got a first page in which the user enters the id and clicks search , it forwards to page2(search_res) page ,
retireves the data from the database and displays in the datatable. Now when the user clicks any of the row it has to forward to the page3 (persondetails.jsp page)
(persondetails.jsp page)

how to click the row and forward to the third page,. i am getting SQL error when i tried to click the row parameters in the search_result page.
JSP search_res page:
search_res.JSP

<h:dataTable
border="0" cellpadding="2" cellspacing="0"
columnClasses="columnClass1" headerClass="headerClass"
footerClass="footerClass" rowClasses="rowClass1, rowClass2"
styleClass="dataTable" id="table1" width="90%" rows="20"
value="#{pc_search_res.person_idall}" var="varperson_idall">
<hx:columnEx id="columnEx1">
<f:facet name="header">
<h:outputText styleClass="outputText, staticField"
value="#{person}" id="text2"></h:outputText>
</f:facet>

<hx:commandExRowAction id="rowSelect" action="#{pc_search_res.doRowSelectAction}">
</hx:commandExRowAction>

<h:outputText id="textperson1" value="#{varperson_idall.personIDNum}"
styleClass="outputText, tableData">
</h:outputText>
</hx:columnEx>

search_res.java

public List getperson_idall(){

try {
registerDriver();
Connection conn = getConnection();
try {
Statement stmt = conn.createStatement();

String sql = "SELECT * FROM PERSON WHERE PERSON_ID = "+requestScope.get("personID"); // person ID = the user enters the value in the first page

ResultSet rs1 = stmt.executeQuery(sql);
while(rs1.next()){

int person_IDval = rs1.getInt("PERSON_ID");
PersonInfo personInfo1 = new PersonInfo(person_IDval);
personInfo1.setpersonIDNum(person_IDval);
personinfoall.add(personInfo1);

}

}
catch (SQLException ex) {
System.out.println("SQL exception not executed: " );
ex.printStackTrace();
}
releaseConnection(conn);
}
catch (Exception ex) {
ex.printStackTrace();
}
return person_idall;
}
public String doRowSelectAction()
{

// wht do i need to write hear to forward to the third page.
return "persondetails";
}
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ram, please make your column a hyperlink and pass the id in request as done in the following code. in url attribute I have given Register.jsp, you can write your own.
Please see the following code snippet and try to resolve your problem accordingly.



Regards,
Pomy
 
ram an
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi pommy,
thanks for your reply .. i dont want to add any hyper link to the page. coz.. the rows are populated from the database,(in search result page) and when the user clicks each row it has to go to the details page (page 3) of each one with the value assigned from the database for each respective field.... now i am testing with one sample... if i hyper link the whole column, then it wil go to the same page whn clicking any rows. is there any other way ... coz i am getting SQL exception error.. and when i run from the server , the dobutton row action is not been called and i am getting SQL exception .....i have set the bean property also and i have binded it..
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not clear where your problem lies, but you may at least get useful insights and ideas out of this: http://balusc.blogspot.com/2006/06/using-datatables.html
 
ram an
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Bauke Scholtz,
the problem is if i click any row in the Data table , there is a error displaying ""SQL exception not executed: null".... but what i want is when i click any row it has to navigate to the details page...

for info: the data table values are populated from the database.
the data table values populate depending on the ID typed in the first page...it gets displayed in the Searh_Result page( in the datatable). page 2..... some 4 or 5 rows will be displayed in the datatable.. if i click a row in the datatable , it has to navigate to the third page..(details page)... but i get SQL exception.. and the value is null...

regards,
harish
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the root cause is just a NullPointerException? Fix that first, if necessary based on the examples/understanding of the mentioned article.
 
ram an
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes Bauke Scholtz,
the error is the null point exception.. i am not clear how to solve that error... if i click the row the value is null there in the session scope.. ........ since the sesion scope is null, the SQL is saying the SQL exception error........
i tired setting the session scope.. but its not working....... how could i do sir?

regards,
harish
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please stop with putting that much dots at end of a sentence. It reads annoying. One is enough. Also please pay more attention to the format of your English sentences, you will overcome more professional and serious then.

Back to your actual problem: so you do not know at all when and why a NullPointerException would occur? Have you gone through a basic Java tutorial/book at all?

Well, consider this example:

What happens here?
 
ram an
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this prints out a null at the end since the "String" is set as null .

 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it doesn't. It throws a NullPointerException at 2nd line.

The null hasn't a charAt() method. Even more, the null has nothing at all.

Do you know how to fix it?
 
ram an
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i may be wrong as i am new. i thought of this.

String string = "ABC";
char firstChar = string.charAt(1);
System.out.println(firstChar);
the value is "A" in the print out. it returns the first value in the string. If it is 0 it gives null point exception. am i correct/?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're partly correct.
It is correct that you can fix it by just instantiating/referencing the desired object reference so that it is not null anymore!
About the the charAt() part, you are wrong. 0 is the first index. Also see the javadoc. It can in no way throw NPE here.

Now let's go back to your actual problem. You are encountering a NullPointerException. You do now know how to find the root cause and how to fix it, do you?
 
ram an
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes Bauke Scholtz,
if i put 0 , it will print out the first String and there will be no null point exception.

in my problem if i click the row it returns a null value, the row action do not get executed.
so do i have to set the session scope when the row parameter gets called with the value so that it will not be null?

 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First you need to find out which reference exactly is null. I.e. what exactly is throwing NPE when you accessed/invoked it? You can find the code line number in the stacktrace.
 
ram an
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Bauke Scholtz,

catch(SQLException ex) {
System.out.println("SQL exception not executed: " );
ex.printStackTrace();

this is the line which throws the null point exception.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may help you.
Wrap the row in your table like this:
<h:commandLink title="Show member detail" action="#{linkBean.linker}" immediate="true" >
<h:outputText value="#{memberlist.memberFullName}" />
<f:param name="arg1" value="#{memberlist.memberId}" />

</h:commandLink>

linkBean is a managed bean with 1 property - arg1.
memberlist is also a managedbean (of course).
linker is a method on the linkbean that returns a String indicating a 'from-outcome' in the navigation rules for the bean.

The 'faces-config' file defines these link props so:
<managed-property>
<property-name>arg1</property-name>
<value>#{arg.arg1}</value>
</managed-property>


Now all you have to do in your target page is to reference the linkbean arg value - in my case memberid - to in turn reference the row in your collection from the source page.
Hope this helps.
 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic