editable listGrid question

Hello,
I have a doubt about editable listgrids.
I've got a listgrid with an editable column, when user updates this column triggers an event through the server, who has to validate in db the new value and update another field in the same record.
To do this, I'm updating the bean property inside the listgrid selected bean, but the listgrid is not modified. If I navigate through the next page (using the listgrid pager) and return back, the new value is displayed.
Is this correct?
Could I update a listgrid value without perform a listgrid.refresh()?

If you don't understand what I mean, I could post some code.

Thanks in advance.
David

Hi David, Yes, Please

Hi David,

Yes, Please provide us with a code snippet which shows what you are trying to achive.

Thanks!

-Senaka

Code

Hi Senaka,
this is the code for my grid:

<bjsf:listGrid id="listado-listGrid" width="100%" rows="10" editable="true"
    var="tipExpRamo" selectMultiple="false"
    binding="#{mantExpRamoListado.tsMantTipExpRamoListGrid}"
    selectListener="#{mantExpRamoListado.itemSelected}">

<bjsf:column>
   <f:facet name="header">
        <bjsf:outputText value="Tipo expediente" width="10%" styleClass="x"/>
   </f:facet>
   <bjsf:inputText customActionListener="#{mantExpRamoListado.pvTipExp}"
     behavior="mapfre:submitOnBlur" value="#{tipExpRamo.tipExp}"/>

</bjsf:column>
<bjsf:column>
   <f:facet name="header">
        <bjsf:outputText value="Nombre del expediente" width="20%" styleClass="x"/>
   </f:facet>
   <bjsf:outputLabel value="#{tipExpRamo.nomExp}" />
</bjsf:column>

When user exits from input text a bb.bjsf.sync(this,'custom'); is performed by mapfre:submitOnBlur behavior and executes the pvTipExp method:
public void pvTipExp() {
    String newValue = validateTipExp (tipExp);
    setNomExp (newValue);
}

This method resides in the bean marked as "selected" by the grid (the itemSelected object), so I thought that the grid would update the outputLabel related with this property but it doesn't.
However, If you paginates or refresh the grid with listGrid.refresh (myArrayList) the newValue appears.
should the grid works as I want? Where have I go wrong?
David

Only the cells which have a

Only the cells which have a value change will get reflected with the new values after the edit- readonly mode switch. So if the backend carries out any server side validation logic and changes the data in the data source you will need to refresh() the grid. This refresh happens when you switch pages via a pager.

Hope this clarifies things.

Cheers,

-Senaka

Hi again Senaka, I don't

Hi again Senaka,
I don't mind to refresh() the grid, but I've got a problem with it.
When grid is refreshed, the component witch triggered the grid lose the focus.
For us is a requirement the focus control and refresh() puts focus on the browser toolbar.
I thought storing the focused component id in a javascript variable and set focus there when sync() was performed but I don't know how to do it.
I would need a callback function for bb.bjsf.sync().
Do you think this might be possible?
Could you suggest another way to control the focus?
Thanks.
David

Backbase JSF provides DeltaActionJavaScript class

Hi David,

Yes indeed, The component looses focus on a refresh() !!.

In client code this can of course be achieved easily by the JavaScript focus() method. However we need to trigger this event in a server sync.

To achieve this Backbase JSF provides you with DeltaActionJavaScript.(extends com.backbase.bjsf.util.actions.DeltaActionBase)

DeltaActionJavaScript allows you to add your custom JavaScript code to the server delta.

An example code fragment;

