开发者

Spring JSF and these wrongly filled forms

I'm thinking about good approaches to develop web software. Spring is great for JDBC stuff but it also has a nice feature for autocompleting faulty forms, nice backing beans for prefilling forms and so on.

Now I started with JSF and it seems more correct than Spring for doing MVC. I like the xhtml approaches, including templates, defining these webflows in the faces-config.xml and so on.

But there is no clear separation of concerns because both frameworks can work with forms, and I am pretty sure you will have to make your mind up if Faces or Spring shall make the forms. I'm tending towards JSF but I'm missing these nifty error handling and prefilling features.

Can JSF do these things also? I'm new to J开发者_如何学JAVASF so I'm not sure how mighty it is.


but I'm missing these nifty error handling and prefilling features. Can JSF do these things also? I'm new to JSF so I'm not sure how mighty it is.

JSF has builtin validation, e.g. <h:inputText required="true">, <f:validateLongRange>, <f:validateRegex> and also conversion, e.g. <f:convertDateTime>, <f:convertNumber>, etc (see them all here). JSF also supports JSR 303 Bean Validation which is controlled by annotations like @NotNull, @Min, @Max, @Pattern, etc on model objects. All validation/conversion errors end up in a <h:message> bound to the input element or a global <h:messages>. This JSF 2.0 tutorial handles validation in depth.

As to prefilling, just set the desired model in bean's (post) constructor or by <f:viewParam> if some ID is to be obtained as request parameter. Basically:

public class Bean {

    private Entity entity;

    @EJB
    private EntityService entityService;

    @PostConstruct
    public void init() {
        entity = entityService.find(someId);
    }

    // ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