我有一个网络服务并建立了一个客户端。我编写了一个 xhtml 页面,将姓名和电话号码发送到 Web 服务。如果我使用 Bean 使用 setter 和 getter 发送字符串,则 Web 服务会向客户端返回空值。如果我改为在函数中输入直接字符串,我会从 Web 服务中获取正确的字符串。
public void submit()
{ PhoneBookProxy.addEntries(name, phoneNum);}
这行不通。
public void submit()
{ PhoneBookProxy.addEntries("Jane Doe", "555 555-5555"); }
这确实有效。
这是为了家庭作业。感谢所有的帮助。
我正在使用带有 JDK 1.7 的 Netbeans
@ManagedBean
@NoneScoped
public class phoneBookClient {
private String firName, lasName, thphoneNum;
private PhoneBook PhoneBookProxy;
public phoneBookClient()
{
PhoneBook_Service service = new PhoneBook_Service();
PhoneBookProxy = service.getPhoneBookPort();
}
public void setFirstName(String fName)
{
firName = fName;
}
public String getFirstName()
{
return firName;
}
public void setLastName(String lName)
{
lasName = lName;
}
public String getLastName()
{
return lasName;
}
public void setPhoneNum(String phoneNum)
{
thphoneNum = phoneNum;
}
public String getPhoneNum()
{
return thphoneNum;
}
public void submit()
{
PhoneBookProxy.addEntry(getLastName(), getFirstName(), getPhoneNum());
}
public List<Object> getEntries()
{
return PhoneBookProxy.getEntries();
}
}
索引.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"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<title>Phone Book Client</title>
</head>
<body>
<h1>Please fill in all fields and click Submit</h1>
<h:form>
<h2>Please Enter your First Name</h2>
<h:inputText id="fnameInputText" required="true"
requiredMessage="Please enter your First name"
value="#{phoneBookClient.firstName}"
validatorMessage="Name must be fewer than 30 characters">
<f:validateLength maximum="30" />
</h:inputText>
<h:message for="fnameInputText" />
<br />
<h2>Please Enter your Last Name</h2>
<h:inputText id="lnameInputText" required="true"
requiredMessage="Please enter your Last name"
value="#{phoneBookClient.lastName}"
validatorMessage="Name must be fewer than 30 characters">
<f:validateLength maximum="30" />
</h:inputText>
<h:message for="lnameInputText" />
<br />
<h2>Please enter your phone number in format: (xxx) xxx-xxxx</h2>
<h:inputText id="phoneInputText" required="true"
requiredMessage="Please enter a valid phone number"
value="#{phoneBookClient.phoneNum}"
validatorMessage="Invalid phone number format">
<f:validateRegex pattern=
"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" />
</h:inputText>
<h:commandButton value="Submit" action="#{phoneBookClient.submit()}"/>
</h:form>
<ui:repeat var="list" value="#{phoneBookClient.entries}" >
<h:outputText value="#{list}" />
<br />
</ui:repeat>
</body>
</html>