在 JSF 页面(比如说 page1)上,我单击一个链接,该链接通过 JavaScript 触发弹出窗口。弹出窗口出现,JSF page1 停留在后台。
在弹出窗口中,我也工作 JSF。当我完成弹出窗口时,我单击弹出窗口上的一个按钮,该按钮调用 window.close() JavaScript 函数来关闭它,并且该按钮的操作方法更新同一页面的管理 bean 中的值1 和返回页面 page1 的路径以将我重定向到启动弹出窗口的同一位置。所以 getter 方法获得了很好的价值,但我的 page1 没有得到更新,只是在手动刷新之后。
两个 bean(“调用者”弹出 bean 和“接收者”bean)都是 SessionScoped。
编辑
- page1 == 测试.xhtml
- tests.xhtml 的支持 bean 是 TestsBean
- 我单击 value="Test no. #{o.noGrid} 的链接之一
- onclick 属性触发弹出窗口的 JavaScript 脚本
xhtml 的片段
<tbody> <ui:repeat var="o" value="#{testsBean.gridTableGeneral}" varStatus="status"> <h:form> <h:panelGroup rendered="#{status.even}"> <tr> <td class="order-table-even-row"><h:commandLink action="#{gridPopUpBean.showGridTest()}" target="_blank" onclick="confirmGrid('Are you sure you want to start the test no. #{o.noGrid}?');" value="Test no. #{o.noGrid}"> <f:setPropertyActionListener value="#{o.noGrid}" target="#{testsBean.noGridToShow}" /> </h:commandLink></td> <td class="order-table-even-row">#{o.totalAccess}</td> <td class="order-table-even-row">#{o.maxPercentage} %</td> <td class="order-table-even-row"><h:commandLink action="#{testsBean.showGridDetaildPage()}"> <img src="/juritest/resources/img/details.png" alt="details" /> </h:commandLink></td> </tr> </h:panelGroup> <h:panelGroup rendered="#{status.odd}"> <tr> <td class="order-table-odd-row"><h:commandLink action="#{gridPopUpBean.showGridTest()}" target="_blank" onclick="confirmGrid('Are you sure you want to start the test no. #{o.noGrid}?');" value="Test no. #{o.noGrid}"> <f:setPropertyActionListener value="#{o.noGrid}" target="#{testsBean.noGridToShow}" /> </h:commandLink></td> <td class="order-table-odd-row">#{o.totalAccess}</td> <td class="order-table-odd-row">#{o.maxPercentage} %</td> <td class="order-table-odd-row"><h:commandLink action="#{testsBean.showGridDetaildPage()}"> <img src="/juritest/resources/img/details.png" alt="details" /> </h:commandLink></td> </tr> </h:panelGroup> </h:form> </ui:repeat>
此页面的支持 bean TestBean.java 的片段是
@ManagedBean @SessionScoped public class TestsBean implements Serializable { private static final long serialVersionUID = 1L; @EJB TestsManager testsManager; @ManagedProperty(value = "#{applicationContainer}") private ApplicationContainer container; @ManagedProperty(value = "#{accessesBean}") private AccessesBean accessesBean; ... getters / setter for the ui:repeat ... public void extractInformationFromDB(int gridCategory) { // extract from the container the right category grids gridList = testsManager.extractFromContainerRightCategory(container, gridCategory); // extract from the right grids array list the grid numbers setNoGrid(testsManager.setNoGrid(gridList)); // extract the accesses accessList = accessesBean.getAccessInformation(gridCategory); // extract from the access array list the grid numbers setNoAccessGrid(accessesBean.setNoAccessGrid(accessList)); setGridTableGeneral(testsManager.createGridTableGeneral(gridList, getNoGrid(), accessList, getNoAccessGrid()));
}
完成后的弹出窗口以 answerResult.xhtml 结尾
<ui:repeat var="n" value="#{answerResultBean.accessWrongAnswerColumnWrapperList}"> <hr /> <h:outputText value="#{n.noQuestion}. #{n.question}" /> <table style="text-align: left;"> <tr> <td> <h:form> <h:graphicImage value="/resources/img/#{n.rightGridAnswerA ? 'tick' : 'x'}Small.png" alt="#{n.rightGridAnswerA ? 'right' : 'wrong'} " /> </h:form></td> <td> <h:outputText value="a) #{n.a}" style="#{n.userAnswerA ? 'font-weight:bold;' : 'font-weight:normal;'}" /> </td> </tr> <tr> <td> <h:form> <h:graphicImage value="/resources/img/#{n.rightGridAnswerB ? 'tick' : 'x'}Small.png" alt="#{n.rightGridAnswerB ? 'right' : 'wrong'} " /> </h:form></td> <td> <h:outputText value="b) #{n.b}" style="#{n.userAnswerB ? 'font-weight:bold;' : 'font-weight:normal;'}" /> </td> </tr> <tr> <td> <h:form> <h:graphicImage value="/resources/img/#{n.rightGridAnswerC ? 'tick' : 'x'}Small.png" alt="#{n.rightGridAnswerC ? 'right' : 'wrong'} " /> </h:form></td> <td> <h:outputText value="c) #{n.c}" style="#{n.userAnswerC ? 'font-weight:bold;' : 'font-weight:normal;'}" /> </td> </tr> </table> <hr /> </ui:repeat> </div> <div id="loginDiv"> <h:commandButton style="text-align:left" onclick="closeWindow(); return true;" action="#{answerResultBean.closeButton()}" value="Close" /> </div>
弹出窗口的最后一页的支持 bean 是 AnswerResult.java
@ManagedBean @SessionScoped public class AnswerResultBean implements Serializable { private static final long serialVersionUID = 1L; @ManagedProperty(value = "#{testsBean}") private TestsBean testsBean; private AccessAnswerResultWrapper accessAnswerResultWrapper; private ArrayList<AccessWrongAnswerColumnWrapper> accessWrongAnswerColumnWrapperList; // getter / setter START /** * @param testsBean The testsBean to set. */ public void setTestsBean(TestsBean testsBean) { this.testsBean = testsBean; }
...
public String closeButton() { testsBean.extractInformationFromDB(GridHelper.convertingGridCategoryFromStringToInteger(getAccessAnswerResultWrapper().getCategory())); return Utils.path + "/tests/tests";
}
我单击带有 value="Close" 触发器和关闭弹出窗口的事件的弹出窗口上的按钮,然后执行 closeButton() 方法,执行来自 TestBean.java 的提取方法,其中设置我在 ui:repeat 中用作属性的属性在 tests.xhtml 中,最后动作方法 closeButton() 将我重定向到 tests.xhtml,它又再次调用支持 bean TestBean.java。
我知道它一团糟,我知道它不是 DRY 并且设计有缺陷,但我正在不断学习。
在最后阶段,我重定向到tests.xhtml,在我设置它使用的属性之前,tests.xhtml 调用bean 并且应该用新值更新它。但它不会得到更新,只是在手动刷新之后。