中传递操作

发布于 2024-07-26 02:13:19 字数 678 浏览 1 评论 0原文

有一些方法可以在 中传递操作。 我想编写带有“是”和“否”按钮的简单弹出窗口,并且我想在不同页面中重用此弹出窗口,这就是为什么我需要在按下“是”按钮时调用不同的操作。 有一种方法可以在 中使用 传递一些值:

<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>

但是有什么方法可以传递 action 吗?

There is some way to pass action in <rich:modalPanel>. I want to write simple popup with "Yes" and "No" button, and I want to reuse this popup in different pages, that's why I need that different action was invoked when "Yes" button pressed. There is a way to pass some value in <rich:modalPanel> with <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>

But is some way to pass action ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

歌枕肩 2024-08-02 02:13:19

当您使用 Facelets 时,请查看 Rick Hightower 的文章 并“传递动作”部分。 它与您使用的基本方法相同,但也在 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]}"/>

请注意,您使用了#。

As you're using Facelets then look at Rick Hightower's article and the section "Passing Actions". It's the same basic method to what you've used, but also passing in the method on the bean.

Eg:

<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>

And then in the popup:

<a4j:commandButton id="yesButton" value="#{msgs.yesButton}"
     action="#{backingBean[yesAction]}"/>

Note that you use the #.

放赐 2024-08-02 02:13:19

我自己找到答案:)。 也许这会对某人有帮助。

我已经使用 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},它对我们来说是必要的$,但不是#

I find the answer by myself :). Maybe it will be helpful for somebody.

I've done this using Facelets. When I'm include popup to my page I pass parametr to it:

            <ui:include src="./WEB-INF/popup/popup.xhtml">
                <ui:param name="yesAction" value="${thisPageBean}" />
            </ui:include>  

Where thisPageBean - is bean from what popup invoked.

Then in my popup I wrote:

 <a4j:commandButton id="yesButton" value="#{msgs.yesButton}"
                     action="#{yesAction.someAtion}"
 </a4j:commandButton>

And with this I invoke thisPageBean.someAtion. All magic is ${thisPageBean}, it's is necessary to us $ but no #.

黑白记忆 2024-08-02 02:13:19

是的,我认为这样做没有任何问题。 如果需要,您可以使用我的代码:

<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;
}

Yes I dont see any problems with doing this. You can use my code if you want:

<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>

Basicly the output in the modal panel will contain the values in the TestBean

Edit (the misunderstanding):

I believe you will have to define your modal panel like this:

<rich:modalPanel id="popup" width="261" height="386"  autosized="true"left="180" top="200" keepVisualState="true"
    binding="#{PopupBean.popupPanel}">
</rich:modalPanel>

And in your managed bean you will have to addChildren to your modal panel dynamically with java like this:

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文