primefaces 버전 3.1.1, Mojarra 2.1.3, Netbeans 7.0.1, Glassfish Server 3.1을 사용하여 인스턴트 메신저를 작성하십시오.ViewScoped 빈은 내 dataTable에서 commandButton을 클릭 할 때마다 다시 생성됩니다.
내 테스트 응용 프로그램은 raw divs 및 css와 함께 상단, 왼쪽, 내용, 오른쪽 및 아래 레이아웃이있는 facelet 템플릿을 사용하고 있습니다. 사용자가 컨테이너 관리 jdbcrealm을 사용하여 로그인하면 해당 템플리트를 사용하는 주 index.html이 제공됩니다.
메뉴 패널에 내비게이션 메뉴를 추가하면 메뉴 항목을 클릭하면 센터 패널의 내용이 아약스로 업데이트됩니다. 센터 패널은 NavigationBean
을 사용하여 <ui:include>
에서 동적으로 업데이트됩니다.
페이지 clientList.xhtml
중 하나에서 <p:dialog>
을 표시하여 세부 정보를 볼 수있는 버튼이 있습니다. <p:dataTable>
입니다. 메신저 viewCoped 빈을 사용하여 dataTable에 표시된 데이터 목록을 보유합니다.
문제는 모든 행의 마지막 열에서 버튼을 클릭하면 대화 상자가 전혀 나타나지 않고 내 p:ajaxStatus
gif 이미지가 계속해서 롤링되는 문제입니다. netbeans와 함께 프로그램을 디버깅 할 때 생성자가 다시 호출되고 버튼을 클릭하면 이전 인스턴스가 사라 졌음을 알 수 있습니다.
이것은 내 index.xhtml
이며 facelets 템플릿을 사용합니다.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<ui:composition template="/BySalesAutomationTemplate.xhtml">
<ui:define name="title">
<h:outputText value="Facelet Index Page"></h:outputText>
</ui:define>
<ui:define name="top">
TOP
</ui:define>
<ui:define name="left">
<ui:include src="users/menu#{request.isUserInRole('ADMIN') ? 'Admin' : 'User'}.xhtml" />
</ui:define>
<ui:define name="right">
<h:outputText value="Cuba2 daan"></h:outputText>
</ui:define>
<ui:define name="maincontent">
<c:if test="#{navigationBean.page!=null}">
<ui:include src="#{navigationBean.page}.xhtml" />
</c:if>
</ui:define>
<ui:define name="bottom">
<center>2012</center>
</ui:define>
</ui:composition>
</html>
이 왼쪽 패널의 메뉴에서 링크를 클릭시 내 index.xhtml의 중앙 패널에 표시되는 clientList.xhtml
페이지입니다.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Client Listing</title>
</h:head>
<h:body>
<p>Client List</p>
<h:form>
<h:commandButton action="#{authBackingBean.logout}" value="Logout" />
</h:form>
<f:view>
<h:form id="formdetail" prependId="false">
<p:ajaxStatus>
<f:facet name="start">
<h:graphicImage value="images/loading.gif" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
<p:growl id="growl" showDetail="true"/>
<p:dataTable id="dtClientList" value="#{saClientController.lazyModel}" rowsPerPageTemplate="10,20,30,50"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
paginatorAlwaysVisible="false" var="item" paginator="true" rows="10">
<f:facet name="header">
<h:outputText value="Client List"/>
</f:facet>
<p:column filterBy="#{item.idSaClient}">
<f:facet name="header">
<h:outputText value="IdSaClient"/>
</f:facet>
<p:commandLink action="#{saClientController.showDetails(item)}" value="#{item.idSaClient}" target=":maincontent"/>
</p:column>
<p:column filterBy="#{item.saClientName}">
<f:facet name="header">
<h:outputText value="saClientName"/>
</f:facet>
<h:outputText value="#{item.saClientName}"/>
</p:column>
<p:column filterBy="#{#item.saClientAddress}">
<f:facet name="header">
<h:outputText value="SaClientAddress"/>
</f:facet>
<h:outputText value="#{item.saClientAddress}"/>
</p:column>
<p:column style="width:40px">
<h:panelGrid columns="3" styleClass="actions" cellpadding="2">
<p:commandButton id="selectButton" update=":formdetail:display" oncomplete="clientDialog.show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{item}" target="#{saClientController.selectedSaClient}" />
</p:commandButton>
</h:panelGrid>
</p:column>
<f:facet name="footer">
<h:outputText value="Client List"/>
</f:facet>
</p:dataTable>
</h:form>
<p:dialog id="clientDialog" header="Client Detail" widgetVar="clientDialog" resizable="false" showEffect="explode" hideEffect="explode">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<h:outputText value="Selected Row" />
</f:facet>
<h:outputText value="ID" />
<h:outputText value="#{saClientcontroller.selectedSaClient.idSaClient}" />
<h:outputText value="NAME:" />
<h:outputText value="#{saClientcontroller.selectedSaClient.saClientName}" />
<h:outputText value="DESCRIPTION:" />
<h:outputText value="#{saClientcontroller.selectedSaClient.saClientAddress}" />
</h:panelGrid>
</p:dialog>
</f:view>
</h:body>
</html>
이것은 내 Backing Bean입니다.
public class SaClientController implements Serializable {
@EJB
private SaClientFacade saClientFacade;
private SaClient selectedSaClient;
private LazyDataModel<SaClient> lazyModel;
private List<SaClient> saclients;
/** Creates a new instance of SaClientController */
public SaClientController() {
}
@PostConstruct
public void Init() {
saclients = saClientFacade.Retrieve();
lazyModel = new LazyDataModelImp(saclients);
}
public LazyDataModel<SaClient> getLazyModel() {
return lazyModel;
}
public List<SaClient> getClients() {
return saClientFacade.Retrieve();
}
public SaClient getDetails() {
return selectedSaClient;
}
public String showDetails(SaClient selectedSaClient) {
this.selectedSaClient = selectedSaClient;
return "DETAILS";
}
public String update() {
System.out.println("###UPDATE###");
selectedSaClient = saClientFacade.Update(selectedSaClient);
return "SAVED";
}
public String list() {
System.out.println("###LIST###");
return "LIST";
}
public SaClient getSelectedSaClient() {
return selectedSaClient;
}
public void setSelectedSaClient(SaClient selectedSaClient) {
this.selectedSaClient = selectedSaClient;
}
public String dummyAction()
{
return null;
}
}
이 web.xml
에서 절약 LazyModelImp
클래스
public class LazyDataModelImp extends LazyDataModel<SaClient> {
private List <SaClient> datasource;
public LazyDataModelImp(List<SaClient> datasource) {
this.datasource = datasource;
}
@Override
public SaClient getRowData(String rowKey) {
for (SaClient saclient : datasource) {
if (saclient.getIdSaClient().toString().equals(rowKey)) {
return saclient;
}
}
return null;
}
@Override
public Object getRowKey(SaClient saclient) {
return saclient.getIdSaClient().toString();
}
@Override
public List<SaClient> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
List<SaClient> data = new ArrayList<SaClient>();
//filter
for (SaClient saclient : datasource) {
boolean match = true;
for (Iterator<String> it = filters.keySet().iterator(); it.hasNext();) {
try {
String filterProperty = it.next();
String filterValue = filters.get(filterProperty);
String fieldValue = String.valueOf(saclient.getFilterSortFieldValue(filterProperty));
if (filterValue == null || fieldValue.startsWith(filterValue.toUpperCase()) || fieldValue.startsWith(filterValue.toLowerCase())) {
match = true;
} else {
match = false;
break;
}
} catch (Exception e) {
match = false;
}
}
if (match) {
data.add(saclient);
}
}
//rowCount
int dataSize = data.size();
this.setRowCount(dataSize);
//paginate
if (dataSize > pageSize) {
try {
return data.subList(first, first + pageSize);
} catch (IndexOutOfBoundsException e) {
return data.subList(first, first + (dataSize % pageSize));
}
}
else {
return data;
}
//sort
//if (sortField != null) {
// Collections.sort(data, new LazySorter(sortField, sortOrder));
//}
//return data;
}
}
이미 해제 한 부분 상태입니다.
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
backingBean
내가clienList.xhtml
의 데이터 테이블의 마지막 열에서보기를 명령 단추를 클릭 처음으로 다시 초기화됩니다. 대화 상자가 전혀 표시되지 않습니다. 하지만 F5를 누르면 대화 상자는 표시 될 수 있지만 내용이 없으면 대화 상자에 표시되는 것은 outputText 레이블이지만 bean 값은 표시되지 않으며 비어 있습니다. 초보자 질문에 대해 유감입니다. 누구든지 내가하는 일이 잘못되었다고 조언 할 수 있다면 매우 기쁠 것입니다. 내비게이션에 대한 조언과 모든 것을 표시하는 내 전략이
index.xhtml
에 있는지 알 수 있습니다. (전 단지 1 시야 ID가 항상
index.xhtml
입니다.) 맞아.
와우 ... 너무 많습니다. 다음 번 발생하는 문제와 직접 관련된 코드 및 구성 만 포함 시키십시오.불가능한 경우 테스트 페이지에서 문제를 재현 해보십시오. –
감사합니다 maple_shaft. 죄송합니다 ... 저는 세부 정보를 얻기 위해 모든 것을 넣고 싶습니다. 나는 다음번에 더 짧은 버전을 넣을 것이다. Btw, 내 솔루션에 대해 항상 /index.xhtml 만 브라우저에 표시되도록 어떻게 생각하십니까? 그리고 센터 패널의 내용 만 동적으로 다른 xhtml 페이지를 포함하여 업데이트되고 있습니까? 괜찮 니? – frazkok
이것은 일반적인 해결책이며 다른 사람들은 이것을 사용했습니다. Primefaces를 이미 사용하고 있으므로 Primefaces Layout 템플릿을 사용하면 도움이 될 것입니다. http://www.primefaces.org/showcase/ui/layoutHome.jsf –