AJAX SelectOneMenu use
bp2s Oct 29, 2009 11:36 AMhi
i've got a rich:toolbar:
<rich:toolBar> <rich:toolBarGroup location="left"> <h:outputText style="text-align: center" value="Select node " /> <h:selectOneMenu id="nodes" value="#{Welcome.chosenNode}"> <f:selectItems value="#{Welcome.nodes}" /> <a4j:commandButton value="Retrieve" reRender="nodeConfig" /> </h:selectOneMenu> </rich:toolBarGroup> </rich:toolBar> <h:panelGroup id="nodeConfig" rendered="#{not empty Welcome.chosenNode}"> <rich:tabPanel switchType="client"> <!-- has to be client - i want all data there --> <rich:tab style="font-weight: bold;" label="#{Welcome.chosenNode} Global Settings"> Here is tab #1 </rich:tab> <rich:tab style="font-weight: bold;" label="File-Message Settings"> Here is tab #2 </rich:tab> </rich:tabPanel> </h:panelGroup>
and in my backing bean, public class Welcome {
<snip> private ApexConnect acon = new ApexConnect(); <snip> public List<SelectItem> getNodes() { nodes = acon.readColumn(); return nodes; } public void setNodes(List n) { nodes = n; } public String getChosenNode() { return chosenNode; } public void setChosenNode(String n) { this.chosenNode = n; System.out.println(n); }
The class ApexConnect makes a connection to an oracle db.
When the page loads, my dropdown menu of nodes is shown, correctly output from the db. But when I select a node and hit 'Retrieve', the app crashes.
From the log, a second OracleDataSource() object is being instantiated. When it gets to the fairly standard
pstmt = conn.prepareStatement("SELECT * FROM " + dbTable);
line that's where it dies:
java.lang.NullPointerException
myPkg.ApexConnect.readColumn(Unknown Source)
myPkg.Welcome.getNodes(Unknown Source)
is the error.
As it's tiered, my app will need to read the db table once per HTTP client connection to the app (ie so a refresh gets new nodes added to the db) but I only want one DB connection.
How can I maintain this first connection to the database so manipulating the SelectOneMenu doesn't cause problems and selecting a item in the dropdown list allows me to act on it? The app thinks the oracle data source member is null when the commandButton is hit.
Thanks IA
M