Re: Converter.getAsString not called?
I tried something similiar to this. I overwrote the validate method to say that if I have a submitted value but my converted value is null, don't reset the submitted value. This all works fine and dandy, but when I get into the RendererUtils.getStringValue method it is showing my submitted value as null. I traced through the code and I can not find who is resetting this value to null. Below is my method for validate and the section of code from RendererUtils that is failing. Any idea why submitted value would be showing as null? public void validate(FacesContext context) { if (context == null) throw new NullPointerException(context); Object submittedValue = getSubmittedValue(); if (submittedValue == null) return; Object convertedValue = getConvertedValue(context, submittedValue); if (!isValid()) return; validateValue(context, convertedValue); if (!isValid()) return; Object previousValue = getValue(); setValue(convertedValue); if (StringUtils.isNotEmpty((String)submittedValue) convertedValue != null) { setSubmittedValue(null); if (compareValues(previousValue, convertedValue)) { queueEvent(new ValueChangeEvent(this, previousValue, convertedValue)); } } else { queueEvent(new ValueChangeEvent(this, previousValue, convertedValue)); } } if (component instanceof EditableValueHolder) { Object submittedValue = ((EditableValueHolder)component).getSubmittedValue(); if (submittedValue != null) // FAILS HERE { if (submittedValue instanceof String) { return (String)submittedValue; } else { throw new IllegalArgumentException(Expected submitted value of type String for component : +getPathToComponent(component)); } } } Andrew Robinson-5 wrote: Yes that is a problem. Okay, another approach.: my:keepSubmitted h:inputText value=#{bean.value} / /my:keepSubmitted public class UIKeepSubmitted extends UIComponentBase { public void processValidators(FacesContext context) { UIInput child = (UIInput)getChildren().get(0); Converter converter = child.getConverter(); boolean localConverter = false; String submitted = child.getSubmittedValue(); if (converter != null) { localConverter = child.getValueBinding(converter) == null; child.setConverter(new ConverterWrapper(converter)); } super.processValidators(context); if (Boolean.FALSE.equals(child.getAttributes().get(ConverterWrapper.VALID_FLAG))) { child.setSubmittedValue(submitted); child.setLocalValue(null); child.setLocalValueSet(false); } child.setConverter(localConverter ? converter : null); } } public class ConverterWrapper implements Converter { public final static String VALID_FLAG = UIInputConversionSucceeded; private Converter orignal; public ConverterWrapper(Converter orignal) { this.original = original; } public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException { boolean valid = true; try { Object obj = original.getAsObject(context, component, value); if (!component.isValid()) { component.setValid(true); valid = false; } return obj; } catch (ConverterException ex) { component.setValid(true); valid = false; } finally { component.getAttributes().put(VALID_FLAG, Boolean.valueOf(valid)); } } public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException { return original.getAsString(context, component, value); } } If you want to use validators, you will have to wrap them too. On 7/10/07, Toppac [EMAIL PROTECTED] wrote: Small problem with this approach. If a component begins with value of Null and my custom converter returns a value of null for invalid values, the value change never fires. Andrew Robinson-5 wrote: Yes, it should jive, unless someone wrote a custom component extending UIInput that changes the behavior so that it doesn't agree with the specification. Process of validate: 1) check for submitted value, if none exit 2) get converter, and convert if found 3) check if valid, exit if not 4) validate the value 5) check if valid, exit if not 6) clear submitted value 7) set local value 8) check fire value change event Process of update: 1) check if valid, else return 2) check if local value is set, else return 3) set the value on the value binding 4) clear the local
Re: Converter.getAsString not called?
I found my problem. I am using Spring Webflow with the redirects turned on. It appears that when the redirect is issued, it is rebuilding the view and thus rebuilding my component, so any values I had set on the component are gone. I am not sure how to stop this. I have server state saving turned on so I thought it would retain the view, even with the redirect. Anyone have a suggestion? MyFaces configuration is below !-- MyFaces Configuration -- context-param param-namejavax.faces.STATE_SAVING_METHOD/param-name param-valueserver/param-value /context-param context-param param-nameorg.apache.myfaces.COMPRESS_STATE_IN_SESSION/param-name param-valuefalse/param-value /context-param context-param param-nameorg.apache.myfaces.SERIALIZE_STATE_IN_SESSION/param-name param-valuefalse/param-value /context-param context-param descriptionOnly applicable if state saving method is server (= default). Defines the amount (default = 20) of the latest views are stored in session. /description param-nameorg.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION/param-name param-value20/param-value /context-param Toppac wrote: I tried something similiar to this. I overwrote the validate method to say that if I have a submitted value but my converted value is null, don't reset the submitted value. This all works fine and dandy, but when I get into the RendererUtils.getStringValue method it is showing my submitted value as null. I traced through the code and I can not find who is resetting this value to null. Below is my method for validate and the section of code from RendererUtils that is failing. Any idea why submitted value would be showing as null? public void validate(FacesContext context) { if (context == null) throw new NullPointerException(context); Object submittedValue = getSubmittedValue(); if (submittedValue == null) return; Object convertedValue = getConvertedValue(context, submittedValue); if (!isValid()) return; validateValue(context, convertedValue); if (!isValid()) return; Object previousValue = getValue(); setValue(convertedValue); if (StringUtils.isNotEmpty((String)submittedValue) convertedValue != null) { setSubmittedValue(null); if (compareValues(previousValue, convertedValue)) { queueEvent(new ValueChangeEvent(this, previousValue, convertedValue)); } } else { queueEvent(new ValueChangeEvent(this, previousValue, convertedValue)); } } if (component instanceof EditableValueHolder) { Object submittedValue = ((EditableValueHolder)component).getSubmittedValue(); if (submittedValue != null) // FAILS HERE { if (submittedValue instanceof String) { return (String)submittedValue; } else { throw new IllegalArgumentException(Expected submitted value of type String for component : +getPathToComponent(component)); } } } Andrew Robinson-5 wrote: Yes that is a problem. Okay, another approach.: my:keepSubmitted h:inputText value=#{bean.value} / /my:keepSubmitted public class UIKeepSubmitted extends UIComponentBase { public void processValidators(FacesContext context) { UIInput child = (UIInput)getChildren().get(0); Converter converter = child.getConverter(); boolean localConverter = false; String submitted = child.getSubmittedValue(); if (converter != null) { localConverter = child.getValueBinding(converter) == null; child.setConverter(new ConverterWrapper(converter)); } super.processValidators(context); if (Boolean.FALSE.equals(child.getAttributes().get(ConverterWrapper.VALID_FLAG))) { child.setSubmittedValue(submitted); child.setLocalValue(null); child.setLocalValueSet(false); } child.setConverter(localConverter ? converter : null); } } public class ConverterWrapper implements Converter { public final static String VALID_FLAG = UIInputConversionSucceeded; private Converter orignal; public ConverterWrapper(Converter orignal) { this.original = original; } public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException { boolean valid = true; try { Object obj = original.getAsObject(context, component, value); if (!component.isValid()) { component.setValid(true); valid = false; } return obj; } catch
converter-for-class not set during RendererUtils
I've overwritten the default Integer converter with my own converter. I defined the converter in my faces-config using the converter-for-class. When I debug through the code I can see that during RendererUtils.getStringValue the converter is coming back as null, so the getAsObject method is not called. This is with MyFaces 1.1.4 using a Post-Redirect-Get model, in case that has a bearing. -- View this message in context: http://www.nabble.com/converter-for-class-not-set-during-RendererUtils-tf4070703.html#a11568404 Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: Converter.getAsString not called?
Interesting idea. But how will this jive with the code already implemented in UIInput that is clearing the submitted value, setting the local value and so on? I think the converter getAsObject is called before any of those values are changed in the UIInput updateModel phase. Andrew Robinson-5 wrote: Perhaps you could leverage custom converters with the ValueChangeEvent The process is, convert, validate, clear submitted value, queue event. The event will be fired at the end of the phase, before the update phase. At that time, you can clear the local value, and re-set the submitted value. That component will not update the model, since there would be no local value, and then if the submitted value is reset, then it would re-render the invalid value as desired. public class SubmittedValueBean implements Converter { private final static String ORIG_SUBMITTED_KEY = original-submitted-value; public Object getAsObject(FacesContext context, UIComponent component, String value) { UIInput input = (UIInput)component; input.getAttributes().remove(ORIG_SUBMITTED_KEY); boolean valid = true; Object val = value.toString(); // attempt to convert the value here. You could use // f:attribute to store information on how to convert the data or something like that if (!valid) { input.getAttributes().put(ORIG_SUBMITTED_KEY, value); return null; } else { return val; } } public void onValueChange(ValueChangeEvent evt) { UIInput input = (UIInput)evt.getComponent(); String origSubmitted = (String)input.getAttributes().get( ORIG_SUBMITTED_KEY); if (origSubmitted != null) { input.setSubmittedValue(origSubmitted); input.setValue(null); input.setLocalValueSet(false); } } On 7/9/07, Toppac [EMAIL PROTECTED] wrote: The only problem with this approach is I already have a domain model that i have written a custom resolver for, so I can bind directly to it. Going this approach I would have to copy the value from the backing bean to my domain model. I don't want to have to maintain a copy like that. Scott O'Bryan wrote: :) That was going to be my suggestion. Andrew Robinson wrote: Another solution you could consider, is doing the conversion/validation in the backing bean instead of in the component, it is messy, but possibly less messy than what I told you. It is more work though. public class Bean { private Integer intValue; private String submittedIntValue; // standard get/set properties here for intValue public String getSubmittedValue() { if (submittedIntValue == null) { return intValue.toString(); } return submittedIntValue(); } public void setSubmittedValue(String value) { try { submittedIntValue = value; if (value == null || value.length() == 0) { intValue = null; } intValue = Integer.parseInt(value); submittedIntValue = null; } catch (NumberFormatException ex) { } } ... h:inputText value=#{bean.submittedIntValue} / Since the backing bean takes any string, you will never get conversion or validation errors and update model will always take place. Then since the inputText is valid, there is no submitted value and no local value, and thus it would get the value from the value binding. Thus it is the bean that is doing the work of the conversion and validation. -Andrew On 7/6/07, Toppac [EMAIL PROTECTED] wrote: Unfortunately I was afraid this may be the answer. I knew from looking at the code that it may require heavy modfications and a departure from the JSF spec. Hopefully I can get the requirements changed. Thanks. Andrew Robinson-5 wrote: The problem is really that you are going against the UIInput part of the JSF specification. By definition, during the processValidators method, if a UIInput component is found to be invalid, then renderResponse is called on the current facescontext. Since you want control of the component's submitted value, perhaps your best bet is component binding or a phase listener, or you could even queue custom events. I can't see an easy way for you do this without a significant hack though. Especially, trying to reset submitted values will get especially ugly for components in iterating parents (data table, data list, tree2, etc.). The easiest hack I would say is to create a phase listener that listens for the before and after validation phase. In that phase listener, replace the faces context. Crude example: public void beforePhase(PhaseEvent evt) { new CustomFacesContext(evt.getFacesContext()); } public void afterPhase(PhaseEvent evt) { ((CustomFacesContext)evt.getFacesContext()).unwrap(); } private class CustomFacesContext extends FacesContextWrapper { private FacesContext wrapped; public CustomFacesContext(FacesContext orig) { super(orig); wrapped = orig
Re: Converter.getAsString not called?
Interesting idea. I will have to give it a try. Andrew Robinson-5 wrote: Yes, it should jive, unless someone wrote a custom component extending UIInput that changes the behavior so that it doesn't agree with the specification. Process of validate: 1) check for submitted value, if none exit 2) get converter, and convert if found 3) check if valid, exit if not 4) validate the value 5) check if valid, exit if not 6) clear submitted value 7) set local value 8) check fire value change event Process of update: 1) check if valid, else return 2) check if local value is set, else return 3) set the value on the value binding 4) clear the local value, and set the localValueSet property to false So, if you can modify the component in between the validation and the update because that is when the valueChangeEvent fires. So in update #2, you will see if the local value is not set, nothing happens. Thus in my example, I remove the local value to prevent the update. Renderers for UIInput will use the submitted value if it is present, and in my example, it is On 7/10/07, Toppac [EMAIL PROTECTED] wrote: Interesting idea. But how will this jive with the code already implemented in UIInput that is clearing the submitted value, setting the local value and so on? I think the converter getAsObject is called before any of those values are changed in the UIInput updateModel phase. Andrew Robinson-5 wrote: Perhaps you could leverage custom converters with the ValueChangeEvent The process is, convert, validate, clear submitted value, queue event. The event will be fired at the end of the phase, before the update phase. At that time, you can clear the local value, and re-set the submitted value. That component will not update the model, since there would be no local value, and then if the submitted value is reset, then it would re-render the invalid value as desired. public class SubmittedValueBean implements Converter { private final static String ORIG_SUBMITTED_KEY = original-submitted-value; public Object getAsObject(FacesContext context, UIComponent component, String value) { UIInput input = (UIInput)component; input.getAttributes().remove(ORIG_SUBMITTED_KEY); boolean valid = true; Object val = value.toString(); // attempt to convert the value here. You could use // f:attribute to store information on how to convert the data or something like that if (!valid) { input.getAttributes().put(ORIG_SUBMITTED_KEY, value); return null; } else { return val; } } public void onValueChange(ValueChangeEvent evt) { UIInput input = (UIInput)evt.getComponent(); String origSubmitted = (String)input.getAttributes().get( ORIG_SUBMITTED_KEY); if (origSubmitted != null) { input.setSubmittedValue(origSubmitted); input.setValue(null); input.setLocalValueSet(false); } } On 7/9/07, Toppac [EMAIL PROTECTED] wrote: The only problem with this approach is I already have a domain model that i have written a custom resolver for, so I can bind directly to it. Going this approach I would have to copy the value from the backing bean to my domain model. I don't want to have to maintain a copy like that. Scott O'Bryan wrote: :) That was going to be my suggestion. Andrew Robinson wrote: Another solution you could consider, is doing the conversion/validation in the backing bean instead of in the component, it is messy, but possibly less messy than what I told you. It is more work though. public class Bean { private Integer intValue; private String submittedIntValue; // standard get/set properties here for intValue public String getSubmittedValue() { if (submittedIntValue == null) { return intValue.toString(); } return submittedIntValue(); } public void setSubmittedValue(String value) { try { submittedIntValue = value; if (value == null || value.length() == 0) { intValue = null; } intValue = Integer.parseInt(value); submittedIntValue = null; } catch (NumberFormatException ex) { } } ... h:inputText value=#{bean.submittedIntValue} / Since the backing bean takes any string, you will never get conversion or validation errors and update model will always take place. Then since the inputText is valid, there is no submitted value and no local value, and thus it would get the value from the value binding. Thus it is the bean that is doing the work of the conversion and validation. -Andrew On 7/6/07, Toppac [EMAIL PROTECTED] wrote: Unfortunately I was afraid this may be the answer. I knew from looking at the code that it may require heavy modfications and a departure from the JSF spec. Hopefully I can get the requirements changed. Thanks. Andrew Robinson-5 wrote: The problem
Re: Converter.getAsString not called?
Small problem with this approach. If a component begins with value of Null and my custom converter returns a value of null for invalid values, the value change never fires. Andrew Robinson-5 wrote: Yes, it should jive, unless someone wrote a custom component extending UIInput that changes the behavior so that it doesn't agree with the specification. Process of validate: 1) check for submitted value, if none exit 2) get converter, and convert if found 3) check if valid, exit if not 4) validate the value 5) check if valid, exit if not 6) clear submitted value 7) set local value 8) check fire value change event Process of update: 1) check if valid, else return 2) check if local value is set, else return 3) set the value on the value binding 4) clear the local value, and set the localValueSet property to false So, if you can modify the component in between the validation and the update because that is when the valueChangeEvent fires. So in update #2, you will see if the local value is not set, nothing happens. Thus in my example, I remove the local value to prevent the update. Renderers for UIInput will use the submitted value if it is present, and in my example, it is On 7/10/07, Toppac [EMAIL PROTECTED] wrote: Interesting idea. But how will this jive with the code already implemented in UIInput that is clearing the submitted value, setting the local value and so on? I think the converter getAsObject is called before any of those values are changed in the UIInput updateModel phase. Andrew Robinson-5 wrote: Perhaps you could leverage custom converters with the ValueChangeEvent The process is, convert, validate, clear submitted value, queue event. The event will be fired at the end of the phase, before the update phase. At that time, you can clear the local value, and re-set the submitted value. That component will not update the model, since there would be no local value, and then if the submitted value is reset, then it would re-render the invalid value as desired. public class SubmittedValueBean implements Converter { private final static String ORIG_SUBMITTED_KEY = original-submitted-value; public Object getAsObject(FacesContext context, UIComponent component, String value) { UIInput input = (UIInput)component; input.getAttributes().remove(ORIG_SUBMITTED_KEY); boolean valid = true; Object val = value.toString(); // attempt to convert the value here. You could use // f:attribute to store information on how to convert the data or something like that if (!valid) { input.getAttributes().put(ORIG_SUBMITTED_KEY, value); return null; } else { return val; } } public void onValueChange(ValueChangeEvent evt) { UIInput input = (UIInput)evt.getComponent(); String origSubmitted = (String)input.getAttributes().get( ORIG_SUBMITTED_KEY); if (origSubmitted != null) { input.setSubmittedValue(origSubmitted); input.setValue(null); input.setLocalValueSet(false); } } On 7/9/07, Toppac [EMAIL PROTECTED] wrote: The only problem with this approach is I already have a domain model that i have written a custom resolver for, so I can bind directly to it. Going this approach I would have to copy the value from the backing bean to my domain model. I don't want to have to maintain a copy like that. Scott O'Bryan wrote: :) That was going to be my suggestion. Andrew Robinson wrote: Another solution you could consider, is doing the conversion/validation in the backing bean instead of in the component, it is messy, but possibly less messy than what I told you. It is more work though. public class Bean { private Integer intValue; private String submittedIntValue; // standard get/set properties here for intValue public String getSubmittedValue() { if (submittedIntValue == null) { return intValue.toString(); } return submittedIntValue(); } public void setSubmittedValue(String value) { try { submittedIntValue = value; if (value == null || value.length() == 0) { intValue = null; } intValue = Integer.parseInt(value); submittedIntValue = null; } catch (NumberFormatException ex) { } } ... h:inputText value=#{bean.submittedIntValue} / Since the backing bean takes any string, you will never get conversion or validation errors and update model will always take place. Then since the inputText is valid, there is no submitted value and no local value, and thus it would get the value from the value binding. Thus it is the bean that is doing the work of the conversion and validation. -Andrew On 7/6/07, Toppac [EMAIL PROTECTED] wrote: Unfortunately I was afraid this may be the answer. I knew from looking at the code that it may require heavy modfications and a departure from the JSF
Re: Converter.getAsString not called?
The only problem with this approach is I already have a domain model that i have written a custom resolver for, so I can bind directly to it. Going this approach I would have to copy the value from the backing bean to my domain model. I don't want to have to maintain a copy like that. Scott O'Bryan wrote: :) That was going to be my suggestion. Andrew Robinson wrote: Another solution you could consider, is doing the conversion/validation in the backing bean instead of in the component, it is messy, but possibly less messy than what I told you. It is more work though. public class Bean { private Integer intValue; private String submittedIntValue; // standard get/set properties here for intValue public String getSubmittedValue() { if (submittedIntValue == null) { return intValue.toString(); } return submittedIntValue(); } public void setSubmittedValue(String value) { try { submittedIntValue = value; if (value == null || value.length() == 0) { intValue = null; } intValue = Integer.parseInt(value); submittedIntValue = null; } catch (NumberFormatException ex) { } } ... h:inputText value=#{bean.submittedIntValue} / Since the backing bean takes any string, you will never get conversion or validation errors and update model will always take place. Then since the inputText is valid, there is no submitted value and no local value, and thus it would get the value from the value binding. Thus it is the bean that is doing the work of the conversion and validation. -Andrew On 7/6/07, Toppac [EMAIL PROTECTED] wrote: Unfortunately I was afraid this may be the answer. I knew from looking at the code that it may require heavy modfications and a departure from the JSF spec. Hopefully I can get the requirements changed. Thanks. Andrew Robinson-5 wrote: The problem is really that you are going against the UIInput part of the JSF specification. By definition, during the processValidators method, if a UIInput component is found to be invalid, then renderResponse is called on the current facescontext. Since you want control of the component's submitted value, perhaps your best bet is component binding or a phase listener, or you could even queue custom events. I can't see an easy way for you do this without a significant hack though. Especially, trying to reset submitted values will get especially ugly for components in iterating parents (data table, data list, tree2, etc.). The easiest hack I would say is to create a phase listener that listens for the before and after validation phase. In that phase listener, replace the faces context. Crude example: public void beforePhase(PhaseEvent evt) { new CustomFacesContext(evt.getFacesContext()); } public void afterPhase(PhaseEvent evt) { ((CustomFacesContext)evt.getFacesContext()).unwrap(); } private class CustomFacesContext extends FacesContextWrapper { private FacesContext wrapped; public CustomFacesContext(FacesContext orig) { super(orig); wrapped = orig; FacesContext.setCurrentInstance(this); } public void renderResponse() { /* swallow */ } public void unwrap() { wrapped.setFacesContext(wrapped); } } Now despite invalid UIInput components, the phases will continue. I haven't thought through all the ramifications though. You may get some ugly side-effects from doing this. -Andrew On 7/6/07, Toppac [EMAIL PROTECTED] wrote: I am using a custom converter to return null so I can bypass these conversion errors during submission. What I want to happen is that even when I bypass these and have my converter return null, I want to have a way to inject the submitted value back in during renderResponse. This does not appear to work with MyFaces out of the box. There is not hook to the converter for some reason and the local value of the component is null. That is the problem I am trying to solve. Andrew Robinson-5 wrote: Just about all components check their member values before they check the value bindings. UIOutput is no different. So if either the submittedValue or local value is set, your ValueBinding expression will not be called. The local value should be converted before being rendered however. If you don't want to throw a conversion error when the user enters abc, then write a custom converter that doesn't throw an error. You could turn abc in to null or 0, based on your requirements for example. If you use custom validators and custom converters, you can make it so that exceptions are never thrown from converting and validation. Out of curiosity, why do you want to update the model when there is invalid data? If you are only wanting to submit one value and don't care if other values are invalid, then I would suggest using the subForm component from the sandbox or the a4j:region if you
Converter.getAsString not called?
Just for a small background. I am trying to find a way to fail validation and/or conversion without dumping out of the JSF lifecycle to render response. I'd like to inject a custom converter that when it fails to convert it saves the submitted value to a session scoped Map and then during render response, when it tries to render the component that failed conversion, the getAsString method would see that the incoming value is null and would go to the session map to grab the last submitted value. Sounds easy enough and should work. But when I tried it, it appears that during render response, if the value on the domain model is null (or if the component value is null, not sure) it does not call the converter.getAsString method. I am not sure why. If someone can tell me why and where it makes this decision that would be great. If this is a bug then great also. But if it is not a bug then can anyone suggest a way to do what I am trying to do? -- View this message in context: http://www.nabble.com/Converter.getAsString-not-called--tf4038047.html#a11472287 Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: Converter.getAsString not called?
I don't think I follow what you are saying exactly. Can you elaborate? Andrew Robinson-5 wrote: Converter will only be called if there is no submitted value. Submitted values are already technically converted as they came from the client, so there is no need to use the converter. On 7/6/07, Toppac [EMAIL PROTECTED] wrote: Just for a small background. I am trying to find a way to fail validation and/or conversion without dumping out of the JSF lifecycle to render response. I'd like to inject a custom converter that when it fails to convert it saves the submitted value to a session scoped Map and then during render response, when it tries to render the component that failed conversion, the getAsString method would see that the incoming value is null and would go to the session map to grab the last submitted value. Sounds easy enough and should work. But when I tried it, it appears that during render response, if the value on the domain model is null (or if the component value is null, not sure) it does not call the converter.getAsString method. I am not sure why. If someone can tell me why and where it makes this decision that would be great. If this is a bug then great also. But if it is not a bug then can anyone suggest a way to do what I am trying to do? -- View this message in context: http://www.nabble.com/Converter.getAsString-not-called--tf4038047.html#a11472287 Sent from the MyFaces - Users mailing list archive at Nabble.com. -- View this message in context: http://www.nabble.com/Converter.getAsString-not-called--tf4038047.html#a11472464 Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: Converter.getAsString not called?
Ok I follow. There a couple of problems here though. let's say my converter is for java.lang.Integer and the submitted value from the POST is abc. I can't use the default converter since it will throw an exception and try to skip directly to renderResponse, not what i want to happen. Right now my converter is just returning null at this point and caches the submitted value. The rest of the lifecycle goes through and during update model the submitted value is set to null since updateModel succeeds. During renderResponse it appears that it tries to get the value from the component first, and if the component does not have a value it tries to get it from evaluating the value binding (see UiOutput.getValue). In this case they are both null, which is expected. But it never tries to call my converter which would restore the cached submitted valued. Andrew Robinson-5 wrote: Typical UIInput behavior: Decode phase - Is there a value in the POST values with the current component's client ID? If so, set the submitted value to that Validate phase - If there is a submitted value, get the converter If there is a converter, convert the submitted value using getAsObject Validate the submitted value If valid, set the local value Update phase - If there is a local value, update the value binding property Render phase - If there is a submitted value, render that Otherwise, get the value from the component If there is a converter, convert the value using getAsString Render the value So as you can see, as long as a UIInput control has a submitted value, it will never render the value from the value attribute of the component. Typically submitted values are only cleared in the validate method of UIInput (if the converted value is valid) On 7/6/07, Toppac [EMAIL PROTECTED] wrote: I don't think I follow what you are saying exactly. Can you elaborate? Andrew Robinson-5 wrote: Converter will only be called if there is no submitted value. Submitted values are already technically converted as they came from the client, so there is no need to use the converter. On 7/6/07, Toppac [EMAIL PROTECTED] wrote: Just for a small background. I am trying to find a way to fail validation and/or conversion without dumping out of the JSF lifecycle to render response. I'd like to inject a custom converter that when it fails to convert it saves the submitted value to a session scoped Map and then during render response, when it tries to render the component that failed conversion, the getAsString method would see that the incoming value is null and would go to the session map to grab the last submitted value. Sounds easy enough and should work. But when I tried it, it appears that during render response, if the value on the domain model is null (or if the component value is null, not sure) it does not call the converter.getAsString method. I am not sure why. If someone can tell me why and where it makes this decision that would be great. If this is a bug then great also. But if it is not a bug then can anyone suggest a way to do what I am trying to do? -- View this message in context: http://www.nabble.com/Converter.getAsString-not-called--tf4038047.html#a11472287 Sent from the MyFaces - Users mailing list archive at Nabble.com. -- View this message in context: http://www.nabble.com/Converter.getAsString-not-called--tf4038047.html#a11472464 Sent from the MyFaces - Users mailing list archive at Nabble.com. -- View this message in context: http://www.nabble.com/Converter.getAsString-not-called--tf4038047.html#a11472718 Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: Converter.getAsString not called?
I am using a custom converter to return null so I can bypass these conversion errors during submission. What I want to happen is that even when I bypass these and have my converter return null, I want to have a way to inject the submitted value back in during renderResponse. This does not appear to work with MyFaces out of the box. There is not hook to the converter for some reason and the local value of the component is null. That is the problem I am trying to solve. Andrew Robinson-5 wrote: Just about all components check their member values before they check the value bindings. UIOutput is no different. So if either the submittedValue or local value is set, your ValueBinding expression will not be called. The local value should be converted before being rendered however. If you don't want to throw a conversion error when the user enters abc, then write a custom converter that doesn't throw an error. You could turn abc in to null or 0, based on your requirements for example. If you use custom validators and custom converters, you can make it so that exceptions are never thrown from converting and validation. Out of curiosity, why do you want to update the model when there is invalid data? If you are only wanting to submit one value and don't care if other values are invalid, then I would suggest using the subForm component from the sandbox or the a4j:region if you are using ajax4jsf. -Andrew On 7/6/07, Toppac [EMAIL PROTECTED] wrote: Ok I follow. There a couple of problems here though. let's say my converter is for java.lang.Integer and the submitted value from the POST is abc. I can't use the default converter since it will throw an exception and try to skip directly to renderResponse, not what i want to happen. Right now my converter is just returning null at this point and caches the submitted value. The rest of the lifecycle goes through and during update model the submitted value is set to null since updateModel succeeds. During renderResponse it appears that it tries to get the value from the component first, and if the component does not have a value it tries to get it from evaluating the value binding (see UiOutput.getValue). In this case they are both null, which is expected. But it never tries to call my converter which would restore the cached submitted valued. Andrew Robinson-5 wrote: Typical UIInput behavior: Decode phase - Is there a value in the POST values with the current component's client ID? If so, set the submitted value to that Validate phase - If there is a submitted value, get the converter If there is a converter, convert the submitted value using getAsObject Validate the submitted value If valid, set the local value Update phase - If there is a local value, update the value binding property Render phase - If there is a submitted value, render that Otherwise, get the value from the component If there is a converter, convert the value using getAsString Render the value So as you can see, as long as a UIInput control has a submitted value, it will never render the value from the value attribute of the component. Typically submitted values are only cleared in the validate method of UIInput (if the converted value is valid) On 7/6/07, Toppac [EMAIL PROTECTED] wrote: I don't think I follow what you are saying exactly. Can you elaborate? Andrew Robinson-5 wrote: Converter will only be called if there is no submitted value. Submitted values are already technically converted as they came from the client, so there is no need to use the converter. On 7/6/07, Toppac [EMAIL PROTECTED] wrote: Just for a small background. I am trying to find a way to fail validation and/or conversion without dumping out of the JSF lifecycle to render response. I'd like to inject a custom converter that when it fails to convert it saves the submitted value to a session scoped Map and then during render response, when it tries to render the component that failed conversion, the getAsString method would see that the incoming value is null and would go to the session map to grab the last submitted value. Sounds easy enough and should work. But when I tried it, it appears that during render response, if the value on the domain model is null (or if the component value is null, not sure) it does not call the converter.getAsString method. I am not sure why. If someone can tell me why and where it makes this decision that would be great. If this is a bug then great also. But if it is not a bug then can anyone suggest a way to do what I am trying to do? -- View this message in context: http://www.nabble.com/Converter.getAsString-not-called--tf4038047.html#a11472287 Sent from the MyFaces - Users mailing list archive at Nabble.com. -- View this message
Re: Converter.getAsString not called?
Unfortunately I was afraid this may be the answer. I knew from looking at the code that it may require heavy modfications and a departure from the JSF spec. Hopefully I can get the requirements changed. Thanks. Andrew Robinson-5 wrote: The problem is really that you are going against the UIInput part of the JSF specification. By definition, during the processValidators method, if a UIInput component is found to be invalid, then renderResponse is called on the current facescontext. Since you want control of the component's submitted value, perhaps your best bet is component binding or a phase listener, or you could even queue custom events. I can't see an easy way for you do this without a significant hack though. Especially, trying to reset submitted values will get especially ugly for components in iterating parents (data table, data list, tree2, etc.). The easiest hack I would say is to create a phase listener that listens for the before and after validation phase. In that phase listener, replace the faces context. Crude example: public void beforePhase(PhaseEvent evt) { new CustomFacesContext(evt.getFacesContext()); } public void afterPhase(PhaseEvent evt) { ((CustomFacesContext)evt.getFacesContext()).unwrap(); } private class CustomFacesContext extends FacesContextWrapper { private FacesContext wrapped; public CustomFacesContext(FacesContext orig) { super(orig); wrapped = orig; FacesContext.setCurrentInstance(this); } public void renderResponse() { /* swallow */ } public void unwrap() { wrapped.setFacesContext(wrapped); } } Now despite invalid UIInput components, the phases will continue. I haven't thought through all the ramifications though. You may get some ugly side-effects from doing this. -Andrew On 7/6/07, Toppac [EMAIL PROTECTED] wrote: I am using a custom converter to return null so I can bypass these conversion errors during submission. What I want to happen is that even when I bypass these and have my converter return null, I want to have a way to inject the submitted value back in during renderResponse. This does not appear to work with MyFaces out of the box. There is not hook to the converter for some reason and the local value of the component is null. That is the problem I am trying to solve. Andrew Robinson-5 wrote: Just about all components check their member values before they check the value bindings. UIOutput is no different. So if either the submittedValue or local value is set, your ValueBinding expression will not be called. The local value should be converted before being rendered however. If you don't want to throw a conversion error when the user enters abc, then write a custom converter that doesn't throw an error. You could turn abc in to null or 0, based on your requirements for example. If you use custom validators and custom converters, you can make it so that exceptions are never thrown from converting and validation. Out of curiosity, why do you want to update the model when there is invalid data? If you are only wanting to submit one value and don't care if other values are invalid, then I would suggest using the subForm component from the sandbox or the a4j:region if you are using ajax4jsf. -Andrew On 7/6/07, Toppac [EMAIL PROTECTED] wrote: Ok I follow. There a couple of problems here though. let's say my converter is for java.lang.Integer and the submitted value from the POST is abc. I can't use the default converter since it will throw an exception and try to skip directly to renderResponse, not what i want to happen. Right now my converter is just returning null at this point and caches the submitted value. The rest of the lifecycle goes through and during update model the submitted value is set to null since updateModel succeeds. During renderResponse it appears that it tries to get the value from the component first, and if the component does not have a value it tries to get it from evaluating the value binding (see UiOutput.getValue). In this case they are both null, which is expected. But it never tries to call my converter which would restore the cached submitted valued. Andrew Robinson-5 wrote: Typical UIInput behavior: Decode phase - Is there a value in the POST values with the current component's client ID? If so, set the submitted value to that Validate phase - If there is a submitted value, get the converter If there is a converter, convert the submitted value using getAsObject Validate the submitted value If valid, set the local value Update phase - If there is a local value, update the value binding property Render phase - If there is a submitted value, render that Otherwise, get the value from the component If there is a converter, convert the value using getAsString Render
RE: Disabled with value binding expression
I wanted to add onto this to see if anyone could provide further insight. I am using a custom variable resolver to access some session scoped variables. I know the value is there because I can print it out. However, whenever I try to reference the value in the disabled attribute of an input element, the value is ignored. The value in the session scope is a Boolean (object). I noticed that the attribute takes a boolean (primitive) on the getter and setter methods. I am wondering if for some reason my Boolean is not being translated correctly. When I just put the string true it works fine. But using something like disabled=#{flowScope.delete} does not work, where deleted is a Boolean. Printing out flowScope.delete using regular EL or an outputText tag works fine. I am using MyFaces 1.1.4, latest Facelets, Webflow 1.0. If anyone has any ideas I would love to hear them. Thanks. Toppac wrote: Thanks for the replies guys. I am using spring webflow also and had the value scoped to a flowScope variable. I am being told that won't work so it looks like I'll need to translate my flowscoped variable to a request scoped one for the disabled attribute to pick up. Tom Innes wrote: See http://wiki.java.net/bin/view/Projects/FaceletsFAQ c:set, c:if are build time tags I use Facelets as well and the following works for me h:inputText disabled=#{mybackingBean.disabled} / and my backing bean method is defined as public boolean getDisabled() { return this.disabled; } Tom -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Craig McClanahan Sent: Tuesday, October 31, 2006 2:45 PM To: MyFaces Discussion Subject: Re: Disabled with value binding expression On 10/31/06, Toppac [EMAIL PROTECTED] wrote: I am using Facelets with MyFaces, which allows jstl page scoped variables to work. Correct me if I am wrong. Sounds like a question for the Facelets list ... but I sure wonder how Facelets makes this happen during the Apply Request Values through Invoke Application phases of the request processing lifecycle, when there is no page scope because there is no page. Also another thing I tried is writing a customer taglib function that will parse my backing bean value and return the string true or false, depending on whether the calling field should be disabled. This seems to work pretty well the first time through, but on subsequent visits to the same page, I don't see the function being called again. It is only called the first time the page is rendered. Shouldn't the function be evaluated every time the page is rendered? Do you know for a fact that logonBean actually exists on the subsequent renderings? If it does not (as someone else in this thread pointed out), your expression will evaluate to false with no errors or exceptions. Craig Craig McClanahan-3 wrote: On 10/31/06, Toppac [EMAIL PROTECTED] wrote: Also I am using c:set var=disabled value=false scope=page/ This is not going to work. JSF expressions do not have access to page scope in a JSP page. You'll need to us something in request scope instead. Craig I typed the wrong thing from memory earlier Toppac wrote: I print out the value to the screen to make sure it is not empty. It evaluates to true when I would expect it to and to false at other times. But even when it is true it does not affect the inputText boxes. I also use jstl tags throughout the page, so I am pretty sure the c taglib is defined. Dennis Byrne wrote: I am trying to use the disabled attribute on some inputText boxes in my application. However, everytime I try to use a binding like this h:inputText disabled=#{mybackingBean.disabled} / In both JSP and JSF, #{backingBeanThatDoesNotExist.propertyThatDoesNotExist} will not throw an exception; it will default to 'false'. Whenever I find myself in your situation I double check expression path. nothing happens. disabled is a Boolean field in the backing bean. I assume it would auto translate to a string, but it doesnt appear to. I then tried using JSTl to set a value a page scoped variable c:set name=disabled value=true/ This does not work either when I change my input box to this h:inputText disabled=#{disabled}/ Perhaps you have not included the c taglib header in the JSP file? The page will silently skip the c:set tag in this case. Dennis Byrne -- View this message in context: http://www.nabble.com/Disabled-with-value-binding-expression-tf2546998.html# a7098480 Sent from the MyFaces - Users mailing list archive at Nabble.com. -- View this message in context: http://www.nabble.com/Disabled-with-value-binding-expression-tf2546998.html# a7100471 Sent from the MyFaces - Users mailing list archive at Nabble.com
RE: Disabled with value binding expression
Doesn't that break the java bean conventions? Nebinger, David wrote: Have you tried using disabled=#{flowScope.delete.booleanValue}? -Original Message- From: Toppac [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 28, 2006 4:45 PM To: users@myfaces.apache.org Subject: RE: Disabled with value binding expression I wanted to add onto this to see if anyone could provide further insight. I am using a custom variable resolver to access some session scoped variables. I know the value is there because I can print it out. However, whenever I try to reference the value in the disabled attribute of an input element, the value is ignored. The value in the session scope is a Boolean (object). I noticed that the attribute takes a boolean (primitive) on the getter and setter methods. I am wondering if for some reason my Boolean is not being translated correctly. When I just put the string true it works fine. But using something like disabled=#{flowScope.delete} does not work, where deleted is a Boolean. Printing out flowScope.delete using regular EL or an outputText tag works fine. I am using MyFaces 1.1.4, latest Facelets, Webflow 1.0. If anyone has any ideas I would love to hear them. Thanks. Toppac wrote: Thanks for the replies guys. I am using spring webflow also and had the value scoped to a flowScope variable. I am being told that won't work so it looks like I'll need to translate my flowscoped variable to a request scoped one for the disabled attribute to pick up. Tom Innes wrote: See http://wiki.java.net/bin/view/Projects/FaceletsFAQ c:set, c:if are build time tags I use Facelets as well and the following works for me h:inputText disabled=#{mybackingBean.disabled} / and my backing bean method is defined as public boolean getDisabled() { return this.disabled; } Tom -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Craig McClanahan Sent: Tuesday, October 31, 2006 2:45 PM To: MyFaces Discussion Subject: Re: Disabled with value binding expression On 10/31/06, Toppac [EMAIL PROTECTED] wrote: I am using Facelets with MyFaces, which allows jstl page scoped variables to work. Correct me if I am wrong. Sounds like a question for the Facelets list ... but I sure wonder how Facelets makes this happen during the Apply Request Values through Invoke Application phases of the request processing lifecycle, when there is no page scope because there is no page. Also another thing I tried is writing a customer taglib function that will parse my backing bean value and return the string true or false, depending on whether the calling field should be disabled. This seems to work pretty well the first time through, but on subsequent visits to the same page, I don't see the function being called again. It is only called the first time the page is rendered. Shouldn't the function be evaluated every time the page is rendered? Do you know for a fact that logonBean actually exists on the subsequent renderings? If it does not (as someone else in this thread pointed out), your expression will evaluate to false with no errors or exceptions. Craig Craig McClanahan-3 wrote: On 10/31/06, Toppac [EMAIL PROTECTED] wrote: Also I am using c:set var=disabled value=false scope=page/ This is not going to work. JSF expressions do not have access to page scope in a JSP page. You'll need to us something in request scope instead. Craig I typed the wrong thing from memory earlier Toppac wrote: I print out the value to the screen to make sure it is not empty. It evaluates to true when I would expect it to and to false at other times. But even when it is true it does not affect the inputText boxes. I also use jstl tags throughout the page, so I am pretty sure the c taglib is defined. Dennis Byrne wrote: I am trying to use the disabled attribute on some inputText boxes in my application. However, everytime I try to use a binding like this h:inputText disabled=#{mybackingBean.disabled} / In both JSP and JSF, #{backingBeanThatDoesNotExist.propertyThatDoesNotExist} will not throw an exception; it will default to 'false'. Whenever I find myself in your situation I double check expression path. nothing happens. disabled is a Boolean field in the backing bean. I assume it would auto translate to a string, but it doesnt appear to. I then tried using JSTl to set a value a page scoped variable c:set name=disabled value=true/ This does not work either when I change my input box
Reseting form styles every time the page renders
Is it possible to force JSF to read the default style from the xhtml every time a view is rendered? I muck with the styles of the view root components on the server side but once I change them, anytime the view is rendered it keeps those style changes unless I change them on the server side again. I'd like it if I could reset the style everytime, so that it starts with a default and then I can modify it based on data on the server side. -- View this message in context: http://www.nabble.com/Reseting-form-styles-every-time-the-page-renders-tf2603173.html#a7262983 Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: Anyone using MyFaces with DWR?
From the dwr website servlet servlet-namedwr-invoker/servlet-name servlet-classuk.ltd.getahead.dwr.DWRServlet/servlet-class /servlet servlet-mapping servlet-namedwr-invoker/servlet-name url-pattern/dwr/*/url-pattern /servlet-mapping Works fine for me with facelets, myfaces and dwr. Mick Knutson-4 wrote: Can I get an example of your web.xml to validate I have the right implementation for dwr 2.x -- Thanks DJ MICK http://www.djmick.com http://www.myspace.com/mickknutson -- View this message in context: http://www.nabble.com/Anyone-using-MyFaces-with-DWR--tf2549437.html#a7116746 Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: Disabled with value binding expression
Also I am using c:set var=disabled value=false scope=page/ I typed the wrong thing from memory earlier Toppac wrote: I print out the value to the screen to make sure it is not empty. It evaluates to true when I would expect it to and to false at other times. But even when it is true it does not affect the inputText boxes. I also use jstl tags throughout the page, so I am pretty sure the c taglib is defined. Dennis Byrne wrote: I am trying to use the disabled attribute on some inputText boxes in my application. However, everytime I try to use a binding like this h:inputText disabled=#{mybackingBean.disabled} / In both JSP and JSF, #{backingBeanThatDoesNotExist.propertyThatDoesNotExist} will not throw an exception; it will default to 'false'. Whenever I find myself in your situation I double check expression path. nothing happens. disabled is a Boolean field in the backing bean. I assume it would auto translate to a string, but it doesnt appear to. I then tried using JSTl to set a value a page scoped variable c:set name=disabled value=true/ This does not work either when I change my input box to this h:inputText disabled=#{disabled}/ Perhaps you have not included the c taglib header in the JSP file? The page will silently skip the c:set tag in this case. Dennis Byrne -- View this message in context: http://www.nabble.com/Disabled-with-value-binding-expression-tf2546998.html#a7098480 Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: Disabled with value binding expression
I print out the value to the screen to make sure it is not empty. It evaluates to true when I would expect it to and to false at other times. But even when it is true it does not affect the inputText boxes. I also use jstl tags throughout the page, so I am pretty sure the c taglib is defined. Dennis Byrne wrote: I am trying to use the disabled attribute on some inputText boxes in my application. However, everytime I try to use a binding like this h:inputText disabled=#{mybackingBean.disabled} / In both JSP and JSF, #{backingBeanThatDoesNotExist.propertyThatDoesNotExist} will not throw an exception; it will default to 'false'. Whenever I find myself in your situation I double check expression path. nothing happens. disabled is a Boolean field in the backing bean. I assume it would auto translate to a string, but it doesnt appear to. I then tried using JSTl to set a value a page scoped variable c:set name=disabled value=true/ This does not work either when I change my input box to this h:inputText disabled=#{disabled}/ Perhaps you have not included the c taglib header in the JSP file? The page will silently skip the c:set tag in this case. Dennis Byrne -- View this message in context: http://www.nabble.com/Disabled-with-value-binding-expression-tf2546998.html#a7098448 Sent from the MyFaces - Users mailing list archive at Nabble.com.
Disabled with value binding expression
I am trying to use the disabled attribute on some inputText boxes in my application. However, everytime I try to use a binding like this h:inputText disabled=#{mybackingBean.disabled} / nothing happens. disabled is a Boolean field in the backing bean. I assume it would auto translate to a string, but it doesnt appear to. I then tried using JSTl to set a value a page scoped variable c:set name=disabled value=true/ This does not work either when I change my input box to this h:inputText disabled=#{disabled}/ The one way I can get it to work is if I use the explicit value disabled=true inline with the tag. Am I missing something simple here? -- View this message in context: http://www.nabble.com/Disabled-with-value-binding-expression-tf2546998.html#a7097990 Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: Disabled with value binding expression
I am using Facelets with MyFaces, which allows jstl page scoped variables to work. Correct me if I am wrong. Also another thing I tried is writing a customer taglib function that will parse my backing bean value and return the string true or false, depending on whether the calling field should be disabled. This seems to work pretty well the first time through, but on subsequent visits to the same page, I don't see the function being called again. It is only called the first time the page is rendered. Shouldn't the function be evaluated every time the page is rendered? Craig McClanahan-3 wrote: On 10/31/06, Toppac [EMAIL PROTECTED] wrote: Also I am using c:set var=disabled value=false scope=page/ This is not going to work. JSF expressions do not have access to page scope in a JSP page. You'll need to us something in request scope instead. Craig I typed the wrong thing from memory earlier Toppac wrote: I print out the value to the screen to make sure it is not empty. It evaluates to true when I would expect it to and to false at other times. But even when it is true it does not affect the inputText boxes. I also use jstl tags throughout the page, so I am pretty sure the c taglib is defined. Dennis Byrne wrote: I am trying to use the disabled attribute on some inputText boxes in my application. However, everytime I try to use a binding like this h:inputText disabled=#{mybackingBean.disabled} / In both JSP and JSF, #{backingBeanThatDoesNotExist.propertyThatDoesNotExist} will not throw an exception; it will default to 'false'. Whenever I find myself in your situation I double check expression path. nothing happens. disabled is a Boolean field in the backing bean. I assume it would auto translate to a string, but it doesnt appear to. I then tried using JSTl to set a value a page scoped variable c:set name=disabled value=true/ This does not work either when I change my input box to this h:inputText disabled=#{disabled}/ Perhaps you have not included the c taglib header in the JSP file? The page will silently skip the c:set tag in this case. Dennis Byrne -- View this message in context: http://www.nabble.com/Disabled-with-value-binding-expression-tf2546998.html#a7098480 Sent from the MyFaces - Users mailing list archive at Nabble.com. -- View this message in context: http://www.nabble.com/Disabled-with-value-binding-expression-tf2546998.html#a7100471 Sent from the MyFaces - Users mailing list archive at Nabble.com.
RE: Disabled with value binding expression
Thanks for the replies guys. I am using spring webflow also and had the value scoped to a flowScope variable. I am being told that won't work so it looks like I'll need to translate my flowscoped variable to a request scoped one for the disabled attribute to pick up. Tom Innes wrote: See http://wiki.java.net/bin/view/Projects/FaceletsFAQ c:set, c:if are build time tags I use Facelets as well and the following works for me h:inputText disabled=#{mybackingBean.disabled} / and my backing bean method is defined as public boolean getDisabled() { return this.disabled; } Tom -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Craig McClanahan Sent: Tuesday, October 31, 2006 2:45 PM To: MyFaces Discussion Subject: Re: Disabled with value binding expression On 10/31/06, Toppac [EMAIL PROTECTED] wrote: I am using Facelets with MyFaces, which allows jstl page scoped variables to work. Correct me if I am wrong. Sounds like a question for the Facelets list ... but I sure wonder how Facelets makes this happen during the Apply Request Values through Invoke Application phases of the request processing lifecycle, when there is no page scope because there is no page. Also another thing I tried is writing a customer taglib function that will parse my backing bean value and return the string true or false, depending on whether the calling field should be disabled. This seems to work pretty well the first time through, but on subsequent visits to the same page, I don't see the function being called again. It is only called the first time the page is rendered. Shouldn't the function be evaluated every time the page is rendered? Do you know for a fact that logonBean actually exists on the subsequent renderings? If it does not (as someone else in this thread pointed out), your expression will evaluate to false with no errors or exceptions. Craig Craig McClanahan-3 wrote: On 10/31/06, Toppac [EMAIL PROTECTED] wrote: Also I am using c:set var=disabled value=false scope=page/ This is not going to work. JSF expressions do not have access to page scope in a JSP page. You'll need to us something in request scope instead. Craig I typed the wrong thing from memory earlier Toppac wrote: I print out the value to the screen to make sure it is not empty. It evaluates to true when I would expect it to and to false at other times. But even when it is true it does not affect the inputText boxes. I also use jstl tags throughout the page, so I am pretty sure the c taglib is defined. Dennis Byrne wrote: I am trying to use the disabled attribute on some inputText boxes in my application. However, everytime I try to use a binding like this h:inputText disabled=#{mybackingBean.disabled} / In both JSP and JSF, #{backingBeanThatDoesNotExist.propertyThatDoesNotExist} will not throw an exception; it will default to 'false'. Whenever I find myself in your situation I double check expression path. nothing happens. disabled is a Boolean field in the backing bean. I assume it would auto translate to a string, but it doesnt appear to. I then tried using JSTl to set a value a page scoped variable c:set name=disabled value=true/ This does not work either when I change my input box to this h:inputText disabled=#{disabled}/ Perhaps you have not included the c taglib header in the JSP file? The page will silently skip the c:set tag in this case. Dennis Byrne -- View this message in context: http://www.nabble.com/Disabled-with-value-binding-expression-tf2546998.html# a7098480 Sent from the MyFaces - Users mailing list archive at Nabble.com. -- View this message in context: http://www.nabble.com/Disabled-with-value-binding-expression-tf2546998.html# a7100471 Sent from the MyFaces - Users mailing list archive at Nabble.com. -- View this message in context: http://www.nabble.com/Disabled-with-value-binding-expression-tf2546998.html#a7103090 Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: datatable with multiple images not interpretting rendered attribute
Thanks for the response but it definately does not work. For some reason when it is rendering the dataTable, whatever the first or last evaluation of the expression is, gets applied to every instance of the image within the datatable. It seems to cache the result of the EL expression for render and then use that for all the images at render time, rather than each image having its own value. I think this is a bug with myfaces Mike Kienenberger wrote: Of the code you posted, it looks ok to me. However, id=#{index + 'working'} is not legal. id must be a static value. On 9/12/06, Toppac [EMAIL PROTECTED] wrote: I am trying to use a datatable to render bunch of data and display an image next to each row rendered based on the rowIndex. My code is below. The problem I am seeing is that inside the graphicImage tag, the index doesn't have scope. I can print the index before and after the graphicImage, but when used inside the rendered attribute it always rendered to empty string. I tried to use the index as part of the id for the graphicImage, something like id=#{index + 'working'} and it always rendered to just working. I have tried just using rowIndex, tried naming the rowIndexVar something other than index, and no luck. I am wondering how I can use the current index inside other tags. I have also tried using JSTL tags c:if to do the rendering and it looks like the index doesn't have scope inside there either. The only other thing I can think may be wrong is that that the rendered attribute of the graphicImage is only calculated once or is calculated and applied to all the rows. The last c:if I have in my code below does work, so it seems to only be something with the rowIndexVar inside a dataTable. Last thing, ignore typos in variable names, as I changed the names of the variables to hide the real function of this code (requirement). And currentItemIndex is a c:set var defined earlier in the page. t:dataTable var=curItem rowIndexVar=index value=#{someData.someItems} border=0 cellpadding=0 cellspacing=0 t:column id=column1 f:facet name=header f:verbatimnbsp;/f:verbatim /f:facet #{index} and #{currentItemIndex} and #{(index - currentItemIndex) eq 0} h:graphicImage alt=Working rendered=#{(index - currentItemIndex) eq 0} value=snapc/images/icons/working.gif / h:graphicImage alt=Complete rendered=#{sf:isCompleteItem(curItem) and ((index - currentItemIndex) ne 0)} value=snapc/images/icons/complete.gif / h:graphicImage alt=Incomplete rendered=#{!sf:isCompleteItem(curItem) and ((index - currentItemIndex) ne 0)} value=snapc/images/icons/red_arrow.gif / /t:column t:column id=column2 f:facet name=header h:outputText value=Year / /f:facet #{curItem.currentlYear} /t:column t:column id=column3 f:facet name=header f:verbatimnbsp;/f:verbatim /f:facet c:if test=#{fn:length(someData.someItems) 1} h:commandLink action=edit type=submit id=edit #{bundle.usage_editdetails_label} f:param name=editIndex value=#{index}/ /h:commandLink nbsp;nbsp;|nbsp;nbsp; h:commandLink action=delete id=delete #{bundle.usage_delete_label} f:param name=deleteIndex value=#{index}/ /h:commandLink /c:if /t:column /t:dataTable -- View this message in context: http://www.nabble.com/datatable-with-multiple-images-not-interpretting-rendered-attribute-tf2261743.html#a6275415 Sent from the MyFaces - Users forum at Nabble.com. -- View this message in context: http://www.nabble.com/datatable-with-multiple-images-not-interpretting-rendered-attribute-tf2261743.html#a6293762 Sent from the MyFaces - Users forum at Nabble.com.
Re: datatable with multiple images not interpretting rendered attribute
Mike thanks for the reply. Yes I am using facelets and I have a custom function that is being called in the render section of the image tag. Here is a simplified example of what I am trying to do. c:set var=currentVehicleIndex value=#{sessionData.currentVehicle} scope=page/ t:dataTable var=curVehicle rowIndexVar=index rendered=#{!(empty policy.vehicles)} value=#{policy.vehicles} border=0 cellpadding=0 cellspacing=0 t:column id=column1 f:facet name=header f:verbatimnbsp;/f:verbatim /f:facet h:graphicImage alt=Working rendered=#{(index - currentVehicleIndex) eq 0} value=snapc/images/icons/working.gif / h:graphicImage alt=Complete rendered=#{sf:isCompleteVehicle(curVehicle) and ((index - currentVehicleIndex) ne 0)} value=snapc/images/icons/complete.gif / h:graphicImage alt=Incomplete rendered=#{!sf:isCompleteVehicle(curVehicle) and ((index - currentVehicleIndex) ne 0)} value=snapc/images/icons/red_arrow.gif / /t:column /t:dataTable What I expect to see is the correct image displayed based on the rendered EL statements. What I end up seeing is the second image rendered for every item in my list. Sometimes I see 2 images rendered at the same time, when in reality they are mutually exclusive. It almost seems like the dataTable at render time is treating all the images as 1 component and either the first or last time it processes all the EL is the one that wins out for every row. The custom function returns a boolean, false by default. The currentVehicleIndex is an Integer and there is custom property resolver to get it. Would the fact that is an Integer and not an int cause any problems? Sorry to jump on this as a MyFaces problem, I am just very frustrated because the code looks like it should work. I've been pulling my hair out trying to figure out what is going on. I read the facelets wiki link you posted but I don't think that applies here. Mike Kienenberger wrote: Are you using facelets? You talked about using JSTL tags, and as far as I know these are only available with Facelets. I also see functions in there, which again makes me think you're using facelets. If you define something with the c: tags, that only happens at compile time, not at render time. http://wiki.java.net/bin/view/Projects/FaceletsFAQ#What_s_the_difference_between_c I recommend that you greatly simplify your example, and post the exact page code here the expected results, and the actual results, so we're better able to help you. What you discussed earlier and what you posted didn't match up, and there's so many references to index and currentItemIndex in there that it's hard for us to guess which part isn't working for you. I use el expressions in rendered statements inside dataTable column children without problems (with facelets). On 9/13/06, Toppac [EMAIL PROTECTED] wrote: Thanks for the response but it definately does not work. For some reason when it is rendering the dataTable, whatever the first or last evaluation of the expression is, gets applied to every instance of the image within the datatable. It seems to cache the result of the EL expression for render and then use that for all the images at render time, rather than each image having its own value. I think this is a bug with myfaces Mike Kienenberger wrote: Of the code you posted, it looks ok to me. However, id=#{index + 'working'} is not legal. id must be a static value. On 9/12/06, Toppac [EMAIL PROTECTED] wrote: I am trying to use a datatable to render bunch of data and display an image next to each row rendered based on the rowIndex. My code is below. The problem I am seeing is that inside the graphicImage tag, the index doesn't have scope. I can print the index before and after the graphicImage, but when used inside the rendered attribute it always rendered to empty string. I tried to use the index as part of the id for the graphicImage, something like id=#{index + 'working'} and it always rendered to just working. I have tried just using rowIndex, tried naming the rowIndexVar something other than index, and no luck. I am wondering how I can use the current index inside other tags. I have also tried using JSTL tags c:if to do the rendering and it looks like the index doesn't have scope inside there either. The only other thing I can think may be wrong is that that the rendered attribute of the graphicImage is only calculated once or is calculated and applied to all the rows. The last c:if I have in my code below does work, so it seems to only be something with the rowIndexVar inside a dataTable. Last thing, ignore typos in variable names, as I changed
Re: datatable with multiple images not interpretting rendered attribute
An addition to this. Right now I am seeing the first image rendering for every item in my list. This means that the index-currentVehicleIndex is always 0. When I print index and currentVehicle index next to the image, it shows that the expression before is not always true. This is again what makes me think it is not evaluating that expression each time it renders a row. Toppac wrote: Mike thanks for the reply. Yes I am using facelets and I have a custom function that is being called in the render section of the image tag. Here is a simplified example of what I am trying to do. c:set var=currentVehicleIndex value=#{sessionData.currentVehicle} scope=page/ t:dataTable var=curVehicle rowIndexVar=index rendered=#{!(empty policy.vehicles)} value=#{policy.vehicles} border=0 cellpadding=0 cellspacing=0 t:column id=column1 f:facet name=header f:verbatimnbsp;/f:verbatim /f:facet h:graphicImage alt=Working rendered=#{(index - currentVehicleIndex) eq 0} value=snapc/images/icons/working.gif / h:graphicImage alt=Complete rendered=#{sf:isCompleteVehicle(curVehicle) and ((index - currentVehicleIndex) ne 0)} value=snapc/images/icons/complete.gif / h:graphicImage alt=Incomplete rendered=#{!sf:isCompleteVehicle(curVehicle) and ((index - currentVehicleIndex) ne 0)} value=snapc/images/icons/red_arrow.gif / /t:column /t:dataTable What I expect to see is the correct image displayed based on the rendered EL statements. What I end up seeing is the second image rendered for every item in my list. Sometimes I see 2 images rendered at the same time, when in reality they are mutually exclusive. It almost seems like the dataTable at render time is treating all the images as 1 component and either the first or last time it processes all the EL is the one that wins out for every row. The custom function returns a boolean, false by default. The currentVehicleIndex is an Integer and there is custom property resolver to get it. Would the fact that is an Integer and not an int cause any problems? Sorry to jump on this as a MyFaces problem, I am just very frustrated because the code looks like it should work. I've been pulling my hair out trying to figure out what is going on. I read the facelets wiki link you posted but I don't think that applies here. Mike Kienenberger wrote: Are you using facelets? You talked about using JSTL tags, and as far as I know these are only available with Facelets. I also see functions in there, which again makes me think you're using facelets. If you define something with the c: tags, that only happens at compile time, not at render time. http://wiki.java.net/bin/view/Projects/FaceletsFAQ#What_s_the_difference_between_c I recommend that you greatly simplify your example, and post the exact page code here the expected results, and the actual results, so we're better able to help you. What you discussed earlier and what you posted didn't match up, and there's so many references to index and currentItemIndex in there that it's hard for us to guess which part isn't working for you. I use el expressions in rendered statements inside dataTable column children without problems (with facelets). On 9/13/06, Toppac [EMAIL PROTECTED] wrote: Thanks for the response but it definately does not work. For some reason when it is rendering the dataTable, whatever the first or last evaluation of the expression is, gets applied to every instance of the image within the datatable. It seems to cache the result of the EL expression for render and then use that for all the images at render time, rather than each image having its own value. I think this is a bug with myfaces Mike Kienenberger wrote: Of the code you posted, it looks ok to me. However, id=#{index + 'working'} is not legal. id must be a static value. On 9/12/06, Toppac [EMAIL PROTECTED] wrote: I am trying to use a datatable to render bunch of data and display an image next to each row rendered based on the rowIndex. My code is below. The problem I am seeing is that inside the graphicImage tag, the index doesn't have scope. I can print the index before and after the graphicImage, but when used inside the rendered attribute it always rendered to empty string. I tried to use the index as part of the id for the graphicImage, something like id=#{index + 'working'} and it always rendered to just working. I have tried just using rowIndex, tried naming the rowIndexVar something other than index, and no luck. I am wondering how I can use the current index inside other tags. I have also tried using JSTL tags c:if to do the rendering and it looks like
datatable with multiple images not interpretting rendered attribute
I am trying to use a datatable to render bunch of data and display an image next to each row rendered based on the rowIndex. My code is below. The problem I am seeing is that inside the graphicImage tag, the index doesn't have scope. I can print the index before and after the graphicImage, but when used inside the rendered attribute it always rendered to empty string. I tried to use the index as part of the id for the graphicImage, something like id=#{index + 'working'} and it always rendered to just working. I have tried just using rowIndex, tried naming the rowIndexVar something other than index, and no luck. I am wondering how I can use the current index inside other tags. I have also tried using JSTL tags c:if to do the rendering and it looks like the index doesn't have scope inside there either. The only other thing I can think may be wrong is that that the rendered attribute of the graphicImage is only calculated once or is calculated and applied to all the rows. The last c:if I have in my code below does work, so it seems to only be something with the rowIndexVar inside a dataTable. Last thing, ignore typos in variable names, as I changed the names of the variables to hide the real function of this code (requirement). And currentItemIndex is a c:set var defined earlier in the page. t:dataTable var=curItem rowIndexVar=index value=#{someData.someItems} border=0 cellpadding=0 cellspacing=0 t:column id=column1 f:facet name=header f:verbatimnbsp;/f:verbatim /f:facet #{index} and #{currentItemIndex} and #{(index - currentItemIndex) eq 0} h:graphicImage alt=Working rendered=#{(index - currentItemIndex) eq 0} value=snapc/images/icons/working.gif / h:graphicImage alt=Complete rendered=#{sf:isCompleteItem(curItem) and ((index - currentItemIndex) ne 0)} value=snapc/images/icons/complete.gif / h:graphicImage alt=Incomplete rendered=#{!sf:isCompleteItem(curItem) and ((index - currentItemIndex) ne 0)} value=snapc/images/icons/red_arrow.gif / /t:column t:column id=column2 f:facet name=header h:outputText value=Year / /f:facet #{curItem.currentlYear} /t:column t:column id=column3 f:facet name=header f:verbatimnbsp;/f:verbatim /f:facet c:if test=#{fn:length(someData.someItems) 1} h:commandLink action=edit type=submit id=edit #{bundle.usage_editdetails_label} f:param name=editIndex value=#{index}/ /h:commandLink nbsp;nbsp;|nbsp;nbsp; h:commandLink action=delete id=delete #{bundle.usage_delete_label} f:param name=deleteIndex value=#{index}/ /h:commandLink /c:if /t:column /t:dataTable -- View this message in context: http://www.nabble.com/datatable-with-multiple-images-not-interpretting-rendered-attribute-tf2261743.html#a6275415 Sent from the MyFaces - Users forum at Nabble.com.