private DeltaActionJavaScript focus(UIBackbaseListGrid grid) {
String clientId = grid.getClientId(FacesContext.getCurrentInstance());
String command = "var oGrid = bb.document.getElementById('"+ clientId +"');oGrid.focus();";
DeltaActionJavaScript jsAction = new DeltaActionJavaScript(grid, command);
return jsAction;

Hope this helps!

Cheers,

-Senaka

I've tried it but it doesn't

I've tried it but it doesn't works, setting focus on the listgrid hasn't any effect on it, it doesn't do anything.
I've created a js variable "wtw_focusedElement", and when an nputText inside a grid gains the focus set this variable with its clientId.
After refreshing I want to set the focus on this field and I use this method:

private void focus(UIBackbaseListGrid grid) {
        String command = "alert('waiting...');var element = bb.document.getElementById(wtw_focusedElement);element.focus();";
        DeltaActionJavaScript jsAction = new DeltaActionJavaScript(grid, command);
        BackbaseContext context = BackbaseContext.getCurrentInstance();
        context.addDeltaAction(jsAction);
}

Notice the alert('waiting...') before the focus sentence.
If I remove this alert focus is not set. I think is a problem related with the rendering time at the client side or something like that, it could be?
Thanks

lose focus

Hi David,

I have tried both your focus method and Senaka's method.
I remove the alert. And it is working fine.
There is no issue regarding of this. My edited row is still being focused after that.

Or maybe it is better if you send the backing bean method where you update the listgrid.

P.S: I have tried in FF2 and IE7 using Backbase version 4.2.0

Thanks

Andys

I'll try it again with BB

I'll try it again with BB 4.2.0 and I'll let you know.
Thanks for your help, andys

David

It still doesn't work

Hi again andys,
I've tried it out and it doesn't work, I post some snippets more:

public void focus(UIComponent component) {
        String command = "var element = bb.document.getElementById(wtw_focusedElement);bb.setProperty(element,'value',wtw_focusedElement);bb.command.focus(element);";
       
        DeltaActionJavaScript jsAction = new DeltaActionJavaScript(component, command);
        BackbaseContext context = BackbaseContext.getCurrentInstance();
        context.addDeltaAction(jsAction);
        }

First I make a refresh and then I call to this focus method:

public void pvImporte (CustomActionEvent event) {
   // Modify some data in my bean, refresh and focus
   listGrid.refresh(data);
   listGrid.focus(event.getComponent());

As you can see in the snippet, I'm changing the 'value' property. I'm doing it to check the DeltaActionJavaScript out. It works fine, but the bb.command.focus(element) has no effect.

However, if I execute this code from another handler (a button, for example) it works fine and my component is focused.

The code in my jsp is:

<bjsf:column>
        <f:facet name="header">
                <bjsf:outputText value="Valorado" width="10%" styleClass="x"/>
        </f:facet>
        <bjsf:inputText id="importeValorado"
                       value="#{desglose.p_importe}"
               customActionListener="#{AP700113.pvImporte}" >

               <f:verbatim>
                   <e:handler event="blur" type="text/javascript">
                        bb.bjsf.sync('custom');
                   </e:handler>        
               </f:verbatim>
         </bjsf:inputText>
</bjsf:column>
<bjsf:column>
        <f:facet name="header">
                <bjsf:outputText value="Liquidado" width="10%" styleClass="x"/>
        </f:facet>
        <bjsf:inputText id="importeLiquidado"
                        value="#{desglose.p_imp_liq}">

        </bjsf:inputText>
</bjsf:column>

Could you help me please??

Hi David, It appears that

Hi David,

It appears that it is also possible to achieve this the following way.

In my listGrid I implement the updateListner.

When the update method gets called, first it gets the selected rox index, then requests a refresh and later reselects a row with the stored selected index.

e.g.

public void update(UpdateEvent event)
        {

                String selectedRow = grid.getSelectedRowsCommaString();//get row index
                grid.refresh(area); // redraw
                grid.setSelectedRowsCommaString(selectedRow);set row index
               
        }

Hope this helps,

-Senaka

OK Senaka, I'll try it

OK Senaka, I'll try it out.
By the way, I've noticed something related to de DeltaActionJavascript, it seems that I cannot focus a component different than the component passed to the DeltaActionJavascript constructor, is it right?

David

I've tried it out ans it

I've tried it out ans it works fine in FF but it doesn't in IE, I'm using both listGrid.setSelectedRowsCommaString and DeltaActionJavaScript to set the focus, but the ;bb.command.focus(element) sentence has no effect in IE.

Regards
David

focus

Hi David,

It is really strange, the solution is just work for me. I guess there is something else which make this problem occuring. We have already tried it in 3 browser, FF, IE7, and even IE6.

I have looked your code again. I am just wondering for these code below

         <bjsf:inputText id="importeValorado"
                       value="#{desglose.p_importe}"
               customActionListener="#{AP700113.pvImporte}" >

               <f:verbatim>
                   <e:handler event="blur" type="text/javascript">
                        bb.bjsf.sync('custom');
                   </e:handler>        
               </f:verbatim>
         </bjsf:inputText>

the bb.bjsf.sync('custom') shouldn't it be like bb.bjsf.sync(this, 'custom') ?

And why do you make a customActionListener to call the focus method, why not using the updateListener instead?

Andys

Yes, you're right, I wrote

Yes, you're right, I wrote directly this code in the post and I did it wrong.
I'm not using the updateListener because I'm not using the edition mechanism from Backbase.
We have a strict requirement, in a listGrid not all the components in a column are editables or not, we must be able to render listGrids with editable components at cell level.
I've created a new inputText component extending yours and it renders an input text or a label depending on if this individual component has to be editable.
To decide wether a component is editable or not we use a new property and we use this way:

<bjsf:listGrid .... var="myRow">
....
<wtw:inputText id="price" value="myRow.price" editable="myRow.priceEditable"/>
...
</bjsf:listGrid>

this way, in the same column some inputs are editable and others aren't.
I hope you could understand me.
Kind regards
David

Hi again, first of all, I

Hi again,
first of all, I apologize for my insistence with this topic but it's really a fundamental requirement for us.
I think we don't understand each other and it's my fault, I didn't explain my problem properly.

You're making test with editable listGrids using the Backbase mechanism. As far as I know, with this mechanism the cell are initially displayed as labels (for example) and when user clicks twice in one one them, it becomes an inputText.

We have to present a listGrid with n editable fields at a time, user has to be able to move between them with TAB and when leaves avery cell a backing bean method must be invoked. This invocation can modify the others cells, so I have to refresh the grid.

I achieved every requirement except one, when user leaves a field, the next field gets focus, but the refresh() removes it.

As you know I tried with DeltaActionJavascript, but it doesn't work in IE.

I hope this clarify my problem

Thanks again and kind regards
David

Listgrid looses focus

Hi David,

It looks like that we might have different understanding for this case.
Would you like to send the file or war file? It might help me a lot to investigate the real application code you have. It's really confusing for us (Senaka and I) because in our simplified test case it does work. It might have something to do with the customization or another application logic in your application.

You can attach the war file or even send it by email to me or Senaka.

Andys