Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to copy data from one field to another field in JSF

 
test mike
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have this JSF code:
<h:selectBooleanCheckbox title="Address" value="#{address.addressMain}" > </h:selectBooleanCheckbox> <hutputText value="Same as with another Address?"/>

<h:inputText id="address1" required="true" value="#{address.address1}"/>

<h:inputText id="address2" required="true" value="#{address.address2}"/>

how can i copy data from one field to another field in JSF?

example: address1 to address2 as i click the checkbox?

im really having real hard time on this... please help..
 
Tim Holloway
Bartender
Posts: 18420
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Mike. But please read our Naming Policy (http://www.javaranch.com/name.jsp) and fix your display name. We appreciate it.

There are 2 ways to get values from one control on a form to another. It sounds like you want the job done client-side. In which case, you'd use JavaScript the same way that it works on regular HTML (non-JSF) pages to copy form data (or state, in the case of checkboxes).

The other way is server-side, but that means that the data is sent down to the server to update the form control's backing bean and the backing bean's setter method for the affecting control then invokes the setter method of the affected control. Like so:
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can implement this in couple of ways

1. use onClick/onChange javascript event.
2. make use of ValueChangeListener in JSF and use the listener class to do the copy process. You may have to set "immediate=true" for the checkbox to avoid validation and in the listener class you need to set response.something to true which I dont remember . just google it or search on javaranch, you can find examples for eventListeners

Thanks,
 
They weren't very bright, but they were very, very big. Ad contrast:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!