0
votes

I have a function to call which component on my XPage performs a submit to the server:

//Used to check which if a component triggered an update
function submittedBy( componentId ){
    try {       
        var eventHandlerClientId = param.get( '$$xspsubmitid' );
        var eventHandlerId = @RightBack( eventHandlerClientId, ':' );
        var eventHandler = getComponent( eventHandlerId );  
        if( !eventHandler ){ 
            return false; 
        }
        var parentComponent = eventHandler.getParent();     
        if( !parentComponent ){ 
            return false;
        }       
        return ( parentComponent.getId() === componentId );  
    } catch( e ){ /*Debug.logException( e );*/ }
}

I have a validator which is called normally via expression language:

validator="#{applicationValidators.valPhone}"

I would like to make the validator conditioned by a check if the submit is done by the element/component with the btnSave id on it e.g.

<xp:this.validator><![CDATA[#{javascript:if (submittedBy('btnSave')){
    return applicationValidators.valPhone();
}}]]></xp:this.validator>

but the valPhone funktion expects some inputs which are injected automatically if I call the method via EL:

public void valPhone(FacesContext facesContext, UIComponent component, Object value)

Is there a way to include the submittedBy function in the EL or must I supply the objects when calling the function in SSJS cause for now I get the error message:

Error while executing JavaScript action expression Script interpreter error, line=2, col=38: Java method 'valPhone()' on java class 'org.acme.projectx.test.ApplicationValidators' not found

When I apply the objects e.g.

applicationValidators.valPhone(facesContext,getComponent("inpPhone"),getComponent("inpPhone").getValue());

it does run the validator method but does not seem to know how to handle the response (in my case I throw a ValidatorExeption with a message.

Error while executing JavaScript action expression Script interpreter error, line=4, col=31: Error calling method 'valPhone(com.ibm.xsp.domino.context.DominoFacesContext, com.ibm.xsp.component.xp.XspInputText, java.lang.String)' on java class 'org.acme.projectx.test.ApplicationValidators' Phone is not valid

Phone is not valid is the string message that I included in the FacesMessagge that I throw in the ValidatorExeption.

1
Why are you not checking the submittedBy component in your validator?Sven Hasselbach

1 Answers

0
votes

I'd take a totally different approach:

  • create a page controller class
  • call a method in the controller when the button is clicked
  • do your validation based on your value(s) in that method
  • if validation fails create a message in the validation error stack

I don't have a reference right now but this would be much easier to program and control in general.