incubator-adffaces-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Döring Markus <Markus.Doer...@tcc-products.de>
Subject Wrong action called
Date Wed, 10 Jan 2007 10:13:21 GMT
Hello,

I'm using myfaces, Trinidad (snapshot M1) and facelets on a tomcat 5.5 webserver.

 

Because I'm not sure if this is a MyFaces or a Trinidad issue I write on both lists.

 

On one of my pages I have an <tr:selectOneChoice> to set an filter on a list of datas.
Below it I have a <tr:table> to display the data itself. In the table there are download-links
(<tr:commandLink>) for every row in the table.

 

All works fine: setting the filter, displaying the table and downloading the data via the
link.

But if I first download data and than change the filter, the action from the download link
is called again (the valueChangeListener is called, too)

 

Here are some code snippets:

 

            //facelet file

 

            <tr:selectOneChoice label="select filter"

                  id="event" autoSubmit="false" onchange="submit()"

                  valueChangeListener="#{dataBean.filterChangeEvent}">

                  <f:selectItems value="#{globalProperties.filterTypes}" />

            </tr:selectOneChoice>

            <tr:table value="#{dataBean.dataList}" var="data">

                  <tr:column>

                        <f:facet name="header">

                             <tr:outputText value="#{id}" />

                        </f:facet>

                        <tr:outputText value="#{data.id}" />

                  </tr:column>

 

 

                  // (some more columns)

 

 

                  <tr:column>

                        <f:facet name="header">

                             <tr:outputText value="data" />

                        </f:facet>

                        <tr:commandLink text="download}">

                             <tr:setActionListener  //only used to get the correct id from
what to download

                                   from="#{data.id}"  

                                   to="#{dataBean.downloadId}" />

                             <f:actionListener

                                   type="de.tccproducts.dprs.basicstats.DataBean" />

                        </tr:commandLink>

                  </tr:column>

            </tr:table>

 

 

      //action Listener methods

      public void processAction(ActionEvent event)

                  throws AbortProcessingException {

            

// get the current data Object

            Data data = getData();

            

// get the byte array that should be downloaded

            byte[] data = data.getByteData();

            

// set mime type and filename

            FacesContext context = FacesContext.getCurrentInstance();

            HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();

            response.setContentType("text/plain");

            response.setHeader("Content-Disposition", "attachment;filename=\"someTestFile.txt\"");

            

// append the byte[] to the response

            ByteArrayInputStream fis = new ByteArrayInputStream(data);

            try {

                  OutputStream os = response.getOutputStream();

                  int read = 0;

                  byte[] bytes = new byte[1024];

                  while ((read = fis.read(bytes)) != -1) {

                        os.write(bytes, 0, read);

                  }

                  os.flush();

                  os.close();

            } catch (Exception ex) {

                  ex.printStackTrace();

            }

            FacesContext.getCurrentInstance().responseComplete();

}

 

 

 

      public void filterChangeEvent(ValueChangeEvent ev) {

 

            // get the selected value from selectOneChoice

            String key = ev.getComponent().getAttributes().get("id").toString();

            FilterType filter = (FilterType) ev.getComponent().getAttributes().get("value");

 

            // set the filter and update the dataList

            setFilter(filter);

}

 

 

My thought is that the commandLink sets some hidden input fields to say the server what to
download. The download is done but the page is not reloaded and so the hidden input fields
stay as they are.

When the valueChangeListener is called, the Server recognises the hidden fields again, and
so executes the commandLink Action again.

 

What can I do to avoid this?

Force a refresh on the page after download is done?

Reset the hidden input fields in some way?

Check in the download action if it really should be executed?

Or is there some other problem I don't see at the moment?

 

Please help if you have an idea on this.

Greetings

Markus


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message