JSF is server-side processing.   So anything that JSF does requires a
form submit.

You can try marking the input field and the triggering action (not
actionListener) as immediate.   That should cause it to validate and
execute your action before the other fields.  I think this will also
short-circuit the rest of the JSF processing, and you won't get
validation errors for other fields.   I could be wrong, though.

However, you're also going to short-circuit the model-update phase, so
you may find this makes it difficult to accomplish your goal of
reading values and updating values on components.

The way I've handled this in my own project is to use javascript to
force an immediate submit, and create an optional validation framework
(OVF) that allows the full JSF lifecycle to execute even though some
components fail to validate.

The example below (combined with the OVF) would submit the change, but
not perform any validation or model updates for components with
optional validators.  For my own use case, I want the validation
errors to show up, but not stop the lifecyle, so it reads "soft"
instead of "none" in the example code.   This allows components that
pass validation to be available after the updateModel phase.

Unfortunately, it's still an "all or nothing" situation for components
marked as optionally-validating.   On my todo list is to allow you to
dynamically group components, depending on the control causing the
action, so that some components are non-validating, some are
soft-validating (generate error messages, but don't short-circuit the
lifecycle) and some are hard-validating (standard JSF behavior where a
validation error ends the current lifecyle).  I haven't decided
whether the best implementation for this is to specify controls by id
(soft="inputText1,inputText2", hard="inputText3", none="inputText4")
or by somehow specifying groups on the optional validators.

Quite honestly, if you have the ability to do this all in pure
javascript, that's the easier solution.  Doing conditional validation,
especially when you need some components to be valid afterward, is
hard in JSF.

<h:selectOneMenu
    id="namedLocationInput"
    onchange="pulldownChanged()"
    value="#{dataModel.workorder.physicalLocation}"
    title="No location selected"
    >
        <f:selectItems value="#{page.physicalLocationItems}"/>
</h:selectOneMenu>

<script language="javascript">
// <![CDATA[
    function pulldownChanged(){
        clear_form();
        
document.forms['form'].elements['NET_SF_JSFC_OPT_VDTR_MODE'].value='none';
        document.getElementById("form:nonclearingRefreshButton").click();
    }
// ]]>

<f:verbatim>
    <input type="submit" style="display: none;"
onclick="document.forms['form'].elements['autoScroll'].value=getScrolling();"
value="Submit" name="form:refreshButton"
id="form:nonclearingRefreshButton"/>
</f:verbatim>


On 10/25/05, Jeffrey Porter <[EMAIL PROTECTED]> wrote:
>
>
>
>
> The spec says ...
>
> MethodBinding representing a value change listener method that will be
> notified when a new value has been set for this input component.
>
> I was left with the impression from this that when the field's value changes
> then the method would get called. Not when the form is submitted.
>
> I don't need to process the form. I'm in the situation where a person types
> in a "part number", and the several other fields are auto populated from
> that value (i.e. the part description & manufacture). The form is not
> submitted thought till they have entered a load of other details.
>
> I guess I can look at getting some javascript to do this. But it's a shame
> there isn't a method for this in MyFaces.
>
> I see that I can write something like this…
>
> <h:selectBooleanCheckbox
>
>         valueChangeListener="#{resumeBean.changeColorMode}"
>
>       onchange="submit()"
>
>       immediate="true"/>
>
> But this results in the form being submitted & error messages being
> displayed because of fields not filled. This would confuse the user, since
>
> They've not pressed the submit button yet.
>
> Jeff.
>
>
>
>
> -----Original Message-----
>  From: Bruno Aranda [mailto:[EMAIL PROTECTED]
>  Sent: 25 October 2005 11:57
>  To: MyFaces Discussion
>  Subject: Re: valueChangeListener - inputText - Which method is correct?
>
>
> Yes, but the ValueChangeEvent will be processed in the Process
>
> Validations phase, after submitting the form. So if you want to change
>
> the value of the other inputText when the first changes, you need to
>
> submit the form (technique #1). Otherwise, you can use javascript if
>
> it is an option to you (if you don't have to process the form).
>
> Hope it is clear now,
>
> Bruno
>
> 2005/10/25, Jeffrey Porter
> <[EMAIL PROTECTED]>:
>
> >
>
> > Thanks Bruno. Great links.
>
> >
>
> >
>
> > The spec for h:inputText states that it has the MethodBinding attribute
>
> > valueChangeListener.
>
> >
>
> > So if I set this as...
>
> >
>
> > <h:inputText id="name" value="#{ncm.name}" required="true"
>
> > valueChangeListener="#{ncm.changeEvent}" />
>
> >
>
> > Should it not call my method in the ncm class?
>
> >
>
> > public void changeEvent(ValueChangeEvent event) {
>
> >         String partNo = ((String)event.getNewValue());
>
> > }
>
> >
>
> > Or am I missing something?
>
> >
>
> > Jeff.
>
> >
>
> >
>
> >
>
> > -----Original Message-----
>
> > From: Bruno Aranda [mailto:[EMAIL PROTECTED]
>
> > Sent: 25 October 2005 11:34
>
> > To: MyFaces Discussion
>
> > Subject: Re: valueChangeListener - inputText - Which method is correct?
>
> >
>
> > If it applies, you can use the technique explained in
>
> > http://wiki.apache.org/myfaces/SubmitPageOnValueChange
> using the
>
> > inputText instead of the selectOneMenu. It should work.
>
> > Or if you want to play with javascript you can take a look at
>
> > http://www.irian.at/myfaces/jslistener.jsf to see how the
> jslistener
>
> > works,
>
> >
>
> > Regards,
>
> >
>
> > Bruno
>
> >
>
> > 2005/10/25, Jeffrey Porter
> <[EMAIL PROTECTED]>:
>
> > >
>
> > >
>
> > >
>
> > > I've seen 3 different examples of using the "valueChangeListener"
>
> > attribute.
>
> > >
>
> > >
>
> > >
>
> > > I've seen...
>
> > >
>
> > >
>
> > >
>
> > > Example 1:
>
> > >
>
> > >
>
> > >
>
> > > JSP <h:inputText value="foo">
>
> > >  <f:valueChangeListener type="com.jsf.MyValueChangeListener"/>
>
> > > </h:inputText>
>
> > >
>
> > >
>
> > >
>
> > >
>
> > > CODE public class MyValueChangeListener implements ValueChangeListener
>
> > {
>
> > >   public MyValueChangeListener() {  }
>
> > >
>
> > >   public void processValueChange(ValueChangeEvent vce)
>
> > > throws AbortProcessingException  {
>
> > >      System.out.println("A value has changed!");
>
> > >   }
>
> > > }
>
> > >
>
> > >
>
> > >
>
> > >
>
> > > Example 2:
>
> > >
>
> > >
>
> > >
>
> > > JSP
>
> > >
>
> > > <h:inputText id="partNumber"
>
> > > value="#{nonConformingMaterial.partNumber}"
> required="true"
>
> > >
>
> > >
> valueChangeListener="#{nonConformingMaterial.changeEvent}"
>
> > >
>
> > >       onclick="submit()"
>
> > >
>
> > >       immediate="true"
>
> > >
>
> > > />
>
> > >
>
> > >
>
> > >
>
> > > Example 3:
>
> > >
>
> > >
>
> > >
>
> > > JSP <s:inputSuggestAjax
>
> > suggestedItemsMethod="#{inputSuggestAjax.getItems}"
>
> > > styleLocation="" />
>
> > >
>
> > >
>
> > >
>
> > >
>
> > >
>
> > >
>
> > >
>
> > >
>
> > > I like example 3, very sexy. (see
>
> > > http://irian.at/myfaces-sandbox/inputSuggestAjax.jsf)
>
> > >
>
> > > But it's not what I need in my application.
>
> > >
>
> > >
>
> > >
>
> > > What I need is, when an inputText is filled in, an action is called so
>
> > that
>
> > > another inputText field is automatically filled in.
>
> > >
>
> > >
>
> > >
>
> > > I presume that I should be trying to get example 1 working. Would you
>
> > agree?
>
> > >
>
> > >
>
> >

Reply via email to