|
Thanks Stefan. You response was a great help.
I’m still left with one question though.
I’ve been following the tutorial from the IBM website (see http://www-128.ibm.com/developerworks/java/library/j-jsf2/index.html)
So I have a Manager class the references the bean. The Manager class contains the method called by jsp onchange (keeping the logic away from the holding bean)
E.g.
<h:inputText valueChangeListener="#{ncmManager.firstnameSelected}" value="#{ncmManager.bean.firstname}" immediate="true" onchange="submit()" /> <h:inputText immediate="true" id="surname" value="#{ncmManager.bean.surname}" required="true" />
public class NonConformingMaterialManager implements java.io.Serializable { private Bean bean; { bean = new Bean(); // contains 2 fields firstname & surname + getter/setter methods } public void firstnameSelected(ValueChangeEvent vce) { // do stuff } }
My question is this. How do I change other values in the page? I want to change the value of surname based on what the firstname value is. I can get the firstname value from the event.
The only code I can find to change the value of the surname field is…
UIInput input2 = (UIInput) ctxt.getViewRoot().findComponent("body").findComponent("_id0").findComponent("surname"); input2.setValue("newSurname");
If I have to do this, and can’t use the member variable (bean), then what is the point of having the “bean” in the manager class & having the jsp tags use the attribute value="#{ncmManager.bean.firstname}" ????
If the firstnameSelected method was on the actual Bean class, then I could access the surname directly. Since my method is on a Manager class though, I can’t.
I hope that made some scene.
Thanks for any input on this.
Jeff
-----Original Message-----
Jeff
1) Shouldn’t this ctxt.getExternalContext().getSessionMap().put(“SHOWTHIS”, “partNumber”); be ctxt.getExternalContext().getSessionMap().put( “partNumber”, “SHOWTHIS”);
surely the component id is the key
2) You could use something like <h:inputText id="partNumber" value="#{nonConformingMaterial.partNumber}" required="true" immediate="true" onchange="submit()"valueChangeListener=”#{nonConformingMaterial. processValueChange” />
so you would move public void processValueChange(ValueChangeEvent vce) throws AbortProcessingException { into your backing bean class and then your code would have direct access to the getter/setter methods
getPartNumber() & setPartNumber() so your code could
public void processValueChange(ValueChangeEvent vce) throws AbortProcessingException { String partNo = ((String)vce.getNewValue()); System.out.println("A value has changed!" + partNo);
setPartNumber(partNo); FacesContext ctxt = FacesContext.getCurrentInstance(); ctxt.renderResponse(); }
3) The doesn’t fire until the component loses focus
If this is NOT OK then you should consider using
Stefan Maric | IT & Professional Services | BT Global Services E: [EMAIL PROTECTED] | www.bt.com/globalservices
This electronic message contains information from British Telecommunications plc, which may be privileged or confidential. The information is intended for use only by the individual(s) or entity named above. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is strictly prohibited. If you have received this electronic message in error, please notify me by telephone or email (to the number or email address above) immediately.
Activity and use of the British Telecommunications plc e-mail system is monitored to secure its effective operation and for other lawful business purposes. Communications using this system will also be monitored and may be recorded to secure effective operation and for other lawful business purposes.
British Telecommunications plc. Registered office: 81 Newgate Street London EC1A 7AJ Registered in England no: 1800000 <hr size=2 width="100%" align=center tabindex=-1> From: Jeffrey
Porter [mailto:[EMAIL PROTECTED]
I have the code that calls my ValueChangeListener implementation. That part works, the bit I’m having trouble with is setting the new a value on page.
JSP… <h:inputText id="partNumber" value="#{nonConformingMaterial.partNumber}" required="true" immediate="true" onchange="submit()" > <f:valueChangeListener type="org.me.jsf.actions.NonConformingMaterialAL"/> </h:inputText>
The code I have is…
CODE… public class NonConformingMaterialAL implements ValueChangeListener {
public void processValueChange(ValueChangeEvent vce) throws AbortProcessingException {
String partNo = ((String)vce.getNewValue()); System.out.println("A value has changed!" + partNo);
// This doesn’t save & show the new value.?!??! FacesContext ctxt = FacesContext.getCurrentInstance(); if (null != vce.getNewValue()) { ctxt.getExternalContext().getSessionMap().put(“SHOWTHIS”, “partNumber”); }
ctxt.renderResponse(); } }
This doesn’t set the value “SHOWTHIS” in the field though.
Can someone please help?
Thanks Jeff. |
- RE: Help still needed with valueChangeListener Jeffrey Porter
- Re: Help still needed with valueChangeListener Volker Weber
- RE: Help still needed with valueChangeListener Jeffrey Porter
- Re: Help still needed with valueChangeListener Volker Weber
- Re: Help still needed with valueChangeListener Volker Weber
- Re: Help still needed with valueChangeListener Mike Kienenberger
- RE: Help still needed with valueChangeListener Jeffrey Porter
- Re: Help still needed with valueChangeListener Mike Kienenberger
- RE: Help still needed with valueChangeListener Jeffrey Porter
- Re: Help still needed with valueChangeListener Mike Kienenberger
- RE: Help still needed with valueChangeListener Jeffrey Porter

