有一些方法可以在<rich:modalPanel>
中传递操作。我想用“是”和“否”按钮编写简单的弹出窗口,我想在不同的页面重用这个弹出窗口,这就是为什么我需要在按下“是”按钮时调用不同的动作。有一种方法可以在<rich:modalPanel>
<a4j:actionparam>
中传递一些值:
<a4j:commandButton value="See details…" id="det"
reRender="popup_dataIdField, …">
<rich:componentControl for="popup"
operation="show" event="onclick" />
<a4j:actionparam name="message" assignTo="#{popupBean.message}"
value="#{myBean.message}" />
</a4j:commandButton>
但是通过行动是否有某种方式?
答案 0 :(得分:2)
当您使用Facelets时,请查看Rick Hightower's article和“传递操作”部分。它与您使用的基本方法相同,但也在bean上传递方法。
例如:
<ui:include src="./WEB-INF/popup/popup.xhtml">
<ui:param name="yesAction" value="save"/>
<ui:param name="cancelAction" value="cancel"/>
<ui:param name="backingBean" value="#{thisPageBean}"/>
</ui:include>
然后在弹出窗口中:
<a4j:commandButton id="yesButton" value="#{msgs.yesButton}"
action="#{backingBean[yesAction]}"/>
请注意,您使用#。
答案 1 :(得分:1)
我自己找到答案:)。也许对某人有帮助。
我使用Facelets完成了这项工作。当我在我的页面中包含弹出窗口时,我将参数传递给它:
<ui:include src="./WEB-INF/popup/popup.xhtml">
<ui:param name="yesAction" value="${thisPageBean}" />
</ui:include>
其中thisPageBean
- 是来自弹出窗口调用的bean。
然后在我的弹出窗口中写道:
<a4j:commandButton id="yesButton" value="#{msgs.yesButton}"
action="#{yesAction.someAtion}"
</a4j:commandButton>
然后我调用thisPageBean.someAtion
。所有魔法都是${thisPageBean}
,这对我们$
是必要的,但不是#
。
答案 2 :(得分:0)
是的我没有看到这样做有任何问题。如果您愿意,可以使用我的代码:
<rich:modalPanel id="popup" width="261" height="386" autosized="true"left="180" top="200" keepVisualState="true">
<h:panelGrid id="panelGrid">
<h:outputText value="#{PopupBean.output}" id="popupMessage"/>
<a4j:commandLink action="#">
<h:outputText value="Close" />
<rich:componentControl for="popup" operation="hide" event="onclick"/>
</a4j:commandLink>
</h:panelGrid>
</rich:modalPanel>
<h:panelGrid columns="2">
<a4j:commandLink action="#" reRender="panelGrid">
<h:outputText value="Yes" />
<rich:componentControl for="popup" operation="show" event="onclick"/>
<a4j:actionparam name="message" assignTo="#{PopupBean.output}" value="#{TestBean.input1}"/>
</a4j:commandLink>
<a4j:commandLink action="#" reRender="panelGrid">
<h:outputText value="No" />
<rich:componentControl for="popup" operation="show" event="onclick"/>
<a4j:actionparam name="message2" assignTo="#{PopupBean.output}" value="#{TestBean.input2}"/>
</a4j:commandLink>
</h:panelGrid>
基本上,模态面板中的输出将包含TestBean中的值
编辑(误解):
我相信你必须像这样定义你的模态面板:
<rich:modalPanel id="popup" width="261" height="386" autosized="true"left="180" top="200" keepVisualState="true"
binding="#{PopupBean.popupPanel}">
</rich:modalPanel>
在你的托管bean中,你必须使用java动态地将children添加到你的模态面板中:
public String action_PoppingThePanel() {
HtmlCommandButton button = new HtmlCommandButton();
button.setValue("Yes");
String action = "#{TestBean.action_yes}";
MethodExpression methodExpression =
FacesContext.getCurrentInstance().getApplication().getExpressionFactory().
createMethodExpression(FacesContext.getCurrentInstance().getELContext(), action, null,
new Class<?>[0]);
button.setActionExpression(methodExpression);
getPopupPanel().getChildren().add(button);
button = new HtmlCommandButton();
button.setValue("No");
String action = "#{TestBean.action_no}";
methodExpression =
FacesContext.getCurrentInstance().getApplication().getExpressionFactory().
createMethodExpression(FacesContext.getCurrentInstance().getELContext(), action, null,
new Class<?>[0]);
button.setActionExpression(methodExpression);
getPopupPanel().getChildren().add(button);
getPopupPanel().setRendered(true);
getPopupPanel().setShowWhenRendered(true);
return null;
}