Steven Gray

Greenhorn
+ Follow
since Mar 26, 2006
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Steven Gray

I have a datatable where I want users to be able to numerically rank their selections. After they submit their selections, the database is updated to reflect their choices.
Example:
Please rank the people you would like to meet with:

__ John
4 Sally
__ Bill
1 Tom
3 Sue
__ Dana
2 Pete

In this example the user has indicated that their first choice is to meet with Tom, their second choice is to meet with Pete, etc. They do not wish to meet with John, Bill or Dana.

This works fine if I have a datatable with a scroll bar. I would like to allow the users to page through their selections using a datascroller before they submit their choices. The problem is that any choices entered by the user are lost when they scroll to a new page. If I am correct, this is because the backing bean is in request scope and the contents are refreshed when the user uses the datascroller. Is there a way to have the datatable retain any user edits while paging through the data? Any insight would be appreciated.
11 years ago
JSF
After doing some more searching, I found the problem. I am using MyEclipse for doing my JSF development. MyEclipse includes the JSF 1.1.01 Reference Implementation. This version of JSF has a known bug where h:commandLinks do not work inside an h:dataTable. Changing the h:commandLink to an h:commandButton solves the problem. My next step is to visit the MyEclipse forums to see if there are any issues with including a later version of the JSF libraries in my project.
11 years ago
JSF
I have a JaveServer Faces page called setupUserLogin.jsp (code below.) I want the user to click on a command link for the row the user wants to edit. Clicking on the link would navigate them to the edit screen editUserLogin.jsp.

If I place the link outside of a row in my datatable it works as expected. See code labeled "This Works" The same code when placed in a column for the datatable never invokes the backing bean and just navigates to http://localhost:8080/TEC/# which displays index.jsp - the main web page for the application. See code below labeled "This does not work"

Any idea what I am doing wrong?


setupUserLogin.jsp



Relative portion of SetupUserLogin.java



Relative portions of faces-config.xml
11 years ago
JSF
Hi Tim,
I solved my problem! My custom JSF component was successfully generating the JavaScript, but I did not think the JavaScript was executing. After some detailed digging,
I discovered a subtle typo in the JavaScript I was generating. I fixed the typo and it started working. Thanks for your help!
11 years ago
JSF
I think I see what you mean, but as I am progressing on this, I have another question. I am creating a JSF custom UI component that the user can drop onto their web page. Basically I want it to prompt the user every N minutes if they want to extend their session. If they answer yes, it extends the session and writes a message to the web page where the component has been placed on the page. I have the code working correctly that generates the Java Script on the page. But I need to know how to "kick off" the Javascript code when the page is being displayed for the first time. Here is what I end up with when the component is created:

<td >
<span id="_id1:sessionStatus" class="StatusMessage"></span>
<script type="text/javascript">
var reqXML;
function LoadXMLDocurl){
if (window.XMLHttpRequest){ //Mozilla, Firefox, Opera 8.01, Safari
reqXML = new XMLHttpRequest();
reqXML.onreadystatechange = BuildXMLResults;
reqXML.open("GET", url, true);
reqXML.send(null);
}
else if(window.ActiveXObject){ //IE
reqXML = new ActiveXObject("Microsoft.XMLHTTP");
if (reqXML) {
reqXML.onreadystatechange = BuildXMLResults;
reqXML.open("GET", url, true);
reqXML.send();
}
}
else{ //Older Browsers
alert("Your Browser does not support Ajax!");
}
} function BuildXMLResults(){
if(reqXML.readyState == 4){ //completed state
if(reqXML.status == 200){ //We got a success page back
alert(reqXML.responseText);
if(reqXML.responseText.indexOf("Session Updated - Server Time:") >= 0){
//window.status = reqXML.responseText; //display the message in the status bar
SetTimer(); //restart timer
}
else{
alert(reqXML.responseText);
//display that that session expired
alert("Your session appears to have expired. You may loose your current data.");
}
}
else{
//display server code not be accessed
alert("There was a problem retrieving the XML data:
" + reqXML.statusText);
}
}
}
function ConfirmUpdate(){
//Ask them to extend
if(confirm("Your session is about to expire. Press 'OK' to renew your session.")){
//load server side page if ok
LoadXMLDoc('sessionUpdater.jsp');
}
}
var timerObj;
function SetTimer(){
//How long before timeout (should be a few minutes before your server's timeout
var dblMinutes = 1;
//set timer to call function to confirm update
timerObj = setTimeout("ConfirmUpdate()",1000*2*dblMinutes);
}
//start the timer
SetTimer();
</script>
</td>

I realize this code is not 100% correct yet. For example, I will have to change the following line in the function BuildXMLResults to write something to the JSF page.
window.status = reqXML.responseText;

My question is how do I modify my JSF custom code to automatically run the Javascript code I generated?

The examples I have seen attach the Javascript to something like the "onkeyup" event for an Input Text Box. In my case, I want the code to start automatically when the page opens. Any suggestions? Thank you In Advance.
11 years ago
JSF
I am a newbie to AJAX. I want to prompt a user before their session is invalidated so they can stay logged in. I have seen an example online for jsp:
Update User's Session With Ajax
I am trying (unsuccessfully) to adapt this for use in a MyFaces application.
My question is where should I place the JavaScript code to start the timer. Should it be in the page header like Eric has in his example?
<html>
<head>
<title>sessionTimeout</title>
<script type="text/javascript" src="SessionWarningTimer.js"></script>
</head>
<body>
<form id="Form1" method="post">
</form>
</body>
</html>

Or should it be invoked from a body onload tag:
<BODY onLoad="SessionWarningTimer.js">

Or should it be invoked using a Phase Listener. If so, what phase?

Thanks in advance.


11 years ago
JSF
Thanks for all the help! I got the phase listener working. After the user logs in, they are displayed an instructions page (instructions.jsp) with a backing bean (InstructionPageBean.java). I have the backing bean coded to go out to the database and fetch the name of the image file to be displayed. Now my problem:

After logging in, the instructions page opens, but without displaying the image file.

If I click on the browser's refresh button, the image displays correctly. What am I doing wrong? Is InstructionPageBean's constructor getting called after the view is rendered for instrucions.jsp? Any help would be appreciated.

Here is the relevant code:

faces_config.xml - UserBean is a backing bean for the login screen (login.jsp).
InstructionPageBean is a backing bean for instructions.jsp.

UserBean.java

InstructionPageBean.java



instructions.jsp


[ March 30, 2006: Message edited by: Steven Gray ]
[ March 30, 2006: Message edited by: Steven Gray ]
16 years ago
JSF
Hi Tim,
I have a question that is also related to page initialization.

I have a web site that is database driven. When a user logs in, their profile is looked up in a database and is used to determine the next page to be displayed. For example, an administrator might be taken to a page that allows them to run special admin reports. If a user is registering for a conference, the registration is customized based on the conference being registered for. If the user is registering for conference X, conference details are retrieved from the database before the registration page opens. When the user sees the registration page it might say:
National Association Of Space Engineers New Ideas Conference
May 3 - 7 2006
Registration begins April 1, 2006

I understand how a backing bean can be used to display these values, but when and how would these values be obtained?

Thanks In Advance
Steven
16 years ago
JSF