-1

I have JSF text box like this

<p:outputLabel value="#{msgs['label.responsible']}:" for="printingResponsibleEdit"
                                rendered="#{b2cOrderDetailBean.b2cActionOrderView.canChangePrintingInfo() and 
                                                   b2cOrderDetailBean.b2cActionOrderView.showExecutionInfo}" />
                            <h:panelGroup id="printresponsible"
                                rendered="#{b2cOrderDetailBean.b2cActionOrderView.canChangePrintingInfo() and 
                                                  b2cOrderDetailBean.b2cActionOrderView.showExecutionInfo}">
                                <p:inputText id="printingResponsibleEdit" value="#{b2cOrderDetailBean.b2cActionOrderView.printingResponsiblePersNr}" size="4"
                                    valueChangeListener="#{b2cOrderDetailBean.changeListenerString}" required="true" immediate="true"
                                    requiredMessage="#{msgs['msg.required']}" binding="#{printingResponsibleBinding}" maxlength="4">
                                <f:attribute name="historyTypeCode" value="PR" /> 
                                </p:inputText>
                                <h:outputText value=" " />
                                <p:commandButton value="#{msgs['button.ok']}" immediate="true" process="printingResponsibleEdit"
                                    actionListener="#{b2cOrderDetailBean.requestPrintingResponsible}" escape="false"
                                    update="printingResponsibleName printingResponsibleEditMsg">
                               <f:attribute name="printingResponsible" value="#{printingResponsibleBinding.localValue}" /> 
                                <f:param name="responsiblePersonName" value="#{b2cOrderDetailBean.b2cActionOrderView.printingResponsiblePersNr}"></f:param>
                                </p:commandButton>
                                <h:outputText id="printingResponsibleName" value=" #{b2cOrderDetailBean.b2cActionOrderView.printingResponsible}" />
                            </h:panelGroup>
                            <p:message id="printingResponsibleEditMsg" for="printingResponsibleEdit" />

And i have my managed beans method like this

public void requestPrintingResponsible(ActionEvent actionEvent) {
        try {
            b2cActionOrderView.setPrintingResponsible(null);
            b2cActionOrderView.setPrintingResponsibleName(null);
            b2cActionOrderView.setPrintingResponsiblePersNr(null);
            String persNr = (String) actionEvent.getComponent().getAttributes().get("printingResponsible");
            if (persNr != null) {
                Account account = accountDelegate.findByPersNr(persNr, localeView.getLocale());
                b2cActionOrderView.setPrintingResponsible(account.getAccountId());
                b2cActionOrderView.setPrintingResponsibleName(account.getName());
                b2cActionOrderView.setPrintingResponsiblePersNr(account.getPersNr());
                validatedPrintingResponsible = account.getPersNr();

                                } else {
                b2cActionOrderView.setPrintingResponsible(null);
            }
        } catch (NoDataFoundException e) {
            LOG.warn("PersNr not found.", e);
            b2cActionOrderView.setPrintingResponsible(null);
            b2cActionOrderView.setPrintingResponsibleName(null);
            b2cActionOrderView.setPrintingResponsiblePersNr(null);
            MessageUtil.addFacesMessage("msg.notFound", colruyt.giftactionmgmt.util.Constants.MSG_PACKAGE, FacesMessage.SEVERITY_ERROR,
                    false, "form:tabView:printingResponsibleEdit", null);
        }


    }

My problem is when i enter a value that is there in the db and after that if i press ok button the corrensponding user name and user id is displayed but after that if i clear the value in the text box and if i press ok button must be filled error message is coming but the previous lable is not getting cleared. ie(username,user id). I have tried in many ways to achieve this can you guys help me

COL
  • 27
  • 1
  • 6

1 Answers1

0

Your problem is clear immediate="true"

When you put immediate="true" on your commandButton you simply say to JSF please skip any validation on form (including printingResponsibleEdit) and process this action (requestPrintingResponsible)

So how can JSF validate printingResponsibleEdit and render an updated p:message(printingResponsibleEditMsg) if you have already skipped the validation phase , See More on JSF lifecycle

Put on your mind you have to render(update) every single component you want it to be updated after Ok button is pressed or simply you can make h:panelGroup container to your component and give it an ID and update it ex: <p:commandButton ... update='containerId'/>.

Youans
  • 4,801
  • 1
  • 31
  • 57