You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Leonardo Uribe (JIRA)" <de...@myfaces.apache.org> on 2007/11/01 07:57:50 UTC
[jira] Commented: (MYFACES-1729) label attribute does not resolve
EL expresion (JSR 252 Issue 6 related)
[ https://issues.apache.org/jira/browse/MYFACES-1729?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12539295 ]
Leonardo Uribe commented on MYFACES-1729:
-----------------------------------------
Fortunately there was a discussion about this on javaserverfaces dev list that mention this trick the last week that helps me to
understand what are they doing.
I have looked at the RI, and they have this trick on MessageFactory:
static Object getLabel(FacesContext context,
UIComponent component) {
Object o = component.getAttributes().get("label");
if (o == null || (o instanceof String && ((String) o).length() == 0)) {
o = component.getValueExpression("label");
}
// Use the "clientId" if there was no label specified.
if (o == null) {
o = component.getClientId(context);
}
return o;
}
As I supposed by deduction creating my solution, they return the ValueExpression
of label for later evaluation. But In my solution I get the expression string instead the ValueExpression Object.
At creating a message:
static FacesMessage getMessage(Locale locale,
String messageId,
Object... params) {
/*.......... */
// At this point, we have a summary and a bundle.
FacesMessage ret = new BindingFacesMessage(locale, summary, detail, params);
/*.......... */
}
So, they have a custom FacesMessage that resolve bindings on demand. The implementation of getDetail shows this:
public String getDetail() {
String pattern = super.getDetail();
resolveBindings();
return getFormattedString(pattern, resolvedParameters);
}
My solution evaluate all the detail and summary String in one step, trying to minimize the changes,
they save the array of params, the message string and resolve them later.
It's a different solution to the same problem, but I think it's compatible with my solution.
> label attribute does not resolve EL expresion (JSR 252 Issue 6 related)
> -----------------------------------------------------------------------
>
> Key: MYFACES-1729
> URL: https://issues.apache.org/jira/browse/MYFACES-1729
> Project: MyFaces Core
> Issue Type: Bug
> Components: JSR-252
> Affects Versions: 1.2.1-SNAPSHOT
> Environment: Tomcat 6, Windows XP
> Reporter: Leonardo Uribe
> Attachments: patchFinalSolution.patch
>
>
> When validation is applied to the following page:
> <%@ page session="false" contentType="text/html;charset=utf-8"%>
> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
> <html>
> <f:view>
> <%@include file="inc/head.inc"%>
> <body>
> <f:loadBundle basename="org.apache.myfaces.examples.resource.example_messages" var="example_messages"/>
> <h1>Myfaces Examples JSF 1.2 Additions</h1>
> <h:messages id="messageList" styleClass="error"/>
> <h:form id="form1">
> <h:panelGrid columns="4">
> <h:outputLabel for="form1:number1"
> value="#{example_messages['sample1_number']} 1 :" />
> <h:outputText value="#{validationController.number1ValidationLabel}" />
> <h:inputText label="#{example_messages['sample1_number']}"
> id="number1" value="#{calcForm.number1}" maxlength="10"
> size="25" required="true">
> <f:validateLongRange minimum="1" maximum="10" />
> </h:inputText>
> <h:message id="number1Error" for="form1:number1" styleClass="error" />
> </h:panelGrid>
> <h:panelGrid columns="4">
> <h:outputLabel for="form1:number2"
> value="#{example_messages['sample1_form']} 2 :" />
> <h:outputText value="#{validationController.number2ValidationLabel}" />
> <h:inputText label="#{example_messages['sample1_form']}"
> id="number2" value="#{calcForm.number2}" maxlength="10"
> size="25" required="true">
> <f:validateLongRange minimum="20" maximum="50" />
> </h:inputText>
> <h:message id="number2Error" for="form1:number2" styleClass="error" />
> </h:panelGrid>
> <h:panelGrid columns="2">
> <h:outputLabel for="form1:result"
> value="#{example_messages['sample1_result']} :" />
> <h:outputText id="result" value="#{calcForm.result}" />
> </h:panelGrid>
> <h:panelGrid columns="4">
> <h:commandButton id="addButton"
> value="#{example_messages['sample1_add']}" action="none">
> <f:actionListener
> type="org.apache.myfaces.examples.example1.CalcActionListener"></f:actionListener>
> </h:commandButton>
> <h:commandButton id="subtractButton"
> value="#{example_messages['sample1_sub']}" action="none">
> <f:actionListener
> type="org.apache.myfaces.examples.example1.CalcActionListener"></f:actionListener>
> </h:commandButton>
> <h:commandLink id="href1" action="none">
> <h:outputText value="#{example_messages['sample1_add_link']}" />
> <f:actionListener
> type="org.apache.myfaces.examples.example1.CalcActionListener"></f:actionListener>
> </h:commandLink>
> <h:commandLink id="href2" action="none">
> <h:outputText value="#{example_messages['sample1_sub_link']}" />
> <f:actionListener
> type="org.apache.myfaces.examples.example1.CalcActionListener"></f:actionListener>
> </h:commandLink>
> </h:panelGrid>
> </h:form>
> </body>
> </f:view>
> </html>
> If you use the attribute label on inputText like this:
> <h:inputText label="#{example_messages['sample1_number']}"
> id="number1" value="#{calcForm.number1}" maxlength="10"
> size="25" required="true">
> <f:validateLongRange minimum="1" maximum="10" />
> </h:inputText>
> and a validation error happens, the EL expression inside label attribute returns null. On a message box this looks like:
> null: Validation Error: Specified attribute is not between the expected values of 20 and 50.
> On JSF RI 1.2 this works correctly. null is replaced by the expression inside the bundle.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.