JSF :: Passing Selected Hyperlink Value As Where Clause Argument In Query
Dec 28, 2013
I have a mySql table of PROJECTS, which I am displaying as a list in the index.xhtml. The projectid column contains hyperlinks. When they're clicked I would like the specific projectid row selected to be passed as the query argument into another jsf file (ListProjects.xhtml) which displays all the project values referring to the projectid selected in the index.xhtml. The named query is:
@NamedQuery(name = "Projects.findByProjectid", query = "SELECT p FROM Projects p WHERE p.projectid = :projectid")
index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
[Code] ....
I get the following stack trace. How to correctly pass the hyperlink parameters.
org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke public void com.manaar.beans.SelProjectMgtBean.init() on com.manaar.beans.SelProjectMgtBean@681859ae
at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:91)
I am trying to pass an object of type Product p to my editProduct method, however trying to call p.getName(); doesn't work and throws a NullPointerException. The same kind of thing works for my displayRecord method (in a different class) and I can call .getName() on Product p, also passed as an argument to that method. Below is my editProduct class. The NullPointerExcepion is being thrown at line 61 (i.e., nameField.setText(p.getName());).
I don't know if I explained right, so here's a line thing of how the classes relate:
And as a side note: adding the line p = new Product(); fixes it and successfully runs the class (including the Save and Quit parts) but obviously I want it to specifically refer to the Product I pass to the method.
I'm asking a question because I don't understand how Product p could possibly be null, because the argument is passed through my DisplayRecord class, which also takes a Product p argument and works. In that class, I have declared Product prod = p; and prod is what I am passing to editProduct.
i wrote a program , who can i read the mails from my gmail account. My wish is, mails with DOI mail activated with javax.mail automatically print the mail body too. Util now, I could not, unfortunately.
Can we pass array as a cmd line argument as follows ?
>java TestRun file[], number if yes, in the main(), how do we capture this array ? public static void main(String [] args){ String [] files = args1 ; // or will it be String [] files = args1[]; }
So I have an application where the user logs in (using j_security_check). User is taken to a welcome page where user's name is displayed as a link. When clicking that link I would like to take the user to a page where the user is able to update the credentials (password, address, etc). In this way the user only has access to the link related to that specific user's credentials. I am trying the following structure:
public String selectedUser() { userName = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(userName); selUser=uServ.findByName(userName); return "UpdateUser";
[Code] ....
The last line of the stack suggests that a null PK value is being picked up by the FacesContext method in the backing bean. I'm confused because the userName string IS the primary key of the user table which is structured like this:
I am trying to create a class to read data from the JOptionPane. I am trying to create a general procedure and then be able to overload it using the rest. Basically I just want to call the procedure readString with options and without options while verifying that the user entered the correct information.
Java Code: public class BankIO { public static final Object[] mainMenu = {"1. Create Account", "2. Delete Account", "3. Update Account", "4. Display Information", "5. Quit"}; public static final String APPLICATION_NAME = "Banking Pro";
I am having a problem with a PreparedStatement for a MySQL query, where the query seems to get cut off. I can't really post a self contained example, because it involves an SQL database.The part of the code with the problem...
Java Code:
public void insertEntry( Hashtable<String, String> strings, Hashtable<String, Integer> integers, Date created, Date paid, boolean enabled) throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver");
[code]....
The output of the whole program, though all it has done so far is create some default values and attempt to insert them with the above code, where the problem occurs.
Debug: SQLpaid = 1990-03-21
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT enabled=0, username='default_username', created='2000-03-21', paid='1990-' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:45)
I am using a IN clause in Oracle DB to pass a collection of custId to retrieve the customer details. If it was 10 or 50 custId's as a collection in IN clause it works fine. But if the collection grows bigger to 500 or 1000 then it is pretty slow to load the JSP page with the customer details.
Here is the query:-
select CustName, CustAge, CustCity, CustPin from CUSTOMER where custId IN (....)
The list of custId that is passed through Hibernate query.setParameterList()
How to optimize this query to make sure it displays the customer details faster even if the collection of elements which we pass is huge?
what is the use of checked exception.I know unchecked exception or Runtime exception are thrown by jvm whenever programmer makes any mistake in logic and current thread is terminated.But checked Exception are checked at compile time so that compiler compels programmer to put risky methods in try catch clause. And this checked Exception are caused due to problem in IO operation or any such operation which the programmer can't control.Programmer can't do anything to avoid this checked exception but can catch this exception.
Now the question is Why compiler compels checked exception to be put in try catch clause but doesn't complain anything in case of Runtime Exception???
now, i want to access a managed bean's method to execute a service call related to the code embedded in the hyperlink.
My Managed bean
@ManagedBean(name="details") @SessionScoped public class XXXX extends Bean implements Serializable{ public XXXX(){...... } public myMethod(..){ service.getDataRelatedToHyperlinkCode(....passing code here to fetch details from DB) } }
if i use postConstruct annotation it is getting executed only once since it is a session scope. and point to be noted is i cannot use viewscope and requestscope.
This is a part of my program. When the user enters "Exam Schedule" in the JtextField and clicks the add button I want the link to change to a link that opens a local pdf file. And if the user enters "Academic Calendar" the Jlabel will be set to another link. So far this works fine but the problem is that if you erase the textfield and enter another value the link of the previous value will still be there.
public void actionPerformed (ActionEvent e){ if (e.getSource ==add) { if (text.getText().equalsIgnoreCase("Exam Schedule")){ link1.setText(text.getText()); link1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
This is a part of my program. When the user enters "Exam Schedule" in the JtextField and clicks the add button I want the link to change to a link that opens a local pdf file. And if the user enters "Academic Calendar" the Jlabel will be set to another link. So far this works fine but the problem is that if you erase the textfield and enter another value the link of the previous value will still be there.
public void actionPerformed (ActionEvent e){ if (e.getSource ==add) { if (text.getText().equalsIgnoreCase("Exam Schedule")){ link1.setText(text.getText()); link1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
I was giving a quick skim to some tutorials on the internet where I have found the exception that is handled is also declared in the throws clause of the method wrapping the try-catch block. For a code representation consider the following:
public void methodName() throws IOException { try { ... } catch (IOException ex) { .... TODO handle exception }
i am doing a code using JSTL to fire a query. everything come fine except the resule is not sorted as desired. i am putting the code below--
String sort_order=(String)request.getAttribute("sort_order"); request.setAttribute("sort_order",sort_order); <sql:query var="viewQueryj" sql= "select USER_ID, PERMISSION_ID, USER_NAME from administrator order by ?"> <sql:param value="${sort_order}"/> </sql:query>
now the resule is always sorted by USER_ID. if i want to sort it using USER_NAME i pass parameter from controller to this page in sort_oredr variable which comes fine but the result doesn't sort by name, only by id. if i hardcode USER_NAME in query then the result is as desired.
i found some problem for this jsp code. Actually I'm new in jsp. I'm trying to insert some data in a sql table in jsp by user input. Here's my code but i couldn't completed it.
I have done 90% of the coding however i am stuck with producing the output, i just cant get the user fields to show.
I have attached a picture of the output that is required. The program consists of two classes i have attached the database class, and have inserted my coding below.
import java.sql.*; import java.io.*; import java.util.*; public class QueryDB { private Connection con = null; String userID,
I seem to be having a issue with my java console app what it should do is query a SQL DB and list the user details (userid, firstname ,lastname) from the user table, and the users stocks (stockname ,stockdiscription) associated to each user from the userstocks table if I'm thinking correctly!
I'm sure it is just a logical error, but I'm not sure of the way to get the out put I'm looking for. I will add the makeDB.java file and DatabaseQuery.java file as well as the current Exception(Run Time Exception) below.
**I have added other users and stocks manually - Not just what the MakeDB.java file inserts **
Output and Exception:
Stock holdings by User User ID User Name Stock - Description ------------------------------------------- admin01 Default Admin Exception in thread "main" java.sql.SQLException: ResultSet is closed at sun.jdbc.odbc.JdbcOdbcResultSet.checkOpen(JdbcOdbcResultSet.java:6647 ) at sun.jdbc.odbc.JdbcOdbcResultSet.next(JdbcOdbcResultSet.java:1248) at DatabaseQuery.main(DatabaseQuery.java:45) Press any key to continue . . .
Java Code:
MakeDB.java: import java.sql.*; import java.io.*; public class MakeDB { public static void main(String[]args) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
I have to get my output to show as per the image attached i am very close but not there yet. I have also attached the database where i extract my information from
/* Program Name: QueryDBDB.java Purpose: to build an initial database for the stocktrakcer application */
import java.sql.*; import java.io.*; import java.util.*; public class QueryDB { private Connection con = null; String userID,firstName,lastName,name,symbol; public QueryDB() throws Exception
I have a Stock Database query class, it compiles and runs well. Thing is when i enter a user, it shows a user stock information but it repeats showing the same user in the command prompt. the repetition is so fast, you can't see the information. All i wanted was the application to show a user's info, then asks you to enter another user again and so forth. Here is the code
import java.io.*; import java.sql.*; import java.util.*; public class StockDatabaseQuery { public static void main(String[] args)throws Exception { String userID; String firstName;
My console SQL Query app is not giving me the desired output.I am sure its might have something to do with my SQL Query.Its missing the description of the stock items and it prints a new line for each user as per number of stocks an repeats the user details and then prints the stock listed by that user(only want the user listed once with all its stocks). I will add my files and current output and desired out put below.
MakeDB.java:
import java.sql.*; import java.io.*; public class MakeDB { public static void main(String[]args) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url="jdbc:odbc:StockTracker";
I have code which query value from database, the use case is the user can enter value as 1,01,11 in database but when the user enter value in xml file he can only enter 11,01,12 in database there is two columns lets say column test1=1 and test2=2 combination of this is 12, which is the value the use will enter in xml, but sometime the use can enter test1=04 than column test2=00 how can i approach this
I got table called card with column crdind,crdpos1,cardpos2 as primary key. The user can enter value as
The rule say if you enter one number in crdpos1 eg 2 than you must enter value in crdpos2 it can be any number 1-9 but if you enter 00-09 in crdpos1 than crdpos2 is 00
The challenge I have is to query this value after they been enter. I have xml file which got field crdpos the use enter 15 which is the combination of column crdpos1=1 and crdpos2=5 ... How can I split the value crdpos and got and able to query in database in two separate column ....
In my JSP I need to retrieve some data from MySQL. I need to assign a "email" variable to the "WHERE" clause. The variable is retrieved from the session attribute. So far, I have this code:
<sql:query dataSource="${user}" var="result"> SELECT * from users where email = ${sessionScope.email}; </sql:query>
import java.util.Scanner; public class GetUserInput { public static void main (String args[]) { int i; float f ; String s;
[code]....
My Query is: input.nextLine() does not wait for user input. Instead it continues execution from next line. But if I move up input.nextLine(); before both input.nextInt(); and input.nextFloat() in the above code, the execution works fine, input.nextLine(); waits for user input. edited code and output are as follows.
import java.util.Scanner; public class GetUserInput { public static void main (String args[]) { int i; float f ; String s;
My output of my app its outputting the correct data just no the format ...
code :
DatabaseQuery.java : import java.io.*; import java.sql.*; import java.util.*; public class DatabaseQuery
[Code] ....
Current output:
Stock holdings by User
User ID User Name Stock - Description ------------------------------------------- admin01 Default Admin DELL Dell Computer Corp admin01 Default Admin MSFT Microsoft Computer Corp
[Code] ....
Desired Output :
Stock holdings by User
User ID User Name Stock - Description ------------------------------------------- admin01 Default Admin DELL Dell Computer Corp MSFT Microsoft Computer Corp ORCL Oracle Corp