EL: Illegal syntax. in JSF + primefaces

1

Please, I would like to know what is wrong with this expression.

<p:inputText id="text_url"
            disabled="#{menuBean.tipoMenu.equalsIgnoreCase('I')?false:true}"
            value="#{menuBean.tipoMenu.equals('I')?menuBean.menu.formularioAsociado:'#'}"
            style="width: 400px" required="false"
            requiredMessage="Completar URL!" />

Send me the following error.

GRAVE: javax.faces.component.UpdateModelException: javax.el.PropertyNotWritableException: /administrador/menu.xhtml @68,42 value="#{menuBean.tipoMenu.equalsIgnoreCase('I')?menuBean.menu.formularioAsociado:'#'}": Sitáxis ilegal para Operación de Poner Valor
at javax.faces.component.UIInput.updateModel(UIInput.java:868)
at javax.faces.component.UIInput.processUpdates(UIInput.java:751)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
at org.primefaces.component.fieldset.Fieldset.processUpdates(Fieldset.java:232)
at javax.faces.component.UIForm.processUpdates(UIForm.java:281)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
at org.primefaces.component.layout.Layout.processUpdates(Layout.java:255)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1254)
at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:412)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1385)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.el.PropertyNotWritableException: /administrador/menu.xhtml @68,42 value="#{menuBean.tipoMenu.equalsIgnoreCase('I')?menuBean.menu.formularioAsociado:'#'}": Sitáxis ilegal para Operación de Poner Valor
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:136)
at javax.faces.component.UIInput.updateModel(UIInput.java:834)
... 37 more
Caused by: javax.el.PropertyNotWritableException: Sitáxis ilegal para Operación de Poner Valor
at org.apache.el.parser.SimpleNode.setValue(SimpleNode.java:137)
at org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:263)
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
... 38 more

And the context is this. That input has two 'scenarios' so to speak. In one you type the URL of the menu and in another you do not. For the second case I wanted to avoid leaving the input blank and put a value. And if they see in the previous attribute, the box can no longer be edited in that same case. The value with which the condition is evaluated comes from a combo that I leave below. The combo fulfills what I want satisfactorily.

<p:selectOneMenu id="text_tip" value="#{menuBean.tipoMenu}"
                onchange="">
    <f:selectItem itemLabel="SubMenu" itemValue="S" />
    <f:selectItem itemLabel="Item" itemValue="I" />
    <p:ajax update="text_url" />
</p:selectOneMenu>

Thanks in advance for any help. :)

    
asked by Hector Ccasani PerdidaMente 21.05.2018 в 18:59
source

1 answer

1

In a <p:inputText/> (and other types of input) the expression is not only used to "read" the value when preparing the HTML, but it is also used to indicate where it should be written, when processing the form, the value returned by the user.

Naturally, to write that value to a property the expression must indicate a property. The formula that you indicate can not be evaluated like that, so it gives you the value.

Normally you will do

<p:inputText value="#{menuBean.valorDelInputText}"/>

Now, for the property to be readable you need to have the getter ; so that it can be modified ( writtable ) has to exister the setter of the property:

public class MenuBean {

    public String getValorDelInputText() {
       ...
    }

    public void setValorDelInputText(String valor) {
       ...
    }
}

If you want to initialize the value, the best place to do it is in the @PostConstruct or in a corresponding JSF event handler.

As a curiosity, this use of EL is what makes #{} instead of ${} ; with ${} the expression is evaluated once and replaced, with #{} the expression is calculated but the expression is continued to be evaluated again later if necessary.

UPDATE: Please, do not change the question once answered; if your goal changes you can always create a new question.

In any case, if you have to execute logic when making an invocation with p:ajax using the attribute listener .

    
answered by 21.05.2018 в 19:42