On 10/5/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > My registrationBean (extends AbstractViewController) has a "password" > attribute as well as a save() method which has this code: > > if (passwords_dont_match) { > error(messages.getMessage("password.mismatch")); > etc. > } > > My jsp has this code: > <h:message for="password" /> > in the "<td>" right next to where the password field is. > > However the error doesn't show up. (There is an empty <td> in the source > so I think the problem is not in my panelGrid..) Plus if I know the errors > are being caught since <f:facet name="header"><h:messages globalOnly= > "true" /></f:facet> > does show the error.
As expected ... you've asked for only the errors specifically associated with this component. I looked at the docs and saw that maybe I should use the other error > method in org.apache.shale.view.AbstractViewBean: > protected void error(javax.faces.component.UIComponent component, > java.lang.String summary) > > But I am not sure how I should get the UIComponent object to use. I tried > unsuccessfully to use: > error( > FacesContext.getCurrentInstance().getViewRoot().findComponent("password"), > messages.getMessage("password.mismatch")); > > but the above component is null, sadly.. I would have thought that being > in the RegistartionBean would imply getting any UIComponent in > registration.jsp should be easy..? Is this the right approach? (Or I > should just go home...) Right strategy ... but one wrong detail. The search expression for findComponent() is the *client id* of the component in question, not the *id* property value. In turn, the client id will be affected by the id of naming containers (such as the <h:form> component) that your input field is nested in. Quickest way to see what value you should use is to do a View Source on the HTML page, and see what id was emitted for the input field. A different approach that will often be easier, though, is to use the "binding" attribute to bind an instance of your actual component into the backing bean. In the JSP page, you can say: <h:inputSecret id="password" binding="#{backingBean.password}" .../> and in the managed bean labelled by "backingBean" (the same one where you do your authentication check): private HtmlInputSecret password = null; public HtmlInputSecret getPassword() { return this.password; } public void setPassword(HtmlInputSecret password) { this.password = password; } That way, the code that calls error() has direct access to the actual component instance, and does not have to look it up. Craig Geeta > >