can't get ice:selectbooleancheckbox to copy one component value to another component value
[Logo]
ICEsoft.org Forums: ICEfaces, ICEmobile, ICEpdf
[Search] Search   [Recent Topics] Recent Topics   [Groups] Home Page | www.icesoft.org  [Login] Login 
can't get ice:selectbooleancheckbox to copy one component value to another component value  XML
Forum Index -> Components
Author Message
databass

Joined: 26/09/2007 00:00:00
Messages: 4
Offline


I'm trying to make a checkbox that when clicked, should copy the mailing address string from the service address string.

I was hoping I could simply set the value of the mailing address to the service address in the checkbox's valueChangeListener.

But when the checkbox is checked, the mailing address doesn't get updated.

Also, I noticed that I can't get the value of the service address the first time the checkbox is checked, but it does give me the value on subsequent checkbox clicks.

These are the relevant parts of my xhtml and bean

form.xhtml

Code:
 <ice:form id="myForm">
 <ice:selectBooleanCheckbox id="copyMailingAddressFromOwner" required="false"
 valueChangeListener="#{newService.handleCopyMailingAddress}"
 value="#{newService.copyMailingAddressFromServiceAddress}" autocomplete="off" />
 mailing address: <ice:inputText id="mailingAddress" value="#{newService.mailingAddress}"/>
 <br/>
 service address: <ice:inputText id="serviceAddress" value="#{newService.serviceAddress}"/>
 </ice:form>
 


bean newServiceAction.java:
Code:
 @Stateful
 @Name("newService")
 @Scope(CONVERSATION)
 public class NewServiceAction implements NewService {
 
   public String getMailingAddress() {
 
     return mailingAddress;
   }
 
   public void setMailingAddress(String mailingAddress) {
     this.mailingAddress=mailingAddress;
   }
 
   public String getServiceAddress() {
     return serviceAddress;
   }
 
   public void setServiceAddress(String serviceAddress) {
     this.serviceAddress =serviceAddress;
   }
 
   public void handleCopyMailingAddress(ValueChangeEvent e) {
    if (!this.copyMailingAddressFromOwner)
 	{
                 this.setServiceAddress(this.getMailingAddress());
 
 	}
 	else
 	{
 		this.setServiceAddress("");
 	}	
 }
 


FYI, I'm using Icefaces 1.7.0 with Seam 2.0.1.GA
Also note that I have gotten this to work using what seems to be like a hack, when I put this code in the valueChangeListener for the checkbox:

Code:
     UIViewRoot viewRoot=javax.faces.context.FacesContext.getCurrentInstance().getViewRoot();
     
     UIInput input = (UIInput) viewRoot.findComponent("myForm:serviceAddress");
    input.setValue(newService.mailingAddress);
 


But obviously I'd like to avoid this since it requires using client-ids.

Any help would be greatly appreciated.

Thanks,
dave
patrick.corless

Joined: 26/10/2004 00:00:00
Messages: 1150
Offline


There's a couple things going on in your sample code. First consider enabling partial submit on the checkbox and inputText fields. This will insure that you bean values are updated on the blur event.

When the valueChangeListener is called without partial submit being enabled on the outputText field the JSF lifecycle will prevent you form getting the assumed value of the outputText field.

The valueChangeListener is fired in the Process Validation phase which is before the components dump their values into the beans. As a result any bean look ups will be out of date unless you access the component directly.

If you want to valueChangeListener to fire in the invoke application phase you can do the following:
Code:
public void handleCopyMailingAddress(ValueChangeEvent event) {
     if (event.getPhaseId() != PhaseId.INVOKE_APPLICATION) {
             event.setPhaseId(PhaseId.INVOKE_APPLICATION);
             event.queue();
      } else {
             // do some wor
      }
 }


[Email]
databass

Joined: 26/09/2007 00:00:00
Messages: 4
Offline


Thanks for the response.

I've put partialSubmit on all of the fields and
I'm now able to read values in the valueChangeListener.

But it still won't update the component values.

I assume that I would put the setServiceAddress method before setting the phaseId.. something like this?


Code:
public void handleCopyMailingAddress(ValueChangeEvent event) {
     if (event.getPhaseId() != PhaseId.INVOKE_APPLICATION) {
 
             this.setServiceAddress("my service address value");
 
             event.setPhaseId(PhaseId.INVOKE_APPLICATION);
             event.queue();
      } else {
             // do some wor
      }
 }





patrick.corless wrote:
There's a couple things going on in your sample code. First consider enabling partial submit on the checkbox and inputText fields. This will insure that you bean values are updated on the blur event.

When the valueChangeListener is called without partial submit being enabled on the outputText field the JSF lifecycle will prevent you form getting the assumed value of the outputText field.

The valueChangeListener is fired in the Process Validation phase which is before the components dump their values into the beans. As a result any bean look ups will be out of date unless you access the component directly.

If you want to valueChangeListener to fire in the invoke application phase you can do the following:
Code:
public void handleCopyMailingAddress(ValueChangeEvent event) {
     if (event.getPhaseId() != PhaseId.INVOKE_APPLICATION) {
             event.setPhaseId(PhaseId.INVOKE_APPLICATION);
             event.queue();
      } else {
             // do some wor
      }
 }


 
patrick.corless

Joined: 26/10/2004 00:00:00
Messages: 1150
Offline


It should actually be the other way around. Something like this.

Code:
public void handleCopyMailingAddress(ValueChangeEvent event) {
      if (event.getPhaseId() != PhaseId.INVOKE_APPLICATION) {
              event.setPhaseId(PhaseId.INVOKE_APPLICATION);
              event.queue();
       } else {
              // do some work in the invoke application phase
              // bean values are guaranteed to be up to date 
             this.setServiceAddress("my service address value");
       }
  }
[Email]
 
Forum Index -> Components
Go to:   
Powered by JForum 2.1.7ice © JForum Team