prats evik

Greenhorn
+ Follow
since Apr 04, 2012
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 prats evik

can anyone tell me how can we consume a web service from a xhtml file?
here is my 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>Cost</title>
</head>
<body>
Zip code: <h:inputText id="zip" required="true"/><br />
Weight: <h:inputText id="weight" required="true"/><br />
Cost:<h:outputText id="cost" required="true" value=""/><br/>


<h:commandButton value="Submit" action="#{productBean.calculate()}"/>

</body>
</html>




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

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.annotation.Resource;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.sql.DataSource;
import javax.sql.rowset.CachedRowSet;////not working

/**
*
* @author pratik khivesara
*/
@WebService(serviceName = "NewWebService2")
public class NewWebService2 {
@Resource(name="jdbc/addressbook")

DataSource dataSource;
int weight;
int cost;
int zip;

/** This is a sample web service operation */
@WebMethod(operationName = "hello")

public String hello1(@WebParam(name = "zip") int txt,@WebParam(name = "weight") int txt2){
String result = "empty result";
try{
if (dataSource == null) {
result = "a";
throw new SQLException("Unable to obtain DataSource"); // checking whether the database is injected
}



Connection connection = dataSource.getConnection();//obtain a connectio

if (connection == null) {
throw new SQLException("Unable to connect to DataSource");//checking whether the connection is established
}
int cost=(txt+txt2)/12;
result=Integer.toString(cost);


}catch(Exception e){}
return result;

}
}

thanks!!
12 years ago
i am unable to display all the data present in the database in a table form.only the first row is displayed .the remaining four are not displayed.
here is the code

<?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"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Example</title>
</h:head>
<h:body>
<h:dataTable value="#{productBean.result}" var="item" cellpadding="10px" cellspacing="0">
<h:column>
<h:selectOneRadio id="radioButton#{product.id}">
<f:selectItem itemValue="b1" itemLabel="" />

</h:selectOneRadio>
</h:column>
<h:column>
<f:facet name="header">Product name</f:facet>
#{item.Products}
</h:column>
<h:column>
<f:facet name="header">Product link</f:facet>
#{item.Image_links}
</h:column>

</h:dataTable>
<h:commandButton value="submit" action=""></h:commandButton>
</h:body>
</html>




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

import java.awt.Container;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.annotation.Resource;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.sql.DataSource;
import javax.sql.rowset.CachedRowSet;
import javax.swing.JButton;
import test.NewWebService;

/**
*
* @author ppk5032
*/
@ManagedBean(name="productBean")
@RequestScoped
public class ProductBean implements Serializable
{

private String product;
private String image;
@Resource(name="jdbc/addressbook")
DataSource dataSource;

public String getImage() {
return image;
}

public void setImage(String image) {
this.image = image;
}

public String getProduct() {
System.out.println("fggf");
return product;
}

public void setProduct(String product) {
this.product = product;
}


public ResultSet getResult() throws SQLException
{
System.out.println("******* in get result");

if (dataSource == null)
{System.out.println("******* inside datasource");
throw new SQLException("Unable to obtain DataSource");
}
System.out.println("******* out get result");
Connection connection = dataSource.getConnection();

if (connection == null)
{System.out.println("*no datasource connection");
throw new SQLException("Unable to connect to the DataSource");
}
try {
System.out.println("inside try");

PreparedStatement statment = connection.prepareStatement("SELECT Products, Image_links FROM website");

ResultSet rs = statment.executeQuery();


CachedRowSet rowSet = new com.sun.rowset.CachedRowSetImpl();

rowSet.populate(statment.executeQuery());

return rowSet;

} finally {
connection.close();
}

}}

can any one tell me what is the problem here?thanks..!

12 years ago
JSF
<?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
12 years ago
JSF
i am still getting the target unreachable error
12 years ago
JSF
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..
12 years ago
JSF
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!
12 years ago
JSF