我正在尝试使用Omnifaces实现ViewScoped CDI bean。使用jsf页面中的ajax调用使用搜索结果填充listface数据表的Bean方法。如果bean范围设置为session,则一切正常。当我尝试将范围设置为Omnifaces ViewScope时,容器开始多次创建和销毁bean,没有任何理由。这是bean代码:
...
import javax.inject.Named;
import org.omnifaces.cdi.ViewScoped;
@Named
@ViewScoped
public class FindClientBean implements Serializable {
@Inject
private ClientDAO clientDAO;
@NotNull(message="Search string cannot be empty")
private String searchString;
private List<Client> resultList;
@PostConstruct
public void init() {
System.out.println("init");
}
@PreDestroy
public void end() {
System.out.println("end");
}
public void findClient() {
System.out.println("method");
resultList = clientDAO.findClientByNameOrLastnamePart(searchString);
}
//Getters and setters..
}
示例输出(一个方法调用有更多的内部和结尾,我跳过了它们):
01:51:50,044 INFO [stdout] (http-localhost-127.0.0.1-9090-5) init
01:51:50,044 INFO [stdout] (http-localhost-127.0.0.1-9090-4) init
01:51:50,044 INFO [stdout] (http-localhost-127.0.0.1-9090-5) end
01:51:50,045 INFO [stdout] (http-localhost-127.0.0.1-9090-4) end
01:51:50,045 INFO [stdout] (http-localhost-127.0.0.1-9090-5) init
01:51:50,045 INFO [stdout] (http-localhost-127.0.0.1-9090-4) init
01:51:50,046 INFO [stdout] (http-localhost-127.0.0.1-9090-5) end
01:51:50,046 INFO [stdout] (http-localhost-127.0.0.1-9090-4) method
01:51:50,047 INFO [stdout] (http-localhost-127.0.0.1-9090-5) init
01:51:50,047 INFO [stdout] (http-localhost-127.0.0.1-9090-5) end
01:51:50,048 INFO [stdout] (http-localhost-127.0.0.1-9090-5) init
01:51:50,048 INFO [stdout] (http-localhost-127.0.0.1-9090-5) end
01:51:50,049 INFO [stdout] (http-localhost-127.0.0.1-9090-5) init
01:51:50,049 INFO [stdout] (http-localhost-127.0.0.1-9090-5) end
它可以是什么?没有找到相关问题。 我的配置:JBoss AS 7.1,Omnifaces 1.6.3,Primefaces 4.0
答案 0 :(得分:1)
我遇到了同样的问题。它对我不起作用的原因是,在我的项目属性中 - &gt; Project Facets是3.0版的动态Web项目
但在web.xml中项目保存为2.5
所以我只是将2.5改为3.0看起来像这样:
<?php
$username = "some username";
$password = "some password";
$hostname = "localhost";
$databasename = "some database";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
@mysqli_select_db($databasename,$dbhandle);
//select a database to work with
$selected = mysql_select_db("mydeos_calendar",$dbhandle)
or die("Could not select mydeos_calendar");
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM appointments ");
$num=mysql_numrows($result);
mysql_close();
echo"<br><b><center>All Appointments</center></b><br><br>";
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// print them one after another
echo "<table cellpadding=10 cellspacing=3 border=1 class=sortable>";
echo "<tr><th>Date/Time</th><th>LEP</th> <th>Language</th> <th>Insurance</th><th>Nature</th><th>Duration</th><th>With</th><th>Vendor</th><th>Status</th><th>Appointment Type</th><th>Actions</th></tr>";
while($row = mysql_fetch_row($result)) {
require "appointmentrows.php";
echo '<td><a href="something">Edit</a> | <a href="something">Delete</a></td>';
echo "</tr>"; }
echo "</table>"; }
else {
// print status message
echo "No Appointments Found!";
}
$i=0;
while ($i < $num) {
$appointment=mysql_result($result,$i,"appointment");
$nature=mysql_result($result,$i,"nature");
$duration=mysql_result($result,$i,"duration");
$status=mysql_result($result,$i,"status");
$language=mysql_result($result,$i,"language");
$lep=mysql_result($result,$i,"lep");
$vendor=mysql_result($result,$i,"vendor");
$insurance=mysql_result($result,$i,"insurance");
$client=mysql_result($result,$i,"client");
$invoiceformat=mysql_result($result,$i,"invoiceformat");
$appointmenttype=mysql_result($result,$i,"appointmenttype");
$i++;
}
?>