1 2 Previous Next 15 Replies Latest reply: Apr 30, 2008 4:09 PM by Robert Stone RSS

modalPanel + dataTable + commandLink = no action

Robert Stone Newbie

I'm implementing search pop-up. Here's what I want:
1. Enter search term and click "Search"
2. Pop-up dialog and feed search term into text field
3. Do the search. Dialog should display table with search results
4. Click on one of the results
5. Value should be populated back into master form
6. Dialog is dismissed

I have a prototype working for all steps except #5. When I click on the command link I can see the event firing, however my action method is never executed (I tried actionListener as well, same no go)

I'm using latest RichFaces 3.2, backing beans are in request scope but placing these in session scope doesn't change the outcome. I also tried a4j:support with same result

Here's a master form

<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:ui="http://java.sun.com/jsf/facelets"
 xmlns:h="http://java.sun.com/jsf/html"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:a4j="http://richfaces.org/a4j"
 xmlns:rich="http://richfaces.org/rich"
 xmlns:s="http://myfaces.apache.org/sandbox"
 xmlns:t="http://myfaces.apache.org/tomahawk"
 xmlns:c="http://java.sun.com/jstl/core">

<ui:composition template="/WEB-INF/layout/layout.xhtml">
 <ui:define name="title">Modal test</ui:define>
 <ui:define name="content">
 <h:form id="modalMasterForm">
 <h:inputText id="modalMasterValue"
 value="#{modalMaster.searchFor}" />
 <a4j:commandButton id="searchButton" value="search" action="#{modalMaster.enterSearchValue}" reRender="searchValue"/>
 <rich:componentControl for="modalSearchPanel" attachTo="searchButton"
 operation="show" event="onclick" />
</h:form>
<a4j:include viewId="WEB-INF/pages/modal/modalTestForm.xhtml" />
 </ui:define>
</ui:composition>
</html>


And here's modal XHTML
<f:subview xmlns="http://www.w3.org/1999/xhtml"
 xmlns:ui="http://java.sun.com/jsf/facelets"
 xmlns:h="http://java.sun.com/jsf/html"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:a4j="http://richfaces.org/a4j"
 xmlns:rich="http://richfaces.org/rich"
 xmlns:s="http://myfaces.apache.org/sandbox"
 xmlns:t="http://myfaces.apache.org/tomahawk"
 xmlns:c="http://java.sun.com/jstl/core">
 <rich:modalPanel id="modalSearchPanel" width="400" height="350">
 <h:form id="userLookupForm">
 <f:facet name="header">
 <h:outputText value="My Modal Test" />
 </f:facet>
 <f:facet name="controls">
 <h:panelGroup>
 <h:graphicImage value="/images/close.png" style="cursor:pointer"
 id="hidelink" />
 <rich:componentControl for="modalSearchPanel" attachTo="hidelink"
 operation="hide" event="onclick" />
 </h:panelGroup>
 </f:facet>
 <h:inputText id="searchValue" value="#{modalMaster.searchFor}" />
 <a4j:commandButton id="search" action="${modalForm.search}"
 reRender="result" />

 <div><a4j:outputPanel id="result">
 <rich:dataTable id="seachResultsTable" var="seachResult"
 value="${modalForm.searchResults}">
 <rich:column>
 <a4j:commandLink value="#{seachResult}" event="onmousedown"
 id="selectSearchValue" actionListener="${modalMaster.backFeed}"
 reRender="modalMasterValue" />
 <rich:componentControl for="modalSearchPanel" operation="hide"
 event="onmouseup" />
 </rich:column>
 </rich:dataTable>
 </a4j:outputPanel></div>
 </h:form>
 <div><h:outputLink value="#" id="link">
 Hide Me
 <rich:componentControl for="modalSearchPanel" attachTo="link"
 operation="hide" event="onclick" />
 </h:outputLink></div>
 </rich:modalPanel>
</f:subview>


