myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Friedrich <trini...@eekboom.com>
Subject Re: [Trinidad] Table expert, anyone?
Date Tue, 13 Nov 2007 00:28:54 GMT
Fair enough. Thanks for staying with me.  PPR on or off does not make any difference.

Here's an extract of my JSF/facelets page:

-----------------------------------------------------------------------------------------------------------------------

<tr:table id="shopTimeDetails" var="details" value="#{shopTimeDetailsHome.shopTimeDetails}"
binding="#{shopTimeDetailsHome.table}">
     <tr:column headerText="Delete">
         <tr:commandLink id="deleteLink" action="#{shopTimeDetailsHome.remove}" immediate="true"
rendered="#{!details.isPlaceholder}">
             <f:param name="detailsRowIndex" value="#{details.rowIndex}"/>
             <img src="images/delete.gif"/>
         </tr:commandLink>
     </tr:column>

     <tr:column headerText="Engine Type">
         <tr:selectOneChoice id="engineType" value="#{details.engineType}" required="true"
autoSubmit="true" immediate="true" 
valueChangeListener="#{shopTimeDetailsHome.handleEngineTypeChanged}">
             <s:selectItems value="#{engineTypesQuery.resultList}" var="engineType" label="#{engineType.name}"/>
         </tr:selectOneChoice>
     </tr:column>

     <tr:column headerText="3LC">
         <tr:inputText id="threelc" value="#{details.threelc}" required="true" maximumLength="3"
rendered="#{!details.isPlaceholder}">
             <tr:validateLength maximum="3"/>
         </tr:inputText>
     </tr:column>

-----------------------------------------------------------------------------------------------------------------------


And here's an extract of the bean that should handle removing/adding rows (property accesors
excluded).
The correct row gets removed from the model (from the "shopTimeDetails" list), but if row
index 1 is
deleted, then the new values from the old index 2 never make it to the page.
I think that's more or less logical: The immediate delete command link causes a "short-circuit"
of the
remaining phases and the processing of the non-immediate components never takes place.
But it sure must be possible somehow to access the stamped components and update them.
Or maybe (hopefully) there's a cleaner/better way to implement this style of UI.

Note my pitiful attempt to copy values manually (now commented out).

-----------------------------------------------------------------------------------------------------------------------

public class ShopTimeDetailsHome {
     private List<ShopTimeDetails> shopTimeDetails;

     private transient CoreTable table;

     public void remove() {
         String indexText = FacesUtil.getRequestParameter("detailsRowIndex");
         try {
             int rowIndex = Integer.parseInt(indexText);
//            handleRowRemove(rowIndex);
             shopTimeDetails.remove(rowIndex);
             updateTransientDetailsProperties();
         }
         catch (NumberFormatException e) {
             errorLog.error("Expected row index to delete, but got: " + indexText, e);
         }
     }

     private void handleRowRemove(int i) {
         Object oldRowKey = table.getRowKey();// backup current model state

         try {
             int rowCount = table.getRowCount();
             int columnCount = table.getChildCount();
             for (int rowIndex = i; rowIndex < rowCount - 1; ++rowIndex) {
                 for (int columnIndex = 0; columnIndex < columnCount; ++columnIndex) {
                     copyCell(rowIndex + 1, columnIndex, rowIndex, columnIndex);
                 }
             }
         }
         finally {
             table.setRowKey(oldRowKey);// restore model state
         }
     }

     private void copyCell(int fromRowIndex, int fromColumnIndex, int toRowIndex, int toColumnIndex)
{
         table.setRowIndex(fromRowIndex);
         List fromColumns = table.getChildren();
         UIComponent column = (UIComponent) fromColumns.get(fromColumnIndex);
         UIComponent fromCell = (UIComponent) column.getChildren().get(0);
         if (fromCell instanceof EditableValueHolder) {
             EditableValueHolder holder = (EditableValueHolder) fromCell;
             Object value = holder.isLocalValueSet() ? holder.getLocalValue() : holder.getValue();

             table.setRowIndex(toRowIndex);
             List toColumns = table.getChildren();
             UIComponent toColumn = (UIComponent) toColumns.get(toColumnIndex);
             EditableValueHolder toCell = (EditableValueHolder) toColumn.getChildren().get(0);

             toCell.setValue(value);
         }
     }

