• Post Reply Bookmark Topic Watch Topic
  • New Topic

Target Unreachable  RSS feed

 
prats evik
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey i am trying to built this simple ecommerce site using jsf..but i am getting this Target Unreachable, identifier 'CustomerBean' resolved to null error..

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Product;

import javax.annotation.ManagedBean;
import javax.annotation.Resource;
import javax.faces.bean.RequestScoped;

/**
*
* @author
*/
//@ManagedBean(name="customerBean")
@RequestScoped
public class CustomerBean {

public String fname;
public String lname;
public String add;
public String card;
@Resource(name="jdbc/addressbook")


public String getAddress() {
return add;
}

public void setAddress(String address) {
this.add = address;
}

public String getFirst() {
return fname;
}

public void setFirst(String first) {
this.fname = first;
}

public String getInfo() {
return add;
}

public void setInfo(String info) {
this.add = info;
}

public String getLast() {
return lname;
}

public void setLast(String last) {
this.lname = last;
}
public String getResult() {
if (fname != null && lname != null && add != null && card != null) {
return "<p style=\"background-color:yellow;width:200px;" + "padding:5px\"> First Name: "
+ getFirst() + "<br/>Second Name: " + getLast() + "<br/>E-Mail: "
+ getAddress() + "<br/>Phone: " + getInfo() + "</p>";
}
return "confirmation";
}
}

this is the bean code


<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
<head>
<title>Customer information</title>
</head>
<body>
<h:form>
please enter information below:<br/>
First name: <h:inputText id="fname" required="true" value="#{CustomerBean.first}"/><br />
Last name: <h:inputText id="lname" required="true" value="#{customerBean.last}"/><br />
Address:<input type="text" name="add" required="true" value="#{customerBean.address}"/><br/>
your card information:<input type="text" required="true" name="card" value="#{customerBean.info}"/><br/>
<input type="submit" value="Submit" action="#{customerBean.result}"/>
</h:form>
</body>
</html>
this is the html file..

if any one could tell me what am i doing wrong it would be great!
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Useful hint: The message editor has a "Code" button that inserts special tags around Java code, XML, and other formatted data. It makes things a lot easier to read.

Your attempt failed because:

1. You commented out the ManagedBean attribute. If you don't have that attribute enabled and you didn't do its equivalent in faces-config.xml, you won't have defined the bean to JSF.
2. You referenced the bean via its class name (CustomerBean), not its instance name (customerBean). Therefore, the bean instance was not found.
3. You used Request scope. OK, that's not actually the primary problem, but Request scope is almost entirely useless in JSF because of how JSF works. Unless you know exactly what the consequences are, avoid Request scope. View Scope is generally better for things that would be in Request scope for non-JSF apps.
 
prats evik
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried you doing the changes what you said but now i am getting this error at @ManagedBean(name="customerBean")
cannot find symbol
symbol: method name()
location: @interface javax.annotation.ManagedBean
what is wrong here..
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure why the error message, but since your bean name is the same as the classname, you can remove the "name" attribute and just code it like this:


The annotation processor will automatically create a bean whose name is the same as the classname except for the required lower-case initial character. Which means, that if the bean classname is "CustomerBean", the annotation processor will ensure that a managed bean named "customerBean" is created by default.
 
prats evik
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am still getting the target unreachable error
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to be missing the "f:view" tags on your page definition. Also, you referenced beans named "customerBean" AND "CustomerBean". The bean name is case-sensitive, and, as I said earlier, the proper capitalization is "customerBean".
 
prats evik
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
<head>
<title>Customer information</title>
</head>
<body>
<h:form>
please enter information below:<br/>
First name: <h:inputText id="fname" required="true" value="#{customerBean.first}"/><br />
Last name: <h:inputText id="lname" required="true" value="#{customerBean.last}"/><br />
Address:<input type="text" name="add" required="true" value="#{customerBean.address}"/><br/>
your card information:<input type="text" required="true" name="card" value="#{customerBean.info}"/><br/>
<input type="submit" value="Submit" action="#{customerBean.result}"/>
</h:form>
</body>
</html>
-------------------------------------------------------------------------------------------------------------------------------------------------

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Product;

import javax.annotation.ManagedBean;
import javax.annotation.Resource;
import javax.faces.bean.RequestScoped;

/**
*
* @author ppk5032
*/
@ManagedBean
@RequestScoped
public class CustomerBean{

public String fname;
public String lname;
public String add;
public String card;
@Resource(name="jdbc/addressbook")



public void setAddress(String address) {
this.add = address;
}
public String getAddress() {
return add;
}


public void setFirst(String first) {
this.fname = first;
}
public String getFirst() {
return fname;
}




public void setInfo(String info) {
this.add = info;
}
public String getInfo() {
return add;
}



public void setLast(String last) {
this.lname = last;
}
public String getLast() {
return lname;
}
public String getResult() {
if (fname != null && lname != null && add != null && card != null) {
return "<p style=\"background-color:yellow;width:200px;" + "padding:5px\"> First Name: "
+ getFirst() + "<br/>Second Name: " + getLast() + "<br/>E-Mail: "
+ getAddress() + "<br/>Phone: " + getInfo() + "</p>";
}
return "confirmation";
}
}

this is what it looks like after making the changes..but i am still getting the error
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!