my dog learned polymorphism*
The moose likes JSF and the fly likes data  table- row selection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "data  table- row selection" Watch "data  table- row selection" New topic
Author

data table- row selection

ram an
Greenhorn

Joined: Feb 12, 2009
Posts: 10
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";
}
Muhammad Ijaz
Ranch Hand

Joined: Mar 03, 2009
Posts: 34
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


IBM Certified WebSphere Commerce Application Developer

ram an
Greenhorn

Joined: Feb 12, 2009
Posts: 10
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..
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Feb 12, 2009
Posts: 10
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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Feb 12, 2009
Posts: 10
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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Feb 12, 2009
Posts: 10
this prints out a null at the end since the "String" is set as null .

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Feb 12, 2009
Posts: 10
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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Feb 12, 2009
Posts: 10
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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Feb 12, 2009
Posts: 10
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.
Bruce Riches
Greenhorn

Joined: Apr 24, 2006
Posts: 14
This may help you.
Wrap the row in your table like this:
<h:commandLink title="Show member detail" action="#{linkBean.linker}" immediate="true" >
<hutputText 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.
 
 
subject: data table- row selection