     private void updateTransientDetailsProperties() {
         for (int i = 0; i < shopTimeDetails.size(); i++) {
             ShopTimeDetails details = shopTimeDetails.get(i);
             boolean isPlaceholder = i == shopTimeDetails.size() - 1;
             details.setIsPlaceholder(isPlaceholder);
             details.setRowIndex(i);
         }
     }



Gerhard Petracek wrote:
> hi,
> 
> at the moment it is difficult to see what you already tried and which 
> painful way of trying different possibilities you already walked along...
> 
> first of all - there is a bug at sortable and filterable tables - i 
> already opened an issue...
> some details: this bug only occurs if you have a changing model within a 
> sortable table - i guess that's not your case!?
> 
> 2 further questions:
> - have you already tried to use component binding?
> - did you already give ppr a chance or did you just deactivated it? - 
> generally ppr should work very well
> 
> if nothing of both would solve your problem - i don't have further 
> spontaneous ideas without knowing more details about your implementation...
> is it possible for you to provide some source code of your 
> implementation or an equivalent example?
> 
> regards,
> gerhard
> 
> 
> 
> 2007/11/13, Stephen Friedrich < trinidad@eekboom.com 
> <mailto:trinidad@eekboom.com>>:
> 
>     Thanks for the answer.
>     I am not at all using PPR at the moment. Just to be sure that my
>     problem is not
>     caused in any way by PPR, I switched it off using this snippet at
>     the top of my page:
>     <script type="text/javascript" xml:space="preserve">
>     // <![CDATA[
>         _pprUnsupported = true;
>     // ]]>
>     </script>
> 
>     If I understand the problem correctly, the immediate flag causes all
>     other components
>     on the page to stay "unprocessed".
>     So the html component with the generated id
>     "shopTimeDetails:1:threelc" just keeps its
>     value, even though at row index 1 there now is a different model value.
> 
>     I just don't have any idea how to make this scenario work.
> 
> 
>     Gerhard Petracek wrote:
>      > hello,
>      >
>      > how do you trigger ppr (the update) at the moment?
>      >
>      > there are several ways to trigger ppr - to answer your question
>      > concerning programmatically updating components maybe the
>     following link
>      > will help you:
>      >
>     http://myfaces.apache.org/trinidad/devguide/ppr.html#Using%20RequestContext
>      >
>      > regards,
>      > gerhard
>      >
>      >
>      >
>      > 2007/11/12, Stephen Friedrich < trinidad@eekboom.com
>     <mailto:trinidad@eekboom.com>
>      > <mailto:trinidad@eekboom.com <mailto:trinidad@eekboom.com>>>:
>      >
>      >     I am desperately trying to get a specific table UI to work - see
>      >     screenshot.
>      >     In short I have a list-backed table model.
>      >     When displayed there's a delete button in front of row.
>      >     The first column is a selectOneChoice.
>      >     There's always one more row at the bottom than there are
>     "real" values.
>      >     If the user selects a value from the dropdown, then another
>     row is
>      >     added.
>      >
>      >     Here's the catch:
>      >     Of course, neither the delete link nor the dropdown should
>     trigger
>      >     validation,
>      >     so I have set immediate="true" on them.
>      >
>      >     Unfortunately now the components on the page do not update
>      >     correctly, for example
>      >     if I delete the second row (see screenshot) the page does indeed
>      >     display one row
>      >     less, but the second row still displays the same data.
>      >
>      >     What the heck can I do to programmatically update the
>     component-side
>      >     of the model?
>      >
>      >
>      >
>      >
>      > --
>      >
>      > http://www.irian.at
>      >
>      > Your JSF powerhouse -
>      > JSF Consulting, Development and
>      > Courses in English and German
>      >
>      > Professional Support for Apache MyFaces
> 
> 
> 
> 
> -- 
> 
> http://www.irian.at
> 
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
> 
> Professional Support for Apache MyFaces


Mime
View raw message