Jeff,

Read through http://wiki.apache.org/myfaces/How_The_Immediate_Attribute_Works
and make sure JSF behavior matches your expectations.

-Mike

On 10/26/05, Jeffrey Porter <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> I've complied my code into an example ear.
>
> http://www.jeffreyporter.pwp.blueyonder.co.uk/ebusiness.ear
>
>
>
> This example will be deployed to…
>
> http://localhost:8080/ebusiness/
>
>
>
> The code in the EAR works. But it's a big fudge!
>
>
>
> Code that works is..
>
>
>
> boolean x = true; // set to false to turn on other code.
>
>
>
> if (x) {
>
>                         UIInput input2 = (UIInput)
> ctxt.getViewRoot().findComponent("body").findComponent("_id0").findComponent("firstname");
>
>             input2.setValue("firstname");
>
>
>
>                         input2 = (UIInput)
> ctxt.getViewRoot().findComponent("body").findComponent("_id0").findComponent("surname");
>
>                         input2.setValue("Surname");
>
> }
>
>
>
> Code that doesn't work is…
>
>
>         bean.setFirstname(firstName+ "::");
>
>         bean.setSurname("yyyyyyyyyyy");
>
>
>
>
>
> The code can be found in
>
>
>
> Ebusiness.ear/ebusiness.war/WEB-INF/lib/ebusiness-support-action.jar
>
>
>
>
>
> If anyone has any ideas on what I'm missing, please do tell.
>
>
>
> Thanks
>
> Jeff.
>
>
>
>
>
>
>
>
> -----Original Message-----
>  From: Jeffrey Porter
> [mailto:[EMAIL PROTECTED]
>  Sent: 26 October 2005 13:08
>  To: MyFaces Discussion
>  Subject: RE: Help still needed with valueChangeListener
>
>
>
> Hi Stefan,
>
>
>
> I've removed the saveState, but no change.
>
> I also have the context-param in my web.xml.
>
>
>
> The difference between what I've got & what you posted below, is that I've
> not got my action method on the bean.
>
> Instead it's on a Manager class.
>
>
>
> Jeff.
>
>
>
>
>
>
>
>
>
> -----Original Message-----
>  From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>  Sent: 26 October 2005 13:01
>  To: [email protected]
>  Subject: RE: Help still needed with valueChangeListener
>
>
>
> Jeff
>
> I haven't been using
>
> <t:saveState
>
>
>
> So I'm not sure if you should have this
>
>
>
> I use
>
>       <context-param>
>
>             <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
>
>             <param-value>client</param-value>
>
>       </context-param>
>
>
>
> In my web.xml
>
>
>
>
>
>
> 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]
>  Sent: Wednesday, October 26, 2005 12:22 PM
>  To: MyFaces Discussion
>  Subject: RE: Help still needed with valueChangeListener
>
>
>
> Hi Stefan,
>
>
>
> This is what I'm trying at the moment.
>
>
>
> This though doesn't change the value displayed on the web page.
>
>
>
> The member variable has the new value set, but the value displayed on the
> page doesn't change.
>
> When the method, firstnameSelected, gets called a second time I can see the
> modified value in the bean instance.
>
>
>
> I'm at a loss of why this doesn't work.
>
>
>
> Jeff.
>
>
>
> The code I have is…
>
>
>
> CODE…
>
> FacesContext ctxt =  FacesContext.getCurrentInstance();
>
>
>
> String firstName = ((String)vce.getNewValue());
>
> System.out.println("A value has changed!" + firstName);
>
>
>
> bean.setFirstname(firstName);
>
> bean.setSurname("yyyyyyyyyyy");
>
>
>
> FacesContext.getCurrentInstance().renderResponse();
>
>
>
> JSP…
>
> <body>
>
> <f:view>
>
>       <t:saveState id="saveStateBean01" value="#{ncmManager}"/>
>
>       <h:panelGroup id="body">
>
>       <h:form>
>
>
>
>       <h:inputText
>
>             id="firstname"
>
>             valueChangeListener="#{ncmManager.categorySelected}"
>
>             value="#{ncmManager.bean.firstname}"
>
>             immediate="true"
>
>             onblur="submit()"
>
>       />
>
>
>
>       <h:inputText immediate="true" id="surname"
> value="#{ncmManager.bean.surname}" required="true" />
>
>
>
>      </h:form>
>
>       </h:panelGroup>
>
> </f:view>
>
> </body>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> -----Original Message-----
>  From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>  Sent: 26 October 2005 12:11
>  To: [email protected]
>  Subject: RE: Help still needed with valueChangeListener
>
>
>
> Jeff
>
>
>
> I want to change the value of surname based on what the firstname value is.
>
> I can get the firstname value from the event
>
>
>
>
>
> private Bean bean = new Bean(); // contains 2 fields firstname & surname +
> getter/setter methods
>
>
>
> This is a member variable of your NonConformingMaterialManager Class
>
> and is accessible to ANY method within NonConformingMaterialManager
>
>
>
> So in your firstnameSelected method you can perform Surname manipulation
> using
>
> bean.setSurname("…..");
>
>
>
>
>
> public void firstnameSelected(ValueChangeEvent vce) {
>
>
>
> bean.setFirstName((String)vce.getNewValue());
>
>
>
> // do Surname stuff
>
> Bean.setSurname("<modified value>");
>
>
>
>
>
>             //          Now update GUI
>
>             FacesContext.getCurrentInstance().renderResponse();
>
> }
>
>
>
> Hope this is what you're looking for
>
>
>
>
> 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]
>  Sent: Wednesday, October 26, 2005 11:44 AM
>  To: MyFaces Discussion
>  Subject: RE: Help still needed with valueChangeListener
>
>
>
>
>
> 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-----
>  From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>  Sent: 26 October 2005 09:38
>  To: [email protected]
>  Subject: RE: Help still needed with valueChangeListener
>
>
>
> 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 onchange="… doesn't fire until the component loses focus
>
>
>
> If this is NOT OK then you should consider using onclick="…
>
>
>
>
>
>
> 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]
>  Sent: Tuesday, October 25, 2005 4:04 PM
>  To: MyFaces Discussion
>  Subject: Help still needed with valueChangeListener
>
>
>
>
>
>
>
> 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="...
>
> [Message clipped]

Reply via email to