I found some links in reference to the similar problem with Trinidad table which has optional preserveDataModel="true" attribute. Couldn't find anything similar in RichFaces table so at this point I'm really banging my head and would appreciate any suggestions

  • 1. Re: modalPanel + dataTable + commandLink = no action
    Robert Stone Newbie

    To make matters even more interesting: if I place a command link outside of datatable then it works. The link looks like the following and goes just above rich:dataTable tag. Is this a bug?

    <a4j:commandLink id="resultLink"
     actionListener="${modalMaster.backFeed}"
     value="#{modalForm.searchTerm}" reRender="modalMasterValue">


  • 2. Re: modalPanel + dataTable + commandLink = no action
    Sergey Smirnov Master

    What is the scope of ${modalForm.searchResults} ?

    Pay your attention at Extended Data Model:
    http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf

  • 3. Re: modalPanel + dataTable + commandLink = no action
    Robert Stone Newbie

     

    "SergeySmirnov" wrote:
    What is the scope of ${modalForm.searchResults} ?


    Request. And you're right, as soon as I put modalForm bean into the session scope the action method started firing. Now - the problem is I don't want that bean in the session scope, what are my options here if any? And also if you can kindly provide it, I would really appreciate some explanation why it is not working in the request scope,

    Thanks in advance

  • 4. Re: modalPanel + dataTable + commandLink = no action
    Robert Stone Newbie

    I found what seem to be an explanation. Basically, when link is inside the table and bean is in the request scope the ID of link gets mangled. See here
    http://forum.java.sun.com/thread.jspa?threadID=5116147

    and here
    http://typo.ars-subtilior.com/articles/2007/02/07/jsf-datatable-and-commandlink

  • 5. Re: modalPanel + dataTable + commandLink = no action
    Robert Stone Newbie

    And to why I don't want my search backing bean in session? Simple - the search will be done, most likely only once and I don't want the resulting value linger in session ad finitum. And I don't want to worry about cleaning up the previous searches. Plus I know, that result that I need is within a click distance, so I consider the fact that I see the link but cannot use it - a bug. Please correct me if I'm wrong

  • 6. Re: modalPanel + dataTable + commandLink = no action
    Ivan Fajardo Newbie

    Hi, i'm having some troubles with modalPanel. I put a form into modal panel, 2 input boxes and i tried to re render the input boxes after clicking in an a4j:commandButton. The value of the input boxes become well into the action, the action does some stuff, but the inputboxes never rerender.

    any help?

    Regards!

  • 7. Re: modalPanel + dataTable + commandLink = no action
    Ilya Shaikovsky Master

    seems like nothing about modal panel ;)


    check please http://wiki.jboss.org/wiki/RichFacesTwoInputText

  • 8. Re: modalPanel + dataTable + commandLink = no action
    Sergey Smirnov Master

    To make data shown on the page, it should be available on the 6th JSF lifecycle phase. However, to make the data processed, you need to have it available before 2nd phase.
    If you fill your searchResults in the action on the 5th phase, it is shown and links are attached to the data. After you click the link, during the next request the request scope bean on the 2nd phase is just empty. So, nothing to process.

    As soon as you did not show the Java code snippet, it is hard to make a suggestion how it is possible in your case to keep the bean in the request scope ans have the example working.

    Fact, that if the searchResults is available already before the 2nd phase, the link will work.

  • 9. Re: modalPanel + dataTable + commandLink = no action
    Robert Stone Newbie

    Well, there's no code to show, really, since I changed the XHTML code to use a4j:actionparam. Here it is

    <rich:dataTable id="seachResultsTable" var="seachResult"
     value="${modalForm.searchResults}">
     <rich:column>
     <a4j:commandLink value="#{seachResult}" event="onclick"
     id="selectSearchValue" reRender="modalMasterValue">
     <a4j:actionparam name="searchFor" value="#{seachResult}"
     assignTo="#{modalMaster.searchFor}" />
     </a4j:commandLink>
     </rich:column>
     </rich:dataTable>


    This works like a charm if modalForm is placed into session scope. Now, if I take the link and place it outside of the datatable as follows, it (the link) works with request scope


    <a4j:commandLink value="#{modalMaster.searchFor}" event="onclick"
     id="selectSearchValue" reRender="modalMasterValue">
     <a4j:actionparam name="searchFor" value="#{modalMaster.searchFor}"
     assignTo="#{modalMaster.searchFor}" />
     </a4j:commandLink>


    Now can you, please, explain why the same code breaks inside the table?

  • 10. Re: modalPanel + dataTable + commandLink = no action
    Robert Stone Newbie

    Here's backing bean code, just in case

    public class ModalFormBean implements Serializable
    {
    
     private static final long serialVersionUID = 1L;
    
     private static final Log logger = LogFactory.getLog(ModalFormBean.class);
    
     private List<String> searchResults = new ArrayList<String>();
    
     /**
     * @return the searchResults
     */
     public final List<String> getSearchResults()
     {
     return searchResults;
     }
    
     /**
     * @param searchResults the searchResults to set
     */
     public final void setSearchResults(List<String> searchResults)
     {
     this.searchResults = searchResults;
     }
    
     public Object search(ActionEvent event)
     {
     // cleanup previous search
     this.searchResults.clear();
     String searchTerm = null;
     UIInput input = (UIInput)FacesUtils.findComponentById(null, "searchValue");
     if (input != null)
     {
     searchTerm = (String) input.getValue();
     }
     for (int i = 0; i < 4; i++)
     {
     this.searchResults.add(searchTerm + "_" + i);
     }
     logger.debug("Searching...");
     return null;
     }
    }
    


  • 11. Re: modalPanel + dataTable + commandLink = no action
    Robert Stone Newbie

    Here's one interesting line from logs (I don't have any disabled components on the page)

    2008-04-30 09:13:27,509 WARN [org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils] - <There should always be a submitted value for an input if it is rendered, its form is submitted, and it was not originally rendered disabled or read-only. You cannot submit a form after disabling an input element via javascript. Consider setting read-only to true instead or resetting the disabled value back to false prior to form submission. Component : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /modal.xhtml][Class: javax.faces.component.html.HtmlInputHidden,Id: googlesearch]}>org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils.decodeUIInput(HtmlRendererUtils.java:114)
    


  • 12. Re: modalPanel + dataTable + commandLink = no action
    Sergey Smirnov Master

     

    "bostone" wrote:
    Here's one interesting line from logs (I don't have any disabled components on the page)
    2008-04-30 09:13:27,509 WARN [org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils] - <There should always be a submitted value for an input if it is rendered, its form is submitted, and it was not originally rendered disabled or read-only. You cannot submit a form after disabling an input element via javascript. Consider setting read-only to true instead or resetting the disabled value back to false prior to form submission. Component : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /modal.xhtml][Class: javax.faces.component.html.HtmlInputHidden,Id: googlesearch]}>org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils.decodeUIInput(HtmlRendererUtils.java:114)
    


    MyFaces is crazy about the same thing - the search result is empty before the 2nd phase, so, the ids can be found.

    I see you implement the serializable interface, so, most likely, the a4j:keepAlive helps you to make it working.

    See http://livedemo.exadel.com/richfaces-demo/richfaces/keepAlive.jsf


    P.S. The advice about looking at Extended Data Model on http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf is still actual


  • 13. Re: modalPanel + dataTable + commandLink = no action
    Robert Stone Newbie

    Interesting - a4j:keepAlive works but only if I place it into original master form and not into pop-up. And set ajaxOnly="false". Still using it not much different from session scope

    I looked once more into extended datamodel demo. Are you referring to extending SerializableDataModel? Can you explain how would it help me to have my bean in request scope? Will it mean that my model will be serialized between requests? If so, I would still have to maintain the data. Some of my searches may contain lots of data I don't want something like that linger in session.

    Sergey, what is you take on couple of links that I provided where the proposed solution is to overwrite Link renderer?

    And another slightly unrelated question - why whole org.ajax4jsf.model package is missing from API and source distro?

  • 14. Re: modalPanel + dataTable + commandLink = no action
    Sergey Smirnov Master

     

    "bostone" wrote:

    And another slightly unrelated question - why whole org.ajax4jsf.model package is missing from API and source distro?


    Are you sure?

1 2 Previous Next