Passing action in <rich:modalPanel>

僤鯓⒐⒋嵵緔 提交于 2019-12-23 03:13:19

问题


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 ?


回答1:


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




回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/1083834/passing-action-in-richmodalpanel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!