私はこの問題を解決する最良の方法は、ちょうど私のコードを貼り付けることであると思う:JSF - Ajaxコール - このコードで何が間違っていますか?
Selector bean
@ManagedBean(name="selector")
@RequestScoped
public class Selector {
@ManagedProperty(value="#{param.page}")
private String page;
private String profilePage;
@PostConstruct
public void init() {
if(profilePage==null || profilePage.trim().isEmpty()) {
this.profilePage="main";
}
if(page==null || page.trim().isEmpty()) {
this.page="homepage";
}
}
public String getProfilePage() { System.out.println("GET ="+profilePage); return profilePage; }
public void setProfilePage(String profilePage) { this.profilePage=profilePage; }
public String getPage() { return page; }
public void setPage(String page) { this.page=page; }
}
profile.xhtml
<h:panelGroup layout="block" id="profileContent">
<h:panelGroup rendered="#{selector.profilePage=='main'}">
<ui:include src="/profile/profile_main.xhtml" />
</h:panelGroup>
<h:panelGroup rendered="#{selector.profilePage=='edit'}">
<ui:include src="/profile/profile_edit.xhtml" />
</h:panelGroup>
</h:panelGroup>
profile_main.xhtml
<h:form id="formProfileMain" prependId="false">
<h:panelGroup layout="block">
<h:outputScript name="jsf.js" library="javax.faces" target="head" />
<h:outputLabel value="MAIN" />
<h:panelGroup layout="block" >
<h:commandButton value="Edit Button">
<f:setPropertyActionListener target="#{selector.profilePage}" value="edit" />
<f:ajax event="action" render=":profileContent"/>
</h:commandButton>
</h:panelGroup>
</h:panelGroup>
</h:form>
profile_edit.xhtml
<h:panelGroup layout="block" id="profileEditContent">
<h:panelGroup rendered="#{selector.profilePage=='edit'}">
<h:form id="formProfileEdit" prependId="false">
<h:panelGroup layout="block">
<h:outputScript name="jsf.js" library="javax.faces" target="head" />
<h:outputLabel value="EDIT" />
<h:panelGroup layout="block">
<h:commandButton value="Confirm Edit">
<f:setPropertyActionListener target="#{selector.profilePage}" value="editConfirm" />
<f:ajax event="action" render=":profileEditContent"/>
</h:commandButton>
<h:commandButton value="Back">
<f:setPropertyActionListener target="#{selector.profilePage}" value="main" />
<f:ajax event="action" render=":profileEdit"/>
</h:commandButton>
</h:panelGroup>
</h:panelGroup>
</h:form>
</h:panelGroup>
<h:panelGroup rendered="#{selector.profilePage=='editConfirm'}">
<h:outputLabel value="FINALLY IM HERE" />
</h:panelGroup>
</h:panelGroup>
私は編集ボタンに最初にクリックして、の確認、編集上よりも、私は(結果として)を取得しようとするとラベルとページFINALLY IM HERE 残念ながら、このdoesntのことが起こります。 編集ボタンをクリックした後、をクリックしてください。を編集しても何も起こりません。
私は間違っていますか?乾杯
新しいバージョンでUPDATE
bean
@ManagedBean
@ViewScoped
public class ProfileSelector {
private String profilePage;
@PostConstruct
public void init() {
if(profilePage==null || profilePage.trim().isEmpty()) {
this.profilePage="main";
}
}
public String getProfilePage() { return profilePage; }
public void setProfilePage(String profilePage) { this.profilePage=profilePage; }
}
profile.xhtml
<h:panelGroup layout="block" id="profileContent">
<h:form id="formProfile" prependId="false">
<h:outputScript name="jsf.js" library="javax.faces" target="head" />
<h:panelGroup rendered="#{profileSelector.profilePage=='main'}">
<ui:include src="/profile/profile_main.xhtml" />
</h:panelGroup>
<h:panelGroup rendered="#{profileSelector.profilePage=='edit'}">
<ui:include src="/profile/profile_edit.xhtml" />
</h:panelGroup>
</h:form>
</h:panelGroup>
profile_main.xhtml
<h:panelGroup layout="block">
<h:outputLabel value="MAIN" />
<h:panelGroup layout="block">
<h:commandButton value="Edit Button">
<f:setPropertyActionListener target="#{profileSelector.profilePage}" value="edit" />
<f:ajax event="action" render=":profileContent"/>
</h:commandButton>
</h:panelGroup>
</h:panelGroup>
複雑になるまあ
profile_edit.xhtml
<h:panelGroup layout="block" id="profileContentEdit">
<h:panelGroup rendered="#{profileSelector.profilePage=='edit'}">
<h:panelGroup layout="block">
<h:outputLabel value="EDIT" />
<h:panelGroup layout="block" styleClass="profilo_3">
<h:commandButton value="Confirm Edit">
<f:setPropertyActionListener target="#{profileSelector.profilePage}" value="editConfirm" />
<f:ajax event="action" render=":profileContentEdit"/>
</h:commandButton>
<h:commandButton value="Back">
<f:setPropertyActionListener target="#{profileSelector.profilePage}" value="main" />
<f:ajax event="action" render=":profileContent"/>
</h:commandButton>
</h:panelGroup>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup rendered="#{profileSelector.profilePage=='editConfirm'}">
<h:outputLabel value="FINALLY Im HERE" />
</h:panelGroup>
</h:panelGroup>
おおを。少なくとも今、私は、それが行列の始まりに「メイン」を持つコンポーネントツリーを作成する理由を理解しています。 RequestStopeでセレクタBeanが必要なので、私は戦略を変更する必要があると思います:)残念ながら、jsfを使ってajax呼び出しで自分のディナミズムメニューを実装する方法は他にありません。 – markzzz
本当に '@ ViewScoped'が必要です。これにアプローチする方法については、回答の更新を参照してください。 – BalusC
ええ、私は2つの別の豆(最高の可視性)に分割。試してみましたが、現時点でレンダリングをロードしています。もう少しお試しください! – markzzz