John Kilbourne

Ranch Hand
+ Follow
since Aug 22, 2001
Merit badge: grant badges
For More
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 John Kilbourne

I'm seeing a general solution in a sort of data-structures approach, but i don't know if I am over-complicating things.

There can be a function, called at onKlick() for each checkbox, that takes as a parameter the "modulus" or number of adjacent checkboxes that need to act like a radio group. The function unchecks any previously checked box that "collides" with a newly checked box in the same "block".

To be most general, it should probably take the array of checkboxes as a parameter as well as the modulus value. "numBlocks" is the number of blocks, so for a 12 element array of checkboxes with a modulus of 3, there are 4 blocks.

function CBRadioGroup(cbArray, modulus)

Iterate over cbArray using an inner and an outer loop:
for(outer = 0; outer < numBlocks; outer++){
for(inner= 1; inner <= modulus; inner ++){
var collisions = new Array()
when the inner loop finds a checked box, add its index location
(inner x outer) to collisions[collisions.length]
At the end of the inner loop, check the length of collisions[];
if it is > 1, there was a collision; the length should be 2.
Determine which of the two colliding indices was checked first.
Uncheck that box
End this iteration of the inner loop
End outer loop.

Determining which of the two colliding indices was checked earlier means compparing the current cbArray with the one used at the last onKlick()

If there is a simpler way, please tell me.
Here is the original jsp page for the code I posted:
[CODE}<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:import url="/WEB-INF/javascript/functions.js" />
<jsp:useBean id="roleGp" scope="session" class="bean.RoleGroupQueryBean"/>
<jsp:setProperty name="roleGp" property="*"/>

<html>
Give the value or range of values for each role<p>

<form name="roleValues" method="get" action="processRGValues.jsp">
<c:forEach items="${paramValues.rolesInGroup}"
var="role" varStatus="status">
<fieldset>
<table>
<tr><td>
<b><c :-o ut value="${role}"/></b><br>
</td><td>&nbsp <input type="checkbox" name="inGroup"
value="inGroup" checked="checked"
onclick="cBvalidate()" />
This role is in the group <br>
</td>
</tr>
<tr>
<td></td>
<td>&nbsp <input type="checkbox" name="inGroup"
value="notInGroup"
onclick="cBvalidate()" />
This role is not in the group <br>
</td>
</tr>
</table>
<br>
&nbsp <input type="checkbox" name="valRange"
value="allVals"
onclick="checkBoxValRange()"/>
ANY value of this role is OK
<br>
&nbsp <input type="checkbox" name="valRange"
value="oneVal"
onclick="checkBoxValRange()"/>
ONLY the value below is OK
<br>
&nbsp &nbsp<input type="text" name="roleVals" size="35"/>
<br>
&nbsp <input type="checkbox" name="valRange"
value="DescentVals"
onclick="checkBoxValRange()"
checked="checked"/>
The value above or any descendent is OK
</fieldset><p><p>
</c:forEach>
</form>

</html>[/CODE]
edited to better format the code)

There are two names, one for each group of checkboxes. Here is the page source for the generated code; I am using convoluted trial and error in my fxn cBvalidate() to find a way to check off one and only one of the top set of checkboxes. In my mind I feel I should be able to make a function to which I pass a parameter "modulus" that lets me make every _X_ checkboxes act like a radio group. For this application, the first group of checkboxes would have modulus 2 (there ar a pair of them), adn the second group would have modulus 3. I appreciate any help you can offer.
[ September 18, 2004: Message edited by: John Kilbourne ]
I have spent many hours on this problem, and can't seem to crack it. How can a checkbox in an array of checkboxes know which index is its home? The checkbox can pass up its corresponding form object, and the array of checkboxes, but how can an onKlick() function for a specific checkbox know that this checkbox is the 7th in a list of 12? The final number of checkboxes is not known ahead of time.

The user first selects from a multiple-select list; the multiple-select specifies the "names" in a set of name-value pairs, and the subsequent checkboxes and textfield specifies the range of values for each name. For each name there are two sets of properties to specify.

My first iteration of this did not permit the user to select a list of names, it only allowed one name. The additional properties were specified with radio buttons.

I can generate the checkboxes ok using c:forEach jsp tags, but I need to a way to make them act like sets of radio buttons. For each dynamically selected name, I have two groups of CB's ("groupA", "groupB") For each name, I want the user to pick one (and only one) from groupA and one and only one from groupB.

The web gave a few tantalizing hints:
http://javascript.internet.com/forms/select-one.html
http://javascript.internet.com/forms/limit-boxes.html
http://javascript.internet.com/forms/controlled-boxes.html
How do I get the actual session attribute object? I have a servlet that for various reasons needs to open a DB connection with each session, and I want to close those connections as the sessions time out. How do i get the actual Connection object that is the value of my session attribute, so I can call close() on it?
Thanks,
John
19 years ago
never mind; I see my question was answered in a thread about halfway down the page, about variable modifiers in methods.
I found a few questions VERY difficult; maybe it's just me. There was one about a subclass will override a superclass *method*, but not a data field named identically in the superclass and subclass.
I found a mock exam in PDF format involving declaring a staic variable inside a method. I retyped it (fixing the typos on the mock exam) and it won't compile, as I thought (contrary to the answer on the exam).

For my sense of reassurance, could someone tell me whether a static variable can be declared inside a method?
I solved it by putting a jar file into jre/lib/ext.
22 years ago
I am trying to call a class (RecordObj) that in turn calls another class (DBConnector) from my getPost() method in my servlet. I placed the two subordinate classes in a package in the directory holding my servlet class. This is my directory structure (Windows NT):
jswdk-1.0.1\examples\WEB-INF\servlets\Record
My servlet is in servlets\. The compiler will not compile my servlet because it cannot find the other two classes. It *can* find and compile the two subordinate classes with no problem though.
I've changed my CLASSPATH to point to servlets\ and ., and I tried putting all three classes together in the \servlets directory, removing their package declarations, but nothing so far seems to help.
22 years ago
I am accessing a db in a servlet and want to display all the rows of a table in a jsp, to divide the presentation from the logic. Essentially I want to pass an object (ResultSet rs) from the servlet to the jsp, so within the jsp I can call something like:
< tr>
while(rs.next())
< td>< %=Record.firstfield%>< /td>
< td>< %=Record.secondfield>< /td>
< /tr>

I am unclear on the use of a directive (syntax < @ page...%>
to import the needed packages as well as the classes and objects (like the ResultSet) instantiated in a separate servlet held in the same container.
I corrected the table stuff to prevent display problems.

[This message has been edited by Carl Trusiak (edited December 12, 2001).]
22 years ago
I am accessing a db in a servlet and want to display all the rows of a table in a jsp, to divide the presentation from the logic. Essentially I want to pass an object (ResultSet rs) from the servlet to the jsp, so within the jsp I can call something like:
< tr>
while(rs.next())
< td>< %=Record.firstfield%>< /td>
< td>< %=Record.secondfield>< /td>
< /tr>

I am unclear on the use of a directive (syntax < @ page...%>
to import the needed packages as well as the classes and objects (like the ResultSet) instantiated in a separate servlet held in the same container.
I corrected the table stuff to prevent display problems.

[This message has been edited by Carl Trusiak (edited December 12, 2001).]
22 years ago
JSP
Can somebody describe the differences and relationships among these methods? I have had a very difficult time getting a scrollpane to size correctly.
I have a program with selected code posted. Every second time through the client-server send-receive cycle, the client does not receive what the server sends.
In brief, client calls sendShowAll(), sending an int to the server which the server receives ok. The client also calls handleServerMessages, to listen for the server's reply.
The server, in a forever loop, receives the SHOWALL int and calls the single method sendShowAll(), followed by flush().
sendShowAll collects records using a JDBC Connection and assembles them into an array list. So far, all is well, the server verifies that it has done all these things. Since the array list is small, the server will send one partial packet. This is determined in sendShowAll, which then calls sendPartialPacket.
The server gets to here every time also, but something happens now that doesn't make sense. The server calls writeInt(PARTIALPACKET), and the client doesn't see it. This would tell the client to receive the partial packet and alter the data model for the table. The client only sees this message every second time this entire process iterates. Instead, the client sees BYE, a writeInt() call signaling that there is nothing more to send now, and the clilent needn't block on i/o.
I am baffled; please help if you can.
The client calls these two methods to update a table:
[code}
ch.sendShowAll();
model.handleServerMessages();[/code]
The server does this:{code]
while (true)
{
int command = in.readInt();
System.out.println("in main,command received: " +command);
switch(command)
{
case SHOWALL:
{
ServerRecord.sendShowAll(out,connection);
out.flush();
System.out.println("in AddressServer; showall sent");
} break;
case DELETE:
{
int recNum = in.readInt();
ServerRecord.deleteRecord(connection,recNum);
System.out.println("deleted rec " + recNum);
} break;
case UPDATE:
{
ServerRecord sR = new ServerRecord();
sR.readRecordFromSocket(in);
System.out.println("Updated "+ sR);
sR.updateDB(connection);
}
case NEW:
{
ServerRecord sR = new ServerRecord();
sR.readRecordFromSocket(in);
System.out.println(sR);
sR.writeNewRecordToDB(connection);
} break;
}//end switch
out.writeInt(BYE);
System.out.println("bye code sent");
[/code]
Then does this:
and this:
What makes a bean a bean; why are they special?
I've read that they are reusable software components, but that doesn't tell me much. When would you *use* them? Also, I get the sense that enterprise java beans are not the same as java beans. What is the scoop on that/
Thanks.
22 years ago