春、JSF2、および休止状態を新しいプロジェクトに統合しようとしていますが、遅延ロードされたコレクションに問題があります。これが私の問題の要約です。EL(JSF)からのajax / PPRリクエストを介して(フェッチ= Lazyを使用した休止状態から)遅延ロードする方法を理解しようとしています。
問題は、ビューが EL 経由で遅延ロードする必要があるコレクションにアクセスしようとしているが、リクエストが終了したためにオブジェクトが切り離されていることです (私は opensessioninviewfilter を使用しています)。多くの短い ajax-y リクエストで PPR を使用する場合、データを遅延ロードする方法はありますか?
この例では、複数のドメイン オブジェクトをリストしようとしています。部分ページ レンダリングでは、ビュー スコープ Bean を使用して、オブジェクトの 1 つを選択し、それに関する詳細を表示して、場合によってはそれを更新したいと考えています。私のアプリケーションでの一般的な情報の流れは次のようになります。
*ドメイン オブジェクトのリストがロードされ、ap:datatable に入力されます。ドメイン オブジェクトは、ビュー スコープのバッキング Bean のリストに格納されます。
*ユーザーがアイテムをクリックして編集すると、viewscoped Bean で ajax/PPR を使用して、workingItem と呼ばれるバッキング Bean の変数にアイテムがロードされます。
*通常、項目はダイアログ (通常は Primefaces p:dialog) に読み込まれますが、これも ajax で行われます。*ここで物事が崩壊します。ドメイン オブジェクトに遅延ロードされるコレクションがある場合 (おそらく ap:selectOneMenu を設定するため)、常に LazyLoadingException がスローされます。
したがって、私の質問は、ajax 呼び出し中にプロキシがアクセスされたときに、遅延ロードされたコレクションをロードするにはどうすればよいかということです (デタッチされたオブジェクトを再アタッチする機会がない場合)。
*これを回避するために熱心なフェッチを使用することはできません。オブジェクト グラフが非常に大きく、セッション情報を他のサーバーに複製する必要があります。
*Spring の opensessioninviewfilter を使用していますが、この場合に役立つとは思いません (右?) *私の根本的な問題は、ドメイン オブジェクトをセッションにアタッチして遅延読み込みを行う方法がわからないことです。 UI がドメイン オブジェクトのプロパティを取得しようとしたとき。
ajax が頻繁に使用されている場合、(休止状態を使用した) 遅延読み込みは非常に難しいことがわかりました。任意の推奨事項、提案をいただければ幸いです。
ここに私のバッキングビーン(ジェネリック)があります:
@Component
@Scope("view")
public abstract class CrudBean<T extends DomainObject,U extends CrudService> extends AgoraBean implements Serializable
{
private static final Logger logger = LoggerFactory.getLogger(CrudBean.class);
protected U crudService;
protected T workingItem;
protected List<T> cachedItems;
protected List<T> filteredList;
public abstract String createWorkingItem();
public void setWorkingItem(T item)
{
workingItem = item;
}
public T getWorkingItem()
{
return workingItem;
}
public List<T> getAllItems()
{
if ( cachedItems == null )
{
cachedItems = getCrudService().getAllItems();
}
return cachedItems;
}
/* Other crud-dy stuff removed */
}
以下は、私のドメイン オブジェクトの 1 つの例です。
@Entity
@Table(name = "sites" )
public class Site implements Serializable, DomainObject {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(updatable = false, nullable = false)
private Long id;
@Version
private Integer version;
@Column(length=255,nullable=false)
private String name;
@Column(length=25)
private String abbreviation;
@Column(length=100)
private String street;
@Column(length=100)
private String city;
@Column(length=2)
private String locationState;
@Column(length=10)
private String zip;
@Column(length=20)
private String phone;
@Column(length=20)
private String fax;
@Column(length=50)
private String contactEmail;
@Index(name = "idxSitePublished")
private boolean published;
@Index(name = "idxSiteDefault")
private boolean defaultSite;
@ManyToOne
private Header header;
@ManyToMany
@Fetch(FetchMode.SELECT)
@BatchSize(size=5)
@OrderBy("priority ASC")
private List<Script> scripts;
@ManyToMany
@BatchSize(size=5)
@OrderBy("priority ASC")
private List<Style> styles;
}
そして私の Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-context.xml</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>home</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
60
</session-timeout>
</session-config>
<!-- Listeners - Spring should come first because we need them for our listener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>net.dupage88.www.servlet.SiteServletContextListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/public/index.html</location>
</error-page>
<!--<error-page>
<error-code>404</error-code>
<location>/public/404.jsf</location>
</error-page>
<error-page>
<error-code>401</error-code>
<location>/public/401.jsf</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/public/500.jsf</location>
</error-page>-->
<!-- For Lazy Loading -->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>RootRedirectFilter</filter-name>
<filter-class>net.dupage88.www.filters.RootRedirectFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RootRedirectFilter</filter-name>
<url-pattern>/index.html</url-pattern>
</filter-mapping>
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<listener>
<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
</web-app>
ヘルプやガイダンスをいただければ幸いです。事前に提供できるヘルプに感謝します。
ありがとう、チャック