This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Feb 10, 2013, 10:28 PM
41 Posts
topic has been resolvedResolved

Editing a multi value field

  • Category: Other
  • Platform: Windows
  • Release: 8.5.3
  • Role: Developer
  • Tags: Multi Value Field editing
  • Replies: 2
Hi,
 
Hoping for a bit of help.  Was searching for the best way to edit multi value fields.  Came across Tommy Valand's code that uses a repeat control.  The the only addition I wanted was to delete an item.  Below is the code
 

<div>

<xp:inputText

value="#{document1.CarQualMin}" styleClass="fld" id="inputText3">

<xp:this.rendered><![CDATA[#{javascript:return ( document1.getItemValueArray( 'CarQualMin' ).length < 2 );}]]></xp:this.rendered>

</xp:inputText>

</div>

<xp:repeat value="#{document1.CarQualMin}"

var="item" indexVar="itemIndex">

<xp:inputText styleClass="fld" id="inputText4">

<xp:this.rendered><![CDATA[#{javascript:return ( document1.getItemValueArray( 'CarQualMin' ).length > 1 );}]]></xp:this.rendered>

<xp:this.value><![CDATA[#{document1.CarQualMin[itemIndex]}]]></xp:this.value>

</xp:inputText>

&#160;&#160;

<xp:button value="Delete" id="button8">

<xp:this.rendered><![CDATA[#{javascript:return ( document1.getItemValueArray( 'CarQualMin' ).length > 1 );}]]></xp:this.rendered>

<xp:eventHandler event="onclick"

submit="true" refreshMode="complete"

disableValidators="true" id="eventHandler4">

<xp:this.action><![CDATA[#{javascript: document1.getValue( "CarQualMin" ).remove( itemIndex )}]]></xp:this.action>

</xp:eventHandler>

</xp:button>

<xp:br id="br2"></xp:br>

</xp:repeat>

What I'm finding is that add works fine, but changing an existing item or deleting an item doesn't save the changes to the back end document.  Below is the save code
 
 

<xp:button value="Save" id="button2"

style="color:rgb(0,0,0)"

rendered="#{javascript:currentDocument.isEditable()}">

<xp:eventHandler event="onclick" submit="true" refreshMode="complete">

<xp:this.action>

<xp:save name="$$PreviousPage"></xp:save>

</xp:this.action></xp:eventHandler></xp:button>
Is there something I've missed?  Thanks for any help
 
Cameron 

Feb 13, 2013, 9:19 AM
3 Posts
Re: Editing a multi value field
Hello, I believe that the Delete button removes the item from a copy of the values returned by getValue() method and stored in memory. You need to write the copy back to the document like this:
 
var tmpValues:java.util.Vector = document1.getValue("CarQualMin");
tmpValues.remove(itemIndex);
document1.replaceItemValue("CarQualMin", tmpValues);
 
Did you consider using the Dojo List Text Box component from the Upgrade Pack 1?  It renders multivalue field items with a small x next to each item allowing you to easily delete that particular value, very handy. You can than have an edit box bound to, for example, a request scope variable and a button which adds value from that variable to the document item. Something like this works for me:
 
<xp:inputText value="#{requestScope.newCarMin}" styleClass="fld" id="inputText3"></xp:inputText>
        <xp:button value="Add" id="button1">
            <xp:eventHandler event="onclick" submit="true"
                refreshMode="complete">
                <xp:this.action><![CDATA[#{javascript:var tmpValues = document1.getItemValue("CarQualMin");    //read current values
tmpValues.add(requestScope.get("newCarMin"));            //add a new one bound to edit field
document1.replaceItemValue("CarQualMin", tmpValues);    //store the values back to document
requestScope.put("newCarMin", "");                        //and clear the scope variable to clear the edit field}]]></xp:this.action>
            </xp:eventHandler></xp:button>
Feb 14, 2013, 10:22 PM
41 Posts
Re: Editing a multi value field
Hi Jan,
 
Thanks for your reply.  Ended up using a multi-line edit box instead.  I'll give your suggestions a try though, as I did like the add/delete/edit of the solution I was using.
 
Regards,
 
Cameron

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal