当前位置: 动力学知识库 > 问答 > 编程问答 >

jsf 2 - JSF inputfield values gone after second button click

问题描述:

The problem is that I'm trying to press a button -> go to the backing bean -> set a boolean to false/true and show a popup accordingly. If the popup shows -> call the method and execute it.

The above is working, but the input fields I've got after the first button click seem to be lost when I'm clicking the button in the popup panel. So all the parameters I've got after the first click (they get in the backing bean object) are gone with the second click (in the popup). What could this be?

It's all in one form and all buttons and inputfields etc are in one a4j:region.. There are no validations errors behind the scenes.

I've got the following backing bean (note that I intentionally didn't put the whole bb in there with al the injects etc..):

@ManagedBean(name = "dossierInTreatmentBB")

@ViewScoped

public class DossierInTreatmentBackingBean {

/** The show center popup. */

private boolean showCenterPopup;

/** The continue assign without report. */

private boolean continueAssignWithoutReport;

public void assign() throws IOException {

if (!continueAssignWithoutReport) {

ExternalOffice eo = annucompLocal.findOfficeByCrestraCode(getEntity().getServiceTreatment());

showCenterPopup = OfficeLevel.CENTER.equals(eo.getServiceType().getOfficeLevel())

}

if (!showCenterPopup) {

dossierInTreatmentDossierLocal.assign();

//refreshes the entity

setDTO(null);

if (!DossierContext.isEditAllowed(getDossier())) {

String url = getRequestContextPath() + "/dossier/consult/detail.jsf?id=%s";

redirect(url, getDossier().getId().toString());

}

}

}

/**

* Assign without report.

* @throws IOException Signals that an I/O exception has occurred.

*/

public void assignWithoutReport() throws IOException {

showCenterPopup = false;

continueAssignWithoutReport = true;

assign();

}

... needed getters and setters ...

and this is my view (assign.xhtml):

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:fragment xmlns="http://www.w3.org/1999/xhtml"

xmlns:ui="http://java.sun.com/jsf/facelets"

xmlns:f="http://java.sun.com/jsf/core"

xmlns:h="http://java.sun.com/jsf/html"

xmlns:ccffdecorate="http://java.sun.com/jsf/composite/ccffdecorate"

xmlns:rich="http://richfaces.org/rich"

xmlns:a4j="http://richfaces.org/a4j">

<a4j:region>

<h:panelGrid layout="block" styleClass="rSplitPanel2" columns="2"

rendered="#{not empty entityBB.entity}">

"some input fields"

</h:panelGrid>

<h:panelGroup layout="block" styleClass="rButtonPanel">

<h:commandButton value="#{AppMessages['general.action.save']}">

<a4j:ajax

render="dossierInTreatmentPanel :messages centerPopupGroup"

listener="#{entityBB.assign}" status="ajaxStatus"

oncomplete="#{rich:component('centerPopup')}.show()" />

</h:commandButton>

<h:commandButton value="#{AppMessages['general.action.cancel']}">

<a4j:ajax execute="@this" render="dossierInTreatmentPanel :messages"

listener="#{entityBB.cancel}" status="ajaxStatus" />

</h:commandButton>

</h:panelGroup>

<h:panelGroup id="centerPopupGroup">

<rich:popupPanel id="centerPopup" modal="true" autosized="true"

rendered="#{entityBB.showCenterPopup}"

onmaskclick="#{rich:component('centerPopupPanel')}.hide()">

<div class="rButtonPanel">

<h:commandButton value="#{AppMessages['general.action.next']}">

<a4j:ajax listener="#{entityBB.assignWithoutReport()}"

status="ajaxStatus"

oncomplete="#{rich:component('centerPopup')}.hide();" />

</h:commandButton>

<h:commandButton value="#{AppMessages['general.action.cancel']}">

<a4j:ajax listener="#{entityBB.cancel}" limitRender="true"

status="ajaxStatus"

onclick="#{rich:component('centerPopup')}.hide(); return false;" />

</h:commandButton>

</div>

</rich:popupPanel>

</h:panelGroup>

</a4j:region>

dit.xhtml:

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"

xmlns:ui="http://java.sun.com/jsf/facelets"

xmlns:f="http://java.sun.com/jsf/core"

xmlns:h="http://java.sun.com/jsf/html"

xmlns:e="http://minfin.regondes2/entity"

xmlns:rich="http://richfaces.org/rich"

xmlns:a4j="http://richfaces.org/a4j"

xmlns:l="http://minfin.regondes2/layout">

<ui:include src="assignBlock/assign.xhtml" />

dossier.xhtml:

<h:form>

<ui:include src="dit.xhtml" />

</h:form>

I'm sorry for not making the views more compact, but since I'm guessing the problem is located in the view I'm showing the whole structure.

网友答案:

Finally found it.

Had to add 2 different a4j:regions. 1 for the form and 1 for the popup panel..

分享给朋友:
您可能感兴趣的文章:
随机阅